blob: 5c990eff850f0d3728e5a49a1aea75c5706663bf [file] [log] [blame]
Greg Ward04613a92002-11-30 22:47:45 +00001/*
2 * ossaudiodev -- Python interface to the OSS (Open Sound System) API.
3 * This is the standard audio API for Linux and some
4 * flavours of BSD [XXX which ones?]; it is also available
5 * for a wide range of commercial Unices.
6 *
7 * Originally written by Peter Bosch, March 2000, as linuxaudiodev.
8 *
9 * Renamed to ossaudiodev and rearranged/revised/hacked up
10 * by Greg Ward <gward@python.net>, November 2002.
Greg Ward3d9994d2002-12-11 15:12:01 +000011 * Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002.
Guido van Rossum0741f802003-06-02 14:15:34 +000012 *
Greg Ward04613a92002-11-30 22:47:45 +000013 * (c) 2000 Peter Bosch. All Rights Reserved.
14 * (c) 2002 Gregory P. Ward. All Rights Reserved.
15 * (c) 2002 Python Software Foundation. All Rights Reserved.
16 *
17 * XXX need a license statement
18 *
19 * $Id$
20 */
21
22#include "Python.h"
23#include "structmember.h"
24
25#ifdef HAVE_FCNTL_H
26#include <fcntl.h>
27#else
28#define O_RDONLY 00
29#define O_WRONLY 01
30#endif
31
Greg Ward04613a92002-11-30 22:47:45 +000032#include <sys/ioctl.h>
Greg Ward0b6dfb82003-03-10 03:17:06 +000033#include <sys/soundcard.h>
34
Greg Ward04613a92002-11-30 22:47:45 +000035#if defined(linux)
Greg Ward04613a92002-11-30 22:47:45 +000036
Thomas Wouters89f507f2006-12-13 04:49:30 +000037#ifndef HAVE_STDINT_H
Greg Ward04613a92002-11-30 22:47:45 +000038typedef unsigned long uint32_t;
Thomas Wouters89f507f2006-12-13 04:49:30 +000039#endif
Greg Ward04613a92002-11-30 22:47:45 +000040
41#elif defined(__FreeBSD__)
Greg Ward04613a92002-11-30 22:47:45 +000042
Greg Ward0b6dfb82003-03-10 03:17:06 +000043# ifndef SNDCTL_DSP_CHANNELS
44# define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
45# endif
Greg Ward04613a92002-11-30 22:47:45 +000046
47#endif
48
49typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000050 PyObject_HEAD
Greg Ward50682d02005-03-07 01:41:11 +000051 char *devicename; /* name of the device file */
52 int fd; /* file descriptor */
53 int mode; /* file mode (O_RDONLY, etc.) */
54 int icount; /* input count */
55 int ocount; /* output count */
56 uint32_t afmts; /* audio formats supported by hardware */
Greg Ward499b73e2002-12-31 03:04:52 +000057} oss_audio_t;
Greg Ward04613a92002-11-30 22:47:45 +000058
Greg Ward3d9994d2002-12-11 15:12:01 +000059typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000060 PyObject_HEAD
Greg Wardad4d9b92002-12-30 03:02:22 +000061 int fd; /* The open mixer device */
Greg Ward3d9994d2002-12-11 15:12:01 +000062} oss_mixer_t;
63
Greg Ward04613a92002-11-30 22:47:45 +000064
Greg Ward499b73e2002-12-31 03:04:52 +000065static PyTypeObject OSSAudioType;
Greg Ward3d9994d2002-12-11 15:12:01 +000066static PyTypeObject OSSMixerType;
Greg Ward04613a92002-11-30 22:47:45 +000067
Greg Ward97708bc2002-11-30 23:17:10 +000068static PyObject *OSSAudioError;
Greg Ward04613a92002-11-30 22:47:45 +000069
Greg Wardda1cacb2002-12-31 03:02:23 +000070
71/* ----------------------------------------------------------------------
72 * DSP object initialization/deallocation
73 */
74
Greg Ward499b73e2002-12-31 03:04:52 +000075static oss_audio_t *
Greg Ward8c6b6a92002-12-11 14:43:13 +000076newossobject(PyObject *arg)
Greg Ward04613a92002-11-30 22:47:45 +000077{
Greg Ward58ae13c2002-12-31 03:07:21 +000078 oss_audio_t *self;
Greg Ward04613a92002-11-30 22:47:45 +000079 int fd, afmts, imode;
Greg Ward50682d02005-03-07 01:41:11 +000080 char *devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000081 char *mode = NULL;
82
Greg Ward9a568eb2002-11-30 23:20:09 +000083 /* Two ways to call open():
Greg Ward04613a92002-11-30 22:47:45 +000084 open(device, mode) (for consistency with builtin open())
85 open(mode) (for backwards compatibility)
86 because the *first* argument is optional, parsing args is
87 a wee bit tricky. */
Greg Ward50682d02005-03-07 01:41:11 +000088 if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
Greg Ward04613a92002-11-30 22:47:45 +000089 return NULL;
90 if (mode == NULL) { /* only one arg supplied */
Greg Ward50682d02005-03-07 01:41:11 +000091 mode = devicename;
92 devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000093 }
94
95 if (strcmp(mode, "r") == 0)
96 imode = O_RDONLY;
97 else if (strcmp(mode, "w") == 0)
98 imode = O_WRONLY;
Greg Ward1e0f57d2002-11-30 23:05:26 +000099 else if (strcmp(mode, "rw") == 0)
100 imode = O_RDWR;
Greg Ward04613a92002-11-30 22:47:45 +0000101 else {
Greg Ward97708bc2002-11-30 23:17:10 +0000102 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
Greg Ward04613a92002-11-30 22:47:45 +0000103 return NULL;
104 }
105
Greg Ward5c5c5772002-12-30 02:58:04 +0000106 /* Open the correct device: either the 'device' argument,
107 or the AUDIODEV environment variable, or "/dev/dsp". */
Greg Ward50682d02005-03-07 01:41:11 +0000108 if (devicename == NULL) { /* called with one arg */
109 devicename = getenv("AUDIODEV");
110 if (devicename == NULL) /* $AUDIODEV not set */
111 devicename = "/dev/dsp";
Greg Ward04613a92002-11-30 22:47:45 +0000112 }
113
Greg Ward5c49ef22003-03-11 16:53:13 +0000114 /* Open with O_NONBLOCK to avoid hanging on devices that only allow
115 one open at a time. This does *not* affect later I/O; OSS
116 provides a special ioctl() for non-blocking read/write, which is
117 exposed via oss_nonblock() below. */
Greg Ward50682d02005-03-07 01:41:11 +0000118 if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) {
119 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000120 return NULL;
121 }
Greg Ward76ffb192003-04-04 01:47:42 +0000122
123 /* And (try to) put it back in blocking mode so we get the
124 expected write() semantics. */
125 if (fcntl(fd, F_SETFL, 0) == -1) {
126 close(fd);
Greg Ward50682d02005-03-07 01:41:11 +0000127 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward76ffb192003-04-04 01:47:42 +0000128 return NULL;
129 }
130
Greg Ward04613a92002-11-30 22:47:45 +0000131 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
Greg Ward50682d02005-03-07 01:41:11 +0000132 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000133 return NULL;
134 }
135 /* Create and initialize the object */
Greg Ward58ae13c2002-12-31 03:07:21 +0000136 if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) {
Greg Ward04613a92002-11-30 22:47:45 +0000137 close(fd);
138 return NULL;
139 }
Greg Ward50682d02005-03-07 01:41:11 +0000140 self->devicename = devicename;
Greg Ward58ae13c2002-12-31 03:07:21 +0000141 self->fd = fd;
142 self->mode = imode;
143 self->icount = self->ocount = 0;
144 self->afmts = afmts;
145 return self;
Greg Ward04613a92002-11-30 22:47:45 +0000146}
147
148static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000149oss_dealloc(oss_audio_t *self)
Greg Ward04613a92002-11-30 22:47:45 +0000150{
151 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000152 if (self->fd != -1)
153 close(self->fd);
154 PyObject_Del(self);
Greg Ward04613a92002-11-30 22:47:45 +0000155}
156
Greg Wardda1cacb2002-12-31 03:02:23 +0000157
158/* ----------------------------------------------------------------------
159 * Mixer object initialization/deallocation
160 */
161
Greg Ward3d9994d2002-12-11 15:12:01 +0000162static oss_mixer_t *
163newossmixerobject(PyObject *arg)
164{
Greg Ward50682d02005-03-07 01:41:11 +0000165 char *devicename = NULL;
Greg Ward0b6dfb82003-03-10 03:17:06 +0000166 int fd;
Greg Ward58ae13c2002-12-31 03:07:21 +0000167 oss_mixer_t *self;
Guido van Rossum0741f802003-06-02 14:15:34 +0000168
Greg Ward50682d02005-03-07 01:41:11 +0000169 if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000170 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000171 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000172
Greg Ward50682d02005-03-07 01:41:11 +0000173 if (devicename == NULL) {
174 devicename = getenv("MIXERDEV");
175 if (devicename == NULL) /* MIXERDEV not set */
176 devicename = "/dev/mixer";
Greg Ward3d9994d2002-12-11 15:12:01 +0000177 }
178
Greg Ward50682d02005-03-07 01:41:11 +0000179 if ((fd = open(devicename, O_RDWR)) == -1) {
180 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward3d9994d2002-12-11 15:12:01 +0000181 return NULL;
182 }
Greg Ward0b6dfb82003-03-10 03:17:06 +0000183
Greg Ward58ae13c2002-12-31 03:07:21 +0000184 if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
Greg Ward3d9994d2002-12-11 15:12:01 +0000185 close(fd);
186 return NULL;
187 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000188
Greg Ward58ae13c2002-12-31 03:07:21 +0000189 self->fd = fd;
Guido van Rossum0741f802003-06-02 14:15:34 +0000190
Greg Ward58ae13c2002-12-31 03:07:21 +0000191 return self;
Greg Ward3d9994d2002-12-11 15:12:01 +0000192}
193
194static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000195oss_mixer_dealloc(oss_mixer_t *self)
Greg Ward3d9994d2002-12-11 15:12:01 +0000196{
197 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000198 if (self->fd != -1)
199 close(self->fd);
200 PyObject_Del(self);
Greg Ward3d9994d2002-12-11 15:12:01 +0000201}
202
Greg Ward131bce02002-11-30 22:56:44 +0000203
204/* Methods to wrap the OSS ioctls. The calling convention is pretty
205 simple:
206 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
207 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
208 etc.
209*/
210
211
Greg Wardd6769062003-05-29 21:53:06 +0000212/* ----------------------------------------------------------------------
213 * Helper functions
214 */
215
Greg Ward131bce02002-11-30 22:56:44 +0000216/* _do_ioctl_1() is a private helper function used for the OSS ioctls --
217 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C
218 like this:
219 ioctl(fd, SNDCTL_DSP_cmd, &arg)
220
221 where arg is the value to set, and on return the driver sets arg to
222 the value that was actually set. Mapping this to Python is obvious:
223 arg = dsp.xxx(arg)
224*/
225static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000226_do_ioctl_1(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000227{
Greg Wardda9f8532002-12-11 14:49:59 +0000228 char argfmt[33] = "i:";
Greg Ward131bce02002-11-30 22:56:44 +0000229 int arg;
230
Greg Wardda9f8532002-12-11 14:49:59 +0000231 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000232 strcat(argfmt, fname);
233 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000234 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000235
Greg Wardda9f8532002-12-11 14:49:59 +0000236 if (ioctl(fd, cmd, &arg) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000237 return PyErr_SetFromErrno(PyExc_IOError);
Christian Heimes217cfd12007-12-02 14:31:20 +0000238 return PyLong_FromLong(arg);
Greg Ward131bce02002-11-30 22:56:44 +0000239}
240
Greg Wardda1cacb2002-12-31 03:02:23 +0000241
Greg Ward3d9994d2002-12-11 15:12:01 +0000242/* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
243 but return an output -- ie. we need to pass a pointer to a local C
244 variable so the driver can write its output there, but from Python
245 all we see is the return value. For example,
246 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
247 devices, but does not use the value of the parameter passed-in in any
248 way.
249*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000250static PyObject *
251_do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd)
252{
253 char argfmt[32] = ":";
254 int arg = 0;
255
256 assert(strlen(fname) <= 30);
257 strcat(argfmt, fname);
258 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000259 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000260
261 if (ioctl(fd, cmd, &arg) == -1)
262 return PyErr_SetFromErrno(PyExc_IOError);
Christian Heimes217cfd12007-12-02 14:31:20 +0000263 return PyLong_FromLong(arg);
Greg Ward3d9994d2002-12-11 15:12:01 +0000264}
265
266
267
Greg Ward131bce02002-11-30 22:56:44 +0000268/* _do_ioctl_0() is a private helper for the no-argument ioctls:
269 SNDCTL_DSP_{SYNC,RESET,POST}. */
270static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000271_do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000272{
Greg Wardda9f8532002-12-11 14:49:59 +0000273 char argfmt[32] = ":";
Greg Wardd0d592f2003-05-27 01:57:21 +0000274 int rv;
Greg Ward131bce02002-11-30 22:56:44 +0000275
Greg Wardda9f8532002-12-11 14:49:59 +0000276 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000277 strcat(argfmt, fname);
278 if (!PyArg_ParseTuple(args, argfmt))
Greg Wardad4d9b92002-12-30 03:02:22 +0000279 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000280
Greg Wardd0d592f2003-05-27 01:57:21 +0000281 /* According to hannu@opensound.com, all three of the ioctls that
282 use this function can block, so release the GIL. This is
283 especially important for SYNC, which can block for several
284 seconds. */
285 Py_BEGIN_ALLOW_THREADS
286 rv = ioctl(fd, cmd, 0);
287 Py_END_ALLOW_THREADS
288
289 if (rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000290 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000291 Py_INCREF(Py_None);
292 return Py_None;
293}
294
295
Greg Wardda1cacb2002-12-31 03:02:23 +0000296/* ----------------------------------------------------------------------
Greg Ward499b73e2002-12-31 03:04:52 +0000297 * Methods of DSP objects (OSSAudioType)
Greg Wardda1cacb2002-12-31 03:02:23 +0000298 */
299
Greg Ward131bce02002-11-30 22:56:44 +0000300static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000301oss_nonblock(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000302{
303 /* Hmmm: it doesn't appear to be possible to return to blocking
304 mode once we're in non-blocking mode! */
Greg Ward7b43c682002-12-30 02:29:28 +0000305 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000306 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000307 Py_INCREF(Py_None);
308 return Py_None;
309}
310
311static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000312oss_setfmt(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000313{
Greg Ward7b43c682002-12-30 02:29:28 +0000314 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
Greg Ward131bce02002-11-30 22:56:44 +0000315}
316
317static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000318oss_getfmts(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000319{
320 int mask;
Greg Ward7b43c682002-12-30 02:29:28 +0000321 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000322 return PyErr_SetFromErrno(PyExc_IOError);
Christian Heimes217cfd12007-12-02 14:31:20 +0000323 return PyLong_FromLong(mask);
Greg Ward131bce02002-11-30 22:56:44 +0000324}
325
326static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000327oss_channels(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000328{
Greg Ward7b43c682002-12-30 02:29:28 +0000329 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
Greg Ward131bce02002-11-30 22:56:44 +0000330}
331
332static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000333oss_speed(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000334{
Greg Ward7b43c682002-12-30 02:29:28 +0000335 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
Greg Ward131bce02002-11-30 22:56:44 +0000336}
337
338static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000339oss_sync(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000340{
Greg Wardd0d592f2003-05-27 01:57:21 +0000341 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
Greg Ward131bce02002-11-30 22:56:44 +0000342}
Guido van Rossum0741f802003-06-02 14:15:34 +0000343
Greg Ward131bce02002-11-30 22:56:44 +0000344static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000345oss_reset(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000346{
Greg Ward7b43c682002-12-30 02:29:28 +0000347 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
Greg Ward131bce02002-11-30 22:56:44 +0000348}
Guido van Rossum0741f802003-06-02 14:15:34 +0000349
Greg Ward131bce02002-11-30 22:56:44 +0000350static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000351oss_post(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000352{
Greg Ward7b43c682002-12-30 02:29:28 +0000353 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
Greg Ward131bce02002-11-30 22:56:44 +0000354}
355
356
357/* Regular file methods: read(), write(), close(), etc. as well
358 as one convenience method, writeall(). */
359
Greg Ward04613a92002-11-30 22:47:45 +0000360static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000361oss_read(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000362{
363 int size, count;
364 char *cp;
365 PyObject *rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000366
Greg Ward04613a92002-11-30 22:47:45 +0000367 if (!PyArg_ParseTuple(args, "i:read", &size))
368 return NULL;
Gregory P. Smith0a608fd2008-09-06 21:34:51 +0000369 rv = PyBytes_FromStringAndSize(NULL, size);
Greg Ward04613a92002-11-30 22:47:45 +0000370 if (rv == NULL)
371 return NULL;
Gregory P. Smith0a608fd2008-09-06 21:34:51 +0000372 cp = PyBytes_AS_STRING(rv);
Greg Ward64927852003-05-23 01:50:37 +0000373
374 Py_BEGIN_ALLOW_THREADS
375 count = read(self->fd, cp, size);
376 Py_END_ALLOW_THREADS
377
378 if (count < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000379 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000380 Py_DECREF(rv);
381 return NULL;
382 }
Greg Ward7b43c682002-12-30 02:29:28 +0000383 self->icount += count;
Gregory P. Smith0a608fd2008-09-06 21:34:51 +0000384 _PyBytes_Resize(&rv, count);
Greg Ward04613a92002-11-30 22:47:45 +0000385 return rv;
386}
387
388static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000389oss_write(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000390{
391 char *cp;
392 int rv, size;
Greg Ward131bce02002-11-30 22:56:44 +0000393
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000394 if (!PyArg_ParseTuple(args, "y#:write", &cp, &size)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000395 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000396 }
Greg Ward64927852003-05-23 01:50:37 +0000397
398 Py_BEGIN_ALLOW_THREADS
399 rv = write(self->fd, cp, size);
400 Py_END_ALLOW_THREADS
401
402 if (rv == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000403 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000404 } else {
Greg Ward7b43c682002-12-30 02:29:28 +0000405 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000406 }
Christian Heimes217cfd12007-12-02 14:31:20 +0000407 return PyLong_FromLong(rv);
Greg Ward131bce02002-11-30 22:56:44 +0000408}
409
410static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000411oss_writeall(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000412{
413 char *cp;
414 int rv, size;
415 fd_set write_set_fds;
416 int select_rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000417
Greg Ward131bce02002-11-30 22:56:44 +0000418 /* NB. writeall() is only useful in non-blocking mode: according to
419 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
420 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
421 write() in blocking mode consumes the whole buffer. In blocking
422 mode, the behaviour of write() and writeall() from Python is
423 indistinguishable. */
424
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000425 if (!PyArg_ParseTuple(args, "y#:write", &cp, &size))
Greg Ward131bce02002-11-30 22:56:44 +0000426 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000427
428 /* use select to wait for audio device to be available */
429 FD_ZERO(&write_set_fds);
Greg Ward7b43c682002-12-30 02:29:28 +0000430 FD_SET(self->fd, &write_set_fds);
Greg Ward04613a92002-11-30 22:47:45 +0000431
432 while (size > 0) {
Greg Ward64927852003-05-23 01:50:37 +0000433 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000434 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Greg Ward64927852003-05-23 01:50:37 +0000435 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000436 assert(select_rv != 0); /* no timeout, can't expire */
437 if (select_rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000438 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000439
Greg Ward64927852003-05-23 01:50:37 +0000440 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000441 rv = write(self->fd, cp, size);
Greg Ward64927852003-05-23 01:50:37 +0000442 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000443 if (rv == -1) {
444 if (errno == EAGAIN) { /* buffer is full, try again */
445 errno = 0;
446 continue;
447 } else /* it's a real error */
Greg Ward97708bc2002-11-30 23:17:10 +0000448 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000449 } else { /* wrote rv bytes */
Greg Ward7b43c682002-12-30 02:29:28 +0000450 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000451 size -= rv;
452 cp += rv;
453 }
Greg Ward04613a92002-11-30 22:47:45 +0000454 }
455 Py_INCREF(Py_None);
456 return Py_None;
457}
458
459static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000460oss_close(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000461{
Greg Ward7b43c682002-12-30 02:29:28 +0000462 if (self->fd >= 0) {
Greg Wardb8043902003-05-26 22:47:30 +0000463 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000464 close(self->fd);
Greg Wardb8043902003-05-26 22:47:30 +0000465 Py_END_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000466 self->fd = -1;
Greg Ward04613a92002-11-30 22:47:45 +0000467 }
468 Py_INCREF(Py_None);
469 return Py_None;
470}
471
472static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000473oss_fileno(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000474{
Christian Heimes217cfd12007-12-02 14:31:20 +0000475 return PyLong_FromLong(self->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000476}
477
Greg Ward131bce02002-11-30 22:56:44 +0000478
479/* Convenience methods: these generally wrap a couple of ioctls into one
480 common task. */
481
Greg Ward04613a92002-11-30 22:47:45 +0000482static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000483oss_setparameters(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000484{
Greg Wardd6769062003-05-29 21:53:06 +0000485 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
486 int fmt, channels, rate;
487 PyObject * rv; /* return tuple (fmt, channels, rate) */
Greg Ward04613a92002-11-30 22:47:45 +0000488
Greg Wardd6769062003-05-29 21:53:06 +0000489 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
490 &wanted_fmt, &wanted_channels, &wanted_rate,
491 &strict))
Greg Ward04613a92002-11-30 22:47:45 +0000492 return NULL;
Greg Wardd6769062003-05-29 21:53:06 +0000493
494 fmt = wanted_fmt;
495 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
496 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000497 }
Greg Wardd6769062003-05-29 21:53:06 +0000498 if (strict && fmt != wanted_fmt) {
499 return PyErr_Format
500 (OSSAudioError,
501 "unable to set requested format (wanted %d, got %d)",
502 wanted_fmt, fmt);
Greg Ward04613a92002-11-30 22:47:45 +0000503 }
504
Greg Wardd6769062003-05-29 21:53:06 +0000505 channels = wanted_channels;
506 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
507 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000508 }
Greg Wardd6769062003-05-29 21:53:06 +0000509 if (strict && channels != wanted_channels) {
510 return PyErr_Format
511 (OSSAudioError,
512 "unable to set requested channels (wanted %d, got %d)",
513 wanted_channels, channels);
Greg Ward04613a92002-11-30 22:47:45 +0000514 }
515
Greg Wardd6769062003-05-29 21:53:06 +0000516 rate = wanted_rate;
Greg Ward7b43c682002-12-30 02:29:28 +0000517 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Greg Wardd6769062003-05-29 21:53:06 +0000518 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000519 }
Greg Wardd6769062003-05-29 21:53:06 +0000520 if (strict && rate != wanted_rate) {
521 return PyErr_Format
522 (OSSAudioError,
523 "unable to set requested rate (wanted %d, got %d)",
524 wanted_rate, rate);
525 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000526
Greg Wardd6769062003-05-29 21:53:06 +0000527 /* Construct the return value: a (fmt, channels, rate) tuple that
528 tells what the audio hardware was actually set to. */
529 rv = PyTuple_New(3);
530 if (rv == NULL)
531 return NULL;
Christian Heimes217cfd12007-12-02 14:31:20 +0000532 PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(fmt));
533 PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(channels));
534 PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(rate));
Greg Wardd6769062003-05-29 21:53:06 +0000535 return rv;
Greg Ward04613a92002-11-30 22:47:45 +0000536}
537
538static int
Greg Ward499b73e2002-12-31 03:04:52 +0000539_ssize(oss_audio_t *self, int *nchannels, int *ssize)
Greg Ward04613a92002-11-30 22:47:45 +0000540{
541 int fmt;
542
543 fmt = 0;
Guido van Rossum0741f802003-06-02 14:15:34 +0000544 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000545 return -errno;
546
547 switch (fmt) {
548 case AFMT_MU_LAW:
549 case AFMT_A_LAW:
550 case AFMT_U8:
551 case AFMT_S8:
Greg Ward38c92662003-05-29 21:55:41 +0000552 *ssize = 1; /* 8 bit formats: 1 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000553 break;
554 case AFMT_S16_LE:
555 case AFMT_S16_BE:
556 case AFMT_U16_LE:
557 case AFMT_U16_BE:
Greg Ward84f8ecd2003-05-29 23:44:44 +0000558 *ssize = 2; /* 16 bit formats: 2 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000559 break;
560 case AFMT_MPEG:
561 case AFMT_IMA_ADPCM:
562 default:
563 return -EOPNOTSUPP;
564 }
Greg Ward7b43c682002-12-30 02:29:28 +0000565 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000566 return -errno;
567 return 0;
568}
569
570
Guido van Rossum0741f802003-06-02 14:15:34 +0000571/* bufsize returns the size of the hardware audio buffer in number
Greg Ward04613a92002-11-30 22:47:45 +0000572 of samples */
573static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000574oss_bufsize(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000575{
576 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000577 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000578
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000579 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000580 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000581 return NULL;
582 }
Greg Ward7b43c682002-12-30 02:29:28 +0000583 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000584 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000585 return NULL;
586 }
Christian Heimes217cfd12007-12-02 14:31:20 +0000587 return PyLong_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
Greg Ward04613a92002-11-30 22:47:45 +0000588}
589
Guido van Rossum0741f802003-06-02 14:15:34 +0000590/* obufcount returns the number of samples that are available in the
Greg Ward04613a92002-11-30 22:47:45 +0000591 hardware for playing */
592static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000593oss_obufcount(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000594{
595 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000596 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000597
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000598 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000599 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000600 return NULL;
601 }
Greg Ward7b43c682002-12-30 02:29:28 +0000602 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000603 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000604 return NULL;
605 }
Christian Heimes217cfd12007-12-02 14:31:20 +0000606 return PyLong_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
Greg Ward04613a92002-11-30 22:47:45 +0000607 (ssize * nchannels));
608}
609
610/* obufcount returns the number of samples that can be played without
611 blocking */
612static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000613oss_obuffree(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000614{
615 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000616 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000617
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000618 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000619 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000620 return NULL;
621 }
Greg Ward7b43c682002-12-30 02:29:28 +0000622 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000623 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000624 return NULL;
625 }
Christian Heimes217cfd12007-12-02 14:31:20 +0000626 return PyLong_FromLong(ai.bytes / (ssize * nchannels));
Greg Ward04613a92002-11-30 22:47:45 +0000627}
628
Greg Ward04613a92002-11-30 22:47:45 +0000629static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000630oss_getptr(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000631{
632 count_info info;
633 int req;
634
Greg Ward7b43c682002-12-30 02:29:28 +0000635 if (self->mode == O_RDONLY)
Greg Wardad4d9b92002-12-30 03:02:22 +0000636 req = SNDCTL_DSP_GETIPTR;
Greg Ward04613a92002-11-30 22:47:45 +0000637 else
Greg Wardad4d9b92002-12-30 03:02:22 +0000638 req = SNDCTL_DSP_GETOPTR;
Greg Ward7b43c682002-12-30 02:29:28 +0000639 if (ioctl(self->fd, req, &info) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000640 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000641 return NULL;
642 }
643 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
644}
645
Greg Wardda1cacb2002-12-31 03:02:23 +0000646
647/* ----------------------------------------------------------------------
648 * Methods of mixer objects (OSSMixerType)
649 */
650
Greg Ward3d9994d2002-12-11 15:12:01 +0000651static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000652oss_mixer_close(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000653{
Greg Ward7b43c682002-12-30 02:29:28 +0000654 if (self->fd >= 0) {
655 close(self->fd);
656 self->fd = -1;
Greg Ward3d9994d2002-12-11 15:12:01 +0000657 }
658 Py_INCREF(Py_None);
659 return Py_None;
660}
661
662static PyObject *
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000663oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000664{
Christian Heimes217cfd12007-12-02 14:31:20 +0000665 return PyLong_FromLong(self->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000666}
667
668/* Simple mixer interface methods */
669
670static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000671oss_mixer_controls(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000672{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000673 return _do_ioctl_1_internal(self->fd, args, "controls",
Greg Ward3d9994d2002-12-11 15:12:01 +0000674 SOUND_MIXER_READ_DEVMASK);
675}
676
677static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000678oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000679{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000680 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
Greg Ward3d9994d2002-12-11 15:12:01 +0000681 SOUND_MIXER_READ_STEREODEVS);
682}
683
684static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000685oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000686{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000687 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
Greg Wardb69bb3d2002-12-12 17:35:45 +0000688 SOUND_MIXER_READ_RECMASK);
Greg Ward3d9994d2002-12-11 15:12:01 +0000689}
690
691static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000692oss_mixer_get(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000693{
694 int channel, volume;
Guido van Rossum0741f802003-06-02 14:15:34 +0000695
Greg Ward3d9994d2002-12-11 15:12:01 +0000696 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000697 if (!PyArg_ParseTuple(args, "i:get", &channel))
Greg Wardad4d9b92002-12-30 03:02:22 +0000698 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000699
Greg Ward3d9994d2002-12-11 15:12:01 +0000700 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000701 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
702 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000703 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000704
Greg Warde7037662002-12-30 03:01:48 +0000705 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000706 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000707
Greg Warde7037662002-12-30 03:01:48 +0000708 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000709}
710
711static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000712oss_mixer_set(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000713{
714 int channel, volume, leftVol, rightVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000715
Greg Ward3d9994d2002-12-11 15:12:01 +0000716 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000717 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
Greg Wardad4d9b92002-12-30 03:02:22 +0000718 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000719
Greg Ward3d9994d2002-12-11 15:12:01 +0000720 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000721 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
722 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000723 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000724
Greg Ward3d9994d2002-12-11 15:12:01 +0000725 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000726 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
727 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000728 }
729
730 volume = (rightVol << 8) | leftVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000731
Greg Warde7037662002-12-30 03:01:48 +0000732 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000733 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000734
Greg Warde7037662002-12-30 03:01:48 +0000735 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000736}
737
738static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000739oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000740{
Greg Wardf05aa102002-12-30 23:19:32 +0000741 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000742 SOUND_MIXER_READ_RECSRC);
743}
744
745static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000746oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000747{
Greg Wardf05aa102002-12-30 23:19:32 +0000748 return _do_ioctl_1(self->fd, args, "set_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000749 SOUND_MIXER_WRITE_RECSRC);
750}
751
752
Greg Wardda1cacb2002-12-31 03:02:23 +0000753/* ----------------------------------------------------------------------
754 * Method tables and other bureaucracy
755 */
756
Greg Ward8c6b6a92002-12-11 14:43:13 +0000757static PyMethodDef oss_methods[] = {
Greg Ward131bce02002-11-30 22:56:44 +0000758 /* Regular file methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000759 { "read", (PyCFunction)oss_read, METH_VARARGS },
760 { "write", (PyCFunction)oss_write, METH_VARARGS },
761 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000762 { "close", (PyCFunction)oss_close, METH_NOARGS },
763 { "fileno", (PyCFunction)oss_fileno, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000764
765 /* Simple ioctl wrappers */
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000766 { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000767 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000768 { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS },
Greg Ward8c6b6a92002-12-11 14:43:13 +0000769 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
770 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000771 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
772 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
773 { "post", (PyCFunction)oss_post, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000774
775 /* Convenience methods -- wrap a couple of ioctls together */
Greg Wardad4d9b92002-12-30 03:02:22 +0000776 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000777 { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS },
778 { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS },
779 { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS },
780 { "getptr", (PyCFunction)oss_getptr, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000781
782 /* Aliases for backwards compatibility */
Greg Wardad4d9b92002-12-30 03:02:22 +0000783 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000784
Greg Wardad4d9b92002-12-30 03:02:22 +0000785 { NULL, NULL} /* sentinel */
Greg Ward04613a92002-11-30 22:47:45 +0000786};
787
Greg Ward3d9994d2002-12-11 15:12:01 +0000788static PyMethodDef oss_mixer_methods[] = {
789 /* Regular file method - OSS mixers are ioctl-only interface */
Thomas Wouters4d70c3d2006-06-08 14:42:34 +0000790 { "close", (PyCFunction)oss_mixer_close, METH_NOARGS },
791 { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000792
793 /* Simple ioctl wrappers */
Guido van Rossum0741f802003-06-02 14:15:34 +0000794 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
Greg Ward2d6f9a92002-12-31 02:54:43 +0000795 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
Guido van Rossum0741f802003-06-02 14:15:34 +0000796 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
Greg Wardad4d9b92002-12-30 03:02:22 +0000797 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
798 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
Greg Wardf05aa102002-12-30 23:19:32 +0000799 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
800 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
Guido van Rossum0741f802003-06-02 14:15:34 +0000801
Greg Wardad4d9b92002-12-30 03:02:22 +0000802 { NULL, NULL}
Greg Ward3d9994d2002-12-11 15:12:01 +0000803};
804
Greg Ward04613a92002-11-30 22:47:45 +0000805static PyObject *
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000806oss_getattro(oss_audio_t *self, PyObject *nameobj)
Greg Ward04613a92002-11-30 22:47:45 +0000807{
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000808 char *name = "";
Greg Ward50682d02005-03-07 01:41:11 +0000809 PyObject * rval = NULL;
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000810
811 if (PyUnicode_Check(nameobj))
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000812 name = _PyUnicode_AsString(nameobj);
813
Greg Ward50682d02005-03-07 01:41:11 +0000814 if (strcmp(name, "closed") == 0) {
815 rval = (self->fd == -1) ? Py_True : Py_False;
816 Py_INCREF(rval);
817 }
818 else if (strcmp(name, "name") == 0) {
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000819 rval = PyUnicode_FromString(self->devicename);
Greg Ward50682d02005-03-07 01:41:11 +0000820 }
821 else if (strcmp(name, "mode") == 0) {
822 /* No need for a "default" in this switch: from newossobject(),
823 self->mode can only be one of these three values. */
824 switch(self->mode) {
825 case O_RDONLY:
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000826 rval = PyUnicode_FromString("r");
Greg Ward50682d02005-03-07 01:41:11 +0000827 break;
828 case O_RDWR:
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000829 rval = PyUnicode_FromString("rw");
Greg Ward50682d02005-03-07 01:41:11 +0000830 break;
831 case O_WRONLY:
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000832 rval = PyUnicode_FromString("w");
Greg Ward50682d02005-03-07 01:41:11 +0000833 break;
834 }
835 }
836 else {
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000837 rval = PyObject_GenericGetAttr((PyObject *)self, nameobj);
Greg Ward50682d02005-03-07 01:41:11 +0000838 }
839 return rval;
Greg Ward04613a92002-11-30 22:47:45 +0000840}
841
Greg Ward499b73e2002-12-31 03:04:52 +0000842static PyTypeObject OSSAudioType = {
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000843 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Greg Ward9a568eb2002-11-30 23:20:09 +0000844 "ossaudiodev.oss_audio_device", /*tp_name*/
Greg Ward499b73e2002-12-31 03:04:52 +0000845 sizeof(oss_audio_t), /*tp_size*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000846 0, /*tp_itemsize*/
Greg Ward04613a92002-11-30 22:47:45 +0000847 /* methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000848 (destructor)oss_dealloc, /*tp_dealloc*/
849 0, /*tp_print*/
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000850 0, /*tp_getattr*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000851 0, /*tp_setattr*/
Mark Dickinsone94c6792009-02-02 20:36:42 +0000852 0, /*tp_reserved*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000853 0, /*tp_repr*/
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000854 0, /*tp_as_number*/
855 0, /*tp_as_sequence*/
856 0, /*tp_as_mapping*/
857 0, /*tp_hash*/
858 0, /*tp_call*/
859 0, /*tp_str*/
860 (getattrofunc)oss_getattro, /*tp_getattro*/
861 0, /*tp_setattro*/
862 0, /*tp_as_buffer*/
863 Py_TPFLAGS_DEFAULT, /*tp_flags*/
864 0, /*tp_doc*/
865 0, /*tp_traverse*/
866 0, /*tp_clear*/
867 0, /*tp_richcompare*/
868 0, /*tp_weaklistoffset*/
869 0, /*tp_iter*/
870 0, /*tp_iternext*/
871 oss_methods, /*tp_methods*/
Greg Ward04613a92002-11-30 22:47:45 +0000872};
873
Greg Ward3d9994d2002-12-11 15:12:01 +0000874static PyTypeObject OSSMixerType = {
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000875 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Greg Ward3d9994d2002-12-11 15:12:01 +0000876 "ossaudiodev.oss_mixer_device", /*tp_name*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000877 sizeof(oss_mixer_t), /*tp_size*/
878 0, /*tp_itemsize*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000879 /* methods */
880 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000881 0, /*tp_print*/
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000882 0, /*tp_getattr*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000883 0, /*tp_setattr*/
Mark Dickinsone94c6792009-02-02 20:36:42 +0000884 0, /*tp_reserved*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000885 0, /*tp_repr*/
Amaury Forgeot d'Arc1f900f12008-07-02 22:38:47 +0000886 0, /*tp_as_number*/
887 0, /*tp_as_sequence*/
888 0, /*tp_as_mapping*/
889 0, /*tp_hash*/
890 0, /*tp_call*/
891 0, /*tp_str*/
892 0, /*tp_getattro*/
893 0, /*tp_setattro*/
894 0, /*tp_as_buffer*/
895 Py_TPFLAGS_DEFAULT, /*tp_flags*/
896 0, /*tp_doc*/
897 0, /*tp_traverse*/
898 0, /*tp_clear*/
899 0, /*tp_richcompare*/
900 0, /*tp_weaklistoffset*/
901 0, /*tp_iter*/
902 0, /*tp_iternext*/
903 oss_mixer_methods, /*tp_methods*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000904};
905
906
Greg Ward04613a92002-11-30 22:47:45 +0000907static PyObject *
Greg Ward9a568eb2002-11-30 23:20:09 +0000908ossopen(PyObject *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000909{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000910 return (PyObject *)newossobject(args);
Greg Ward04613a92002-11-30 22:47:45 +0000911}
912
Greg Ward3d9994d2002-12-11 15:12:01 +0000913static PyObject *
914ossopenmixer(PyObject *self, PyObject *args)
915{
916 return (PyObject *)newossmixerobject(args);
917}
918
Greg Ward9a568eb2002-11-30 23:20:09 +0000919static PyMethodDef ossaudiodev_methods[] = {
920 { "open", ossopen, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000921 { "openmixer", ossopenmixer, METH_VARARGS },
Greg Ward04613a92002-11-30 22:47:45 +0000922 { 0, 0 },
923};
924
Greg Ward1e0f57d2002-11-30 23:05:26 +0000925
926#define _EXPORT_INT(mod, name) \
Martin v. Löwis1a214512008-06-11 05:26:20 +0000927 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return NULL;
Greg Ward1e0f57d2002-11-30 23:05:26 +0000928
Greg Ward744f0fd2002-12-31 03:23:59 +0000929
930static char *control_labels[] = SOUND_DEVICE_LABELS;
931static char *control_names[] = SOUND_DEVICE_NAMES;
932
933
934static int
935build_namelists (PyObject *module)
936{
937 PyObject *labels;
938 PyObject *names;
939 PyObject *s;
940 int num_controls;
941 int i;
942
943 num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
944 assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
945
946 labels = PyList_New(num_controls);
947 names = PyList_New(num_controls);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000948 if (labels == NULL || names == NULL)
949 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000950 for (i = 0; i < num_controls; i++) {
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000951 s = PyUnicode_FromString(control_labels[i]);
Greg Ward744f0fd2002-12-31 03:23:59 +0000952 if (s == NULL)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000953 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000954 PyList_SET_ITEM(labels, i, s);
Guido van Rossum0741f802003-06-02 14:15:34 +0000955
Neal Norwitz8abd2e62007-08-26 04:57:08 +0000956 s = PyUnicode_FromString(control_names[i]);
Greg Ward744f0fd2002-12-31 03:23:59 +0000957 if (s == NULL)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000958 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000959 PyList_SET_ITEM(names, i, s);
960 }
961
962 if (PyModule_AddObject(module, "control_labels", labels) == -1)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000963 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000964 if (PyModule_AddObject(module, "control_names", names) == -1)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000965 goto error1;
Greg Ward744f0fd2002-12-31 03:23:59 +0000966
967 return 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000968
969error2:
970 Py_XDECREF(labels);
971error1:
972 Py_XDECREF(names);
973 return -1;
Guido van Rossum0741f802003-06-02 14:15:34 +0000974}
Greg Ward744f0fd2002-12-31 03:23:59 +0000975
976
Martin v. Löwis1a214512008-06-11 05:26:20 +0000977static struct PyModuleDef ossaudiodevmodule = {
Antoine Pitrouf95a1b32010-05-09 15:52:27 +0000978 PyModuleDef_HEAD_INIT,
979 "ossaudiodev",
980 NULL,
981 -1,
982 ossaudiodev_methods,
983 NULL,
984 NULL,
985 NULL,
986 NULL
Martin v. Löwis1a214512008-06-11 05:26:20 +0000987};
988
Antoine Pitrou39b35432010-03-23 00:25:54 +0000989PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +0000990PyInit_ossaudiodev(void)
Greg Ward04613a92002-11-30 22:47:45 +0000991{
992 PyObject *m;
Guido van Rossum0741f802003-06-02 14:15:34 +0000993
Antoine Pitrou39b35432010-03-23 00:25:54 +0000994 if (PyType_Ready(&OSSAudioType) < 0)
995 return NULL;
996
997 if (PyType_Ready(&OSSMixerType) < 0)
998 return NULL;
999
Martin v. Löwis1a214512008-06-11 05:26:20 +00001000 m = PyModule_Create(&ossaudiodevmodule);
Neal Norwitz1ac754f2006-01-19 06:09:39 +00001001 if (m == NULL)
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001002 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +00001003
Guido van Rossum0741f802003-06-02 14:15:34 +00001004 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
Antoine Pitrouf95a1b32010-05-09 15:52:27 +00001005 NULL, NULL);
Greg Wardd6769062003-05-29 21:53:06 +00001006 if (OSSAudioError) {
Guido van Rossum0741f802003-06-02 14:15:34 +00001007 /* Each call to PyModule_AddObject decrefs it; compensate: */
1008 Py_INCREF(OSSAudioError);
1009 Py_INCREF(OSSAudioError);
Greg Wardad4d9b92002-12-30 03:02:22 +00001010 PyModule_AddObject(m, "error", OSSAudioError);
Greg Wardd6769062003-05-29 21:53:06 +00001011 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
1012 }
Greg Ward04613a92002-11-30 22:47:45 +00001013
Greg Ward744f0fd2002-12-31 03:23:59 +00001014 /* Build 'control_labels' and 'control_names' lists and add them
1015 to the module. */
1016 if (build_namelists(m) == -1) /* XXX what to do here? */
Martin v. Löwis1a214512008-06-11 05:26:20 +00001017 return NULL;
Greg Ward744f0fd2002-12-31 03:23:59 +00001018
Greg Ward1e0f57d2002-11-30 23:05:26 +00001019 /* Expose the audio format numbers -- essential! */
1020 _EXPORT_INT(m, AFMT_QUERY);
1021 _EXPORT_INT(m, AFMT_MU_LAW);
1022 _EXPORT_INT(m, AFMT_A_LAW);
1023 _EXPORT_INT(m, AFMT_IMA_ADPCM);
1024 _EXPORT_INT(m, AFMT_U8);
1025 _EXPORT_INT(m, AFMT_S16_LE);
1026 _EXPORT_INT(m, AFMT_S16_BE);
1027 _EXPORT_INT(m, AFMT_S8);
1028 _EXPORT_INT(m, AFMT_U16_LE);
1029 _EXPORT_INT(m, AFMT_U16_BE);
1030 _EXPORT_INT(m, AFMT_MPEG);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +00001031#ifdef AFMT_AC3
Greg Ward1e0f57d2002-11-30 23:05:26 +00001032 _EXPORT_INT(m, AFMT_AC3);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +00001033#endif
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001034#ifdef AFMT_S16_NE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001035 _EXPORT_INT(m, AFMT_S16_NE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001036#endif
Greg Ward0f260542005-03-28 02:40:46 +00001037#ifdef AFMT_U16_NE
1038 _EXPORT_INT(m, AFMT_U16_NE);
1039#endif
1040#ifdef AFMT_S32_LE
1041 _EXPORT_INT(m, AFMT_S32_LE);
1042#endif
1043#ifdef AFMT_S32_BE
1044 _EXPORT_INT(m, AFMT_S32_BE);
1045#endif
1046#ifdef AFMT_MPEG
1047 _EXPORT_INT(m, AFMT_MPEG);
1048#endif
Guido van Rossum0741f802003-06-02 14:15:34 +00001049
Greg Ward37897c22002-12-30 02:43:36 +00001050 /* Expose the sound mixer device numbers. */
Greg Ward7b43c682002-12-30 02:29:28 +00001051 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
Greg Ward3d9994d2002-12-11 15:12:01 +00001052 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1053 _EXPORT_INT(m, SOUND_MIXER_BASS);
1054 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1055 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1056 _EXPORT_INT(m, SOUND_MIXER_PCM);
1057 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1058 _EXPORT_INT(m, SOUND_MIXER_LINE);
1059 _EXPORT_INT(m, SOUND_MIXER_MIC);
1060 _EXPORT_INT(m, SOUND_MIXER_CD);
1061 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1062 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1063 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1064 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1065 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1066 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1067 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1068 _EXPORT_INT(m, SOUND_MIXER_LINE3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001069#ifdef SOUND_MIXER_DIGITAL1
Greg Ward3d9994d2002-12-11 15:12:01 +00001070 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
Greg Wardfd0283e2004-05-11 01:34:55 +00001071#endif
1072#ifdef SOUND_MIXER_DIGITAL2
Greg Ward3d9994d2002-12-11 15:12:01 +00001073 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
Greg Wardfd0283e2004-05-11 01:34:55 +00001074#endif
1075#ifdef SOUND_MIXER_DIGITAL3
Greg Ward3d9994d2002-12-11 15:12:01 +00001076 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001077#endif
1078#ifdef SOUND_MIXER_PHONEIN
Greg Ward3d9994d2002-12-11 15:12:01 +00001079 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
Greg Wardfd0283e2004-05-11 01:34:55 +00001080#endif
1081#ifdef SOUND_MIXER_PHONEOUT
Greg Ward3d9994d2002-12-11 15:12:01 +00001082 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
Greg Wardfd0283e2004-05-11 01:34:55 +00001083#endif
1084#ifdef SOUND_MIXER_VIDEO
Greg Ward3d9994d2002-12-11 15:12:01 +00001085 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001086#endif
1087#ifdef SOUND_MIXER_RADIO
Greg Ward3d9994d2002-12-11 15:12:01 +00001088 _EXPORT_INT(m, SOUND_MIXER_RADIO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001089#endif
1090#ifdef SOUND_MIXER_MONITOR
Greg Ward3d9994d2002-12-11 15:12:01 +00001091 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
Greg Wardfd0283e2004-05-11 01:34:55 +00001092#endif
Greg Ward04613a92002-11-30 22:47:45 +00001093
Greg Ward1e0f57d2002-11-30 23:05:26 +00001094 /* Expose all the ioctl numbers for masochists who like to do this
1095 stuff directly. */
1096 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1097 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1098 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1099 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1100 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1101 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1102 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1103 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1104 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1105 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001106#ifdef SNDCTL_DSP_BIND_CHANNEL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001107 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001108#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001109 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1110 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1111 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001112#ifdef SNDCTL_DSP_GETCHANNELMASK
Greg Ward1e0f57d2002-11-30 23:05:26 +00001113 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001114#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001115 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1116 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1117 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
Greg Wardfd0283e2004-05-11 01:34:55 +00001118#ifdef SNDCTL_DSP_GETODELAY
Greg Ward1e0f57d2002-11-30 23:05:26 +00001119 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
Greg Wardfd0283e2004-05-11 01:34:55 +00001120#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001121 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1122 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001123#ifdef SNDCTL_DSP_GETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001124 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001125#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001126 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1127 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1128 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1129 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1130 _EXPORT_INT(m, SNDCTL_DSP_POST);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001131#ifdef SNDCTL_DSP_PROFILE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001132 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001133#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001134 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1135 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1136 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1137 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1138 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001139#ifdef SNDCTL_DSP_SETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001140 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001141#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001142 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1143 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1144 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1145 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1146 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1147 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1148 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1149 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1150 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1151 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1152 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1153 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1154 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1155 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1156 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001157#ifdef SNDCTL_SEQ_GETTIME
Greg Ward1e0f57d2002-11-30 23:05:26 +00001158 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001159#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001160 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1161 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1162 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1163 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1164 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1165 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1166 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1167 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1168 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1169 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001170#ifdef SNDCTL_SYNTH_CONTROL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001171 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001172#endif
1173#ifdef SNDCTL_SYNTH_ID
Greg Ward1e0f57d2002-11-30 23:05:26 +00001174 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001175#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001176 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1177 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001178#ifdef SNDCTL_SYNTH_REMOVESAMPLE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001179 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001180#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001181 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1182 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1183 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1184 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1185 _EXPORT_INT(m, SNDCTL_TMR_START);
1186 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1187 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1188 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
Martin v. Löwis1a214512008-06-11 05:26:20 +00001189 return m;
Greg Ward04613a92002-11-30 22:47:45 +00001190}