blob: 9716838ba231dd945e0a32cf53f12b37d9c20753 [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
37typedef unsigned long uint32_t;
38
39#elif defined(__FreeBSD__)
Greg Ward04613a92002-11-30 22:47:45 +000040
Greg Ward0b6dfb82003-03-10 03:17:06 +000041# ifndef SNDCTL_DSP_CHANNELS
42# define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
43# endif
Greg Ward04613a92002-11-30 22:47:45 +000044
45#endif
46
47typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000048 PyObject_HEAD
Greg Ward50682d02005-03-07 01:41:11 +000049 char *devicename; /* name of the device file */
50 int fd; /* file descriptor */
51 int mode; /* file mode (O_RDONLY, etc.) */
52 int icount; /* input count */
53 int ocount; /* output count */
54 uint32_t afmts; /* audio formats supported by hardware */
Greg Ward499b73e2002-12-31 03:04:52 +000055} oss_audio_t;
Greg Ward04613a92002-11-30 22:47:45 +000056
Greg Ward3d9994d2002-12-11 15:12:01 +000057typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000058 PyObject_HEAD
Greg Wardad4d9b92002-12-30 03:02:22 +000059 int fd; /* The open mixer device */
Greg Ward3d9994d2002-12-11 15:12:01 +000060} oss_mixer_t;
61
Greg Ward04613a92002-11-30 22:47:45 +000062
Greg Ward499b73e2002-12-31 03:04:52 +000063static PyTypeObject OSSAudioType;
Greg Ward3d9994d2002-12-11 15:12:01 +000064static PyTypeObject OSSMixerType;
Greg Ward04613a92002-11-30 22:47:45 +000065
Greg Ward97708bc2002-11-30 23:17:10 +000066static PyObject *OSSAudioError;
Greg Ward04613a92002-11-30 22:47:45 +000067
Greg Wardda1cacb2002-12-31 03:02:23 +000068
69/* ----------------------------------------------------------------------
70 * DSP object initialization/deallocation
71 */
72
Greg Ward499b73e2002-12-31 03:04:52 +000073static oss_audio_t *
Greg Ward8c6b6a92002-12-11 14:43:13 +000074newossobject(PyObject *arg)
Greg Ward04613a92002-11-30 22:47:45 +000075{
Greg Ward58ae13c2002-12-31 03:07:21 +000076 oss_audio_t *self;
Greg Ward04613a92002-11-30 22:47:45 +000077 int fd, afmts, imode;
Greg Ward50682d02005-03-07 01:41:11 +000078 char *devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000079 char *mode = NULL;
80
Greg Ward9a568eb2002-11-30 23:20:09 +000081 /* Two ways to call open():
Greg Ward04613a92002-11-30 22:47:45 +000082 open(device, mode) (for consistency with builtin open())
83 open(mode) (for backwards compatibility)
84 because the *first* argument is optional, parsing args is
85 a wee bit tricky. */
Greg Ward50682d02005-03-07 01:41:11 +000086 if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
Greg Ward04613a92002-11-30 22:47:45 +000087 return NULL;
88 if (mode == NULL) { /* only one arg supplied */
Greg Ward50682d02005-03-07 01:41:11 +000089 mode = devicename;
90 devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000091 }
92
93 if (strcmp(mode, "r") == 0)
94 imode = O_RDONLY;
95 else if (strcmp(mode, "w") == 0)
96 imode = O_WRONLY;
Greg Ward1e0f57d2002-11-30 23:05:26 +000097 else if (strcmp(mode, "rw") == 0)
98 imode = O_RDWR;
Greg Ward04613a92002-11-30 22:47:45 +000099 else {
Greg Ward97708bc2002-11-30 23:17:10 +0000100 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
Greg Ward04613a92002-11-30 22:47:45 +0000101 return NULL;
102 }
103
Greg Ward5c5c5772002-12-30 02:58:04 +0000104 /* Open the correct device: either the 'device' argument,
105 or the AUDIODEV environment variable, or "/dev/dsp". */
Greg Ward50682d02005-03-07 01:41:11 +0000106 if (devicename == NULL) { /* called with one arg */
107 devicename = getenv("AUDIODEV");
108 if (devicename == NULL) /* $AUDIODEV not set */
109 devicename = "/dev/dsp";
Greg Ward04613a92002-11-30 22:47:45 +0000110 }
111
Greg Ward5c49ef22003-03-11 16:53:13 +0000112 /* Open with O_NONBLOCK to avoid hanging on devices that only allow
113 one open at a time. This does *not* affect later I/O; OSS
114 provides a special ioctl() for non-blocking read/write, which is
115 exposed via oss_nonblock() below. */
Greg Ward50682d02005-03-07 01:41:11 +0000116 if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) {
117 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000118 return NULL;
119 }
Greg Ward76ffb192003-04-04 01:47:42 +0000120
121 /* And (try to) put it back in blocking mode so we get the
122 expected write() semantics. */
123 if (fcntl(fd, F_SETFL, 0) == -1) {
124 close(fd);
Greg Ward50682d02005-03-07 01:41:11 +0000125 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward76ffb192003-04-04 01:47:42 +0000126 return NULL;
127 }
128
Greg Ward04613a92002-11-30 22:47:45 +0000129 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
Greg Ward50682d02005-03-07 01:41:11 +0000130 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000131 return NULL;
132 }
133 /* Create and initialize the object */
Greg Ward58ae13c2002-12-31 03:07:21 +0000134 if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) {
Greg Ward04613a92002-11-30 22:47:45 +0000135 close(fd);
136 return NULL;
137 }
Greg Ward50682d02005-03-07 01:41:11 +0000138 self->devicename = devicename;
Greg Ward58ae13c2002-12-31 03:07:21 +0000139 self->fd = fd;
140 self->mode = imode;
141 self->icount = self->ocount = 0;
142 self->afmts = afmts;
143 return self;
Greg Ward04613a92002-11-30 22:47:45 +0000144}
145
146static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000147oss_dealloc(oss_audio_t *self)
Greg Ward04613a92002-11-30 22:47:45 +0000148{
149 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000150 if (self->fd != -1)
151 close(self->fd);
152 PyObject_Del(self);
Greg Ward04613a92002-11-30 22:47:45 +0000153}
154
Greg Wardda1cacb2002-12-31 03:02:23 +0000155
156/* ----------------------------------------------------------------------
157 * Mixer object initialization/deallocation
158 */
159
Greg Ward3d9994d2002-12-11 15:12:01 +0000160static oss_mixer_t *
161newossmixerobject(PyObject *arg)
162{
Greg Ward50682d02005-03-07 01:41:11 +0000163 char *devicename = NULL;
Greg Ward0b6dfb82003-03-10 03:17:06 +0000164 int fd;
Greg Ward58ae13c2002-12-31 03:07:21 +0000165 oss_mixer_t *self;
Guido van Rossum0741f802003-06-02 14:15:34 +0000166
Greg Ward50682d02005-03-07 01:41:11 +0000167 if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000168 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000169 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000170
Greg Ward50682d02005-03-07 01:41:11 +0000171 if (devicename == NULL) {
172 devicename = getenv("MIXERDEV");
173 if (devicename == NULL) /* MIXERDEV not set */
174 devicename = "/dev/mixer";
Greg Ward3d9994d2002-12-11 15:12:01 +0000175 }
176
Greg Ward50682d02005-03-07 01:41:11 +0000177 if ((fd = open(devicename, O_RDWR)) == -1) {
178 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward3d9994d2002-12-11 15:12:01 +0000179 return NULL;
180 }
Greg Ward0b6dfb82003-03-10 03:17:06 +0000181
Greg Ward58ae13c2002-12-31 03:07:21 +0000182 if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
Greg Ward3d9994d2002-12-11 15:12:01 +0000183 close(fd);
184 return NULL;
185 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000186
Greg Ward58ae13c2002-12-31 03:07:21 +0000187 self->fd = fd;
Guido van Rossum0741f802003-06-02 14:15:34 +0000188
Greg Ward58ae13c2002-12-31 03:07:21 +0000189 return self;
Greg Ward3d9994d2002-12-11 15:12:01 +0000190}
191
192static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000193oss_mixer_dealloc(oss_mixer_t *self)
Greg Ward3d9994d2002-12-11 15:12:01 +0000194{
195 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000196 if (self->fd != -1)
197 close(self->fd);
198 PyObject_Del(self);
Greg Ward3d9994d2002-12-11 15:12:01 +0000199}
200
Greg Ward131bce02002-11-30 22:56:44 +0000201
202/* Methods to wrap the OSS ioctls. The calling convention is pretty
203 simple:
204 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
205 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
206 etc.
207*/
208
209
Greg Wardd6769062003-05-29 21:53:06 +0000210/* ----------------------------------------------------------------------
211 * Helper functions
212 */
213
Greg Ward131bce02002-11-30 22:56:44 +0000214/* _do_ioctl_1() is a private helper function used for the OSS ioctls --
215 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C
216 like this:
217 ioctl(fd, SNDCTL_DSP_cmd, &arg)
218
219 where arg is the value to set, and on return the driver sets arg to
220 the value that was actually set. Mapping this to Python is obvious:
221 arg = dsp.xxx(arg)
222*/
223static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000224_do_ioctl_1(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000225{
Greg Wardda9f8532002-12-11 14:49:59 +0000226 char argfmt[33] = "i:";
Greg Ward131bce02002-11-30 22:56:44 +0000227 int arg;
228
Greg Wardda9f8532002-12-11 14:49:59 +0000229 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000230 strcat(argfmt, fname);
231 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000232 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000233
Greg Wardda9f8532002-12-11 14:49:59 +0000234 if (ioctl(fd, cmd, &arg) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000235 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000236 return PyInt_FromLong(arg);
237}
238
Greg Wardda1cacb2002-12-31 03:02:23 +0000239
Greg Ward3d9994d2002-12-11 15:12:01 +0000240/* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
241 but return an output -- ie. we need to pass a pointer to a local C
242 variable so the driver can write its output there, but from Python
243 all we see is the return value. For example,
244 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
245 devices, but does not use the value of the parameter passed-in in any
246 way.
247*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000248static PyObject *
249_do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd)
250{
251 char argfmt[32] = ":";
252 int arg = 0;
253
254 assert(strlen(fname) <= 30);
255 strcat(argfmt, fname);
256 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000257 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000258
259 if (ioctl(fd, cmd, &arg) == -1)
260 return PyErr_SetFromErrno(PyExc_IOError);
261 return PyInt_FromLong(arg);
262}
263
264
265
Greg Ward131bce02002-11-30 22:56:44 +0000266/* _do_ioctl_0() is a private helper for the no-argument ioctls:
267 SNDCTL_DSP_{SYNC,RESET,POST}. */
268static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000269_do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000270{
Greg Wardda9f8532002-12-11 14:49:59 +0000271 char argfmt[32] = ":";
Greg Wardd0d592f2003-05-27 01:57:21 +0000272 int rv;
Greg Ward131bce02002-11-30 22:56:44 +0000273
Greg Wardda9f8532002-12-11 14:49:59 +0000274 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000275 strcat(argfmt, fname);
276 if (!PyArg_ParseTuple(args, argfmt))
Greg Wardad4d9b92002-12-30 03:02:22 +0000277 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000278
Greg Wardd0d592f2003-05-27 01:57:21 +0000279 /* According to hannu@opensound.com, all three of the ioctls that
280 use this function can block, so release the GIL. This is
281 especially important for SYNC, which can block for several
282 seconds. */
283 Py_BEGIN_ALLOW_THREADS
284 rv = ioctl(fd, cmd, 0);
285 Py_END_ALLOW_THREADS
286
287 if (rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000288 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000289 Py_INCREF(Py_None);
290 return Py_None;
291}
292
293
Greg Wardda1cacb2002-12-31 03:02:23 +0000294/* ----------------------------------------------------------------------
Greg Ward499b73e2002-12-31 03:04:52 +0000295 * Methods of DSP objects (OSSAudioType)
Greg Wardda1cacb2002-12-31 03:02:23 +0000296 */
297
Greg Ward131bce02002-11-30 22:56:44 +0000298static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000299oss_nonblock(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000300{
301 /* Hmmm: it doesn't appear to be possible to return to blocking
302 mode once we're in non-blocking mode! */
Greg Ward7b43c682002-12-30 02:29:28 +0000303 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000304 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000305 Py_INCREF(Py_None);
306 return Py_None;
307}
308
309static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000310oss_setfmt(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000311{
Greg Ward7b43c682002-12-30 02:29:28 +0000312 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
Greg Ward131bce02002-11-30 22:56:44 +0000313}
314
315static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000316oss_getfmts(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000317{
318 int mask;
Greg Ward7b43c682002-12-30 02:29:28 +0000319 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000320 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000321 return PyInt_FromLong(mask);
322}
323
324static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000325oss_channels(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000326{
Greg Ward7b43c682002-12-30 02:29:28 +0000327 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
Greg Ward131bce02002-11-30 22:56:44 +0000328}
329
330static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000331oss_speed(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000332{
Greg Ward7b43c682002-12-30 02:29:28 +0000333 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
Greg Ward131bce02002-11-30 22:56:44 +0000334}
335
336static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000337oss_sync(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000338{
Greg Wardd0d592f2003-05-27 01:57:21 +0000339 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
Greg Ward131bce02002-11-30 22:56:44 +0000340}
Guido van Rossum0741f802003-06-02 14:15:34 +0000341
Greg Ward131bce02002-11-30 22:56:44 +0000342static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000343oss_reset(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000344{
Greg Ward7b43c682002-12-30 02:29:28 +0000345 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
Greg Ward131bce02002-11-30 22:56:44 +0000346}
Guido van Rossum0741f802003-06-02 14:15:34 +0000347
Greg Ward131bce02002-11-30 22:56:44 +0000348static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000349oss_post(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000350{
Greg Ward7b43c682002-12-30 02:29:28 +0000351 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
Greg Ward131bce02002-11-30 22:56:44 +0000352}
353
354
355/* Regular file methods: read(), write(), close(), etc. as well
356 as one convenience method, writeall(). */
357
Greg Ward04613a92002-11-30 22:47:45 +0000358static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000359oss_read(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000360{
361 int size, count;
362 char *cp;
363 PyObject *rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000364
Greg Ward04613a92002-11-30 22:47:45 +0000365 if (!PyArg_ParseTuple(args, "i:read", &size))
366 return NULL;
367 rv = PyString_FromStringAndSize(NULL, size);
368 if (rv == NULL)
369 return NULL;
370 cp = PyString_AS_STRING(rv);
Greg Ward64927852003-05-23 01:50:37 +0000371
372 Py_BEGIN_ALLOW_THREADS
373 count = read(self->fd, cp, size);
374 Py_END_ALLOW_THREADS
375
376 if (count < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000377 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000378 Py_DECREF(rv);
379 return NULL;
380 }
Greg Ward7b43c682002-12-30 02:29:28 +0000381 self->icount += count;
Greg Ward04613a92002-11-30 22:47:45 +0000382 _PyString_Resize(&rv, count);
383 return rv;
384}
385
386static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000387oss_write(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000388{
389 char *cp;
390 int rv, size;
Greg Ward131bce02002-11-30 22:56:44 +0000391
392 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000393 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000394 }
Greg Ward64927852003-05-23 01:50:37 +0000395
396 Py_BEGIN_ALLOW_THREADS
397 rv = write(self->fd, cp, size);
398 Py_END_ALLOW_THREADS
399
400 if (rv == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000401 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000402 } else {
Greg Ward7b43c682002-12-30 02:29:28 +0000403 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000404 }
405 return PyInt_FromLong(rv);
406}
407
408static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000409oss_writeall(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000410{
411 char *cp;
412 int rv, size;
413 fd_set write_set_fds;
414 int select_rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000415
Greg Ward131bce02002-11-30 22:56:44 +0000416 /* NB. writeall() is only useful in non-blocking mode: according to
417 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
418 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
419 write() in blocking mode consumes the whole buffer. In blocking
420 mode, the behaviour of write() and writeall() from Python is
421 indistinguishable. */
422
Guido van Rossum0741f802003-06-02 14:15:34 +0000423 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
Greg Ward131bce02002-11-30 22:56:44 +0000424 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000425
426 /* use select to wait for audio device to be available */
427 FD_ZERO(&write_set_fds);
Greg Ward7b43c682002-12-30 02:29:28 +0000428 FD_SET(self->fd, &write_set_fds);
Greg Ward04613a92002-11-30 22:47:45 +0000429
430 while (size > 0) {
Greg Ward64927852003-05-23 01:50:37 +0000431 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000432 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Greg Ward64927852003-05-23 01:50:37 +0000433 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000434 assert(select_rv != 0); /* no timeout, can't expire */
435 if (select_rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000436 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000437
Greg Ward64927852003-05-23 01:50:37 +0000438 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000439 rv = write(self->fd, cp, size);
Greg Ward64927852003-05-23 01:50:37 +0000440 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000441 if (rv == -1) {
442 if (errno == EAGAIN) { /* buffer is full, try again */
443 errno = 0;
444 continue;
445 } else /* it's a real error */
Greg Ward97708bc2002-11-30 23:17:10 +0000446 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000447 } else { /* wrote rv bytes */
Greg Ward7b43c682002-12-30 02:29:28 +0000448 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000449 size -= rv;
450 cp += rv;
451 }
Greg Ward04613a92002-11-30 22:47:45 +0000452 }
453 Py_INCREF(Py_None);
454 return Py_None;
455}
456
457static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000458oss_close(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000459{
Greg Ward7b43c682002-12-30 02:29:28 +0000460 if (self->fd >= 0) {
Greg Wardb8043902003-05-26 22:47:30 +0000461 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000462 close(self->fd);
Greg Wardb8043902003-05-26 22:47:30 +0000463 Py_END_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000464 self->fd = -1;
Greg Ward04613a92002-11-30 22:47:45 +0000465 }
466 Py_INCREF(Py_None);
467 return Py_None;
468}
469
470static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000471oss_fileno(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000472{
Greg Ward7b43c682002-12-30 02:29:28 +0000473 return PyInt_FromLong(self->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000474}
475
Greg Ward131bce02002-11-30 22:56:44 +0000476
477/* Convenience methods: these generally wrap a couple of ioctls into one
478 common task. */
479
Greg Ward04613a92002-11-30 22:47:45 +0000480static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000481oss_setparameters(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000482{
Greg Wardd6769062003-05-29 21:53:06 +0000483 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
484 int fmt, channels, rate;
485 PyObject * rv; /* return tuple (fmt, channels, rate) */
Greg Ward04613a92002-11-30 22:47:45 +0000486
Greg Wardd6769062003-05-29 21:53:06 +0000487 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
488 &wanted_fmt, &wanted_channels, &wanted_rate,
489 &strict))
Greg Ward04613a92002-11-30 22:47:45 +0000490 return NULL;
Greg Wardd6769062003-05-29 21:53:06 +0000491
492 fmt = wanted_fmt;
493 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
494 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000495 }
Greg Wardd6769062003-05-29 21:53:06 +0000496 if (strict && fmt != wanted_fmt) {
497 return PyErr_Format
498 (OSSAudioError,
499 "unable to set requested format (wanted %d, got %d)",
500 wanted_fmt, fmt);
Greg Ward04613a92002-11-30 22:47:45 +0000501 }
502
Greg Wardd6769062003-05-29 21:53:06 +0000503 channels = wanted_channels;
504 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
505 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000506 }
Greg Wardd6769062003-05-29 21:53:06 +0000507 if (strict && channels != wanted_channels) {
508 return PyErr_Format
509 (OSSAudioError,
510 "unable to set requested channels (wanted %d, got %d)",
511 wanted_channels, channels);
Greg Ward04613a92002-11-30 22:47:45 +0000512 }
513
Greg Wardd6769062003-05-29 21:53:06 +0000514 rate = wanted_rate;
Greg Ward7b43c682002-12-30 02:29:28 +0000515 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Greg Wardd6769062003-05-29 21:53:06 +0000516 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000517 }
Greg Wardd6769062003-05-29 21:53:06 +0000518 if (strict && rate != wanted_rate) {
519 return PyErr_Format
520 (OSSAudioError,
521 "unable to set requested rate (wanted %d, got %d)",
522 wanted_rate, rate);
523 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000524
Greg Wardd6769062003-05-29 21:53:06 +0000525 /* Construct the return value: a (fmt, channels, rate) tuple that
526 tells what the audio hardware was actually set to. */
527 rv = PyTuple_New(3);
528 if (rv == NULL)
529 return NULL;
530 PyTuple_SET_ITEM(rv, 0, PyInt_FromLong(fmt));
531 PyTuple_SET_ITEM(rv, 1, PyInt_FromLong(channels));
532 PyTuple_SET_ITEM(rv, 2, PyInt_FromLong(rate));
533 return rv;
Greg Ward04613a92002-11-30 22:47:45 +0000534}
535
536static int
Greg Ward499b73e2002-12-31 03:04:52 +0000537_ssize(oss_audio_t *self, int *nchannels, int *ssize)
Greg Ward04613a92002-11-30 22:47:45 +0000538{
539 int fmt;
540
541 fmt = 0;
Guido van Rossum0741f802003-06-02 14:15:34 +0000542 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000543 return -errno;
544
545 switch (fmt) {
546 case AFMT_MU_LAW:
547 case AFMT_A_LAW:
548 case AFMT_U8:
549 case AFMT_S8:
Greg Ward38c92662003-05-29 21:55:41 +0000550 *ssize = 1; /* 8 bit formats: 1 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000551 break;
552 case AFMT_S16_LE:
553 case AFMT_S16_BE:
554 case AFMT_U16_LE:
555 case AFMT_U16_BE:
Greg Ward84f8ecd2003-05-29 23:44:44 +0000556 *ssize = 2; /* 16 bit formats: 2 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000557 break;
558 case AFMT_MPEG:
559 case AFMT_IMA_ADPCM:
560 default:
561 return -EOPNOTSUPP;
562 }
Greg Ward7b43c682002-12-30 02:29:28 +0000563 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000564 return -errno;
565 return 0;
566}
567
568
Guido van Rossum0741f802003-06-02 14:15:34 +0000569/* bufsize returns the size of the hardware audio buffer in number
Greg Ward04613a92002-11-30 22:47:45 +0000570 of samples */
571static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000572oss_bufsize(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000573{
574 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000575 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000576
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000577 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000578 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000579 return NULL;
580 }
Greg Ward7b43c682002-12-30 02:29:28 +0000581 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000582 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000583 return NULL;
584 }
585 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
586}
587
Guido van Rossum0741f802003-06-02 14:15:34 +0000588/* obufcount returns the number of samples that are available in the
Greg Ward04613a92002-11-30 22:47:45 +0000589 hardware for playing */
590static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000591oss_obufcount(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000592{
593 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000594 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000595
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000596 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000597 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000598 return NULL;
599 }
Greg Ward7b43c682002-12-30 02:29:28 +0000600 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000601 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000602 return NULL;
603 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000604 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
Greg Ward04613a92002-11-30 22:47:45 +0000605 (ssize * nchannels));
606}
607
608/* obufcount returns the number of samples that can be played without
609 blocking */
610static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000611oss_obuffree(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000612{
613 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000614 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000615
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000616 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000617 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000618 return NULL;
619 }
Greg Ward7b43c682002-12-30 02:29:28 +0000620 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000621 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000622 return NULL;
623 }
624 return PyInt_FromLong(ai.bytes / (ssize * nchannels));
625}
626
Greg Ward04613a92002-11-30 22:47:45 +0000627static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000628oss_getptr(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000629{
630 count_info info;
631 int req;
632
Greg Ward7b43c682002-12-30 02:29:28 +0000633 if (self->mode == O_RDONLY)
Greg Wardad4d9b92002-12-30 03:02:22 +0000634 req = SNDCTL_DSP_GETIPTR;
Greg Ward04613a92002-11-30 22:47:45 +0000635 else
Greg Wardad4d9b92002-12-30 03:02:22 +0000636 req = SNDCTL_DSP_GETOPTR;
Greg Ward7b43c682002-12-30 02:29:28 +0000637 if (ioctl(self->fd, req, &info) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000638 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000639 return NULL;
640 }
641 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
642}
643
Greg Wardda1cacb2002-12-31 03:02:23 +0000644
645/* ----------------------------------------------------------------------
646 * Methods of mixer objects (OSSMixerType)
647 */
648
Greg Ward3d9994d2002-12-11 15:12:01 +0000649static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000650oss_mixer_close(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000651{
Greg Ward7b43c682002-12-30 02:29:28 +0000652 if (self->fd >= 0) {
653 close(self->fd);
654 self->fd = -1;
Greg Ward3d9994d2002-12-11 15:12:01 +0000655 }
656 Py_INCREF(Py_None);
657 return Py_None;
658}
659
660static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000661oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000662{
Greg Ward7b43c682002-12-30 02:29:28 +0000663 return PyInt_FromLong(self->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000664}
665
666/* Simple mixer interface methods */
667
668static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000669oss_mixer_controls(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000670{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000671 return _do_ioctl_1_internal(self->fd, args, "controls",
Greg Ward3d9994d2002-12-11 15:12:01 +0000672 SOUND_MIXER_READ_DEVMASK);
673}
674
675static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000676oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000677{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000678 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
Greg Ward3d9994d2002-12-11 15:12:01 +0000679 SOUND_MIXER_READ_STEREODEVS);
680}
681
682static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000683oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000684{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000685 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
Greg Wardb69bb3d2002-12-12 17:35:45 +0000686 SOUND_MIXER_READ_RECMASK);
Greg Ward3d9994d2002-12-11 15:12:01 +0000687}
688
689static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000690oss_mixer_get(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000691{
692 int channel, volume;
Guido van Rossum0741f802003-06-02 14:15:34 +0000693
Greg Ward3d9994d2002-12-11 15:12:01 +0000694 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000695 if (!PyArg_ParseTuple(args, "i:get", &channel))
Greg Wardad4d9b92002-12-30 03:02:22 +0000696 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000697
Greg Ward3d9994d2002-12-11 15:12:01 +0000698 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000699 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
700 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000701 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000702
Greg Warde7037662002-12-30 03:01:48 +0000703 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000704 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000705
Greg Warde7037662002-12-30 03:01:48 +0000706 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000707}
708
709static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000710oss_mixer_set(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000711{
712 int channel, volume, leftVol, rightVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000713
Greg Ward3d9994d2002-12-11 15:12:01 +0000714 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000715 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
Greg Wardad4d9b92002-12-30 03:02:22 +0000716 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000717
Greg Ward3d9994d2002-12-11 15:12:01 +0000718 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000719 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
720 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000721 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000722
Greg Ward3d9994d2002-12-11 15:12:01 +0000723 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000724 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
725 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000726 }
727
728 volume = (rightVol << 8) | leftVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000729
Greg Warde7037662002-12-30 03:01:48 +0000730 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000731 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000732
Greg Warde7037662002-12-30 03:01:48 +0000733 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000734}
735
736static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000737oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000738{
Greg Wardf05aa102002-12-30 23:19:32 +0000739 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000740 SOUND_MIXER_READ_RECSRC);
741}
742
743static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000744oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000745{
Greg Wardf05aa102002-12-30 23:19:32 +0000746 return _do_ioctl_1(self->fd, args, "set_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000747 SOUND_MIXER_WRITE_RECSRC);
748}
749
750
Greg Wardda1cacb2002-12-31 03:02:23 +0000751/* ----------------------------------------------------------------------
752 * Method tables and other bureaucracy
753 */
754
Greg Ward8c6b6a92002-12-11 14:43:13 +0000755static PyMethodDef oss_methods[] = {
Greg Ward131bce02002-11-30 22:56:44 +0000756 /* Regular file methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000757 { "read", (PyCFunction)oss_read, METH_VARARGS },
758 { "write", (PyCFunction)oss_write, METH_VARARGS },
759 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000760 { "close", (PyCFunction)oss_close, METH_NOARGS },
761 { "fileno", (PyCFunction)oss_fileno, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000762
763 /* Simple ioctl wrappers */
Georg Brandl96a8c392006-05-29 21:04:52 +0000764 { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000765 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000766 { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS },
Greg Ward8c6b6a92002-12-11 14:43:13 +0000767 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
768 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000769 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
770 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
771 { "post", (PyCFunction)oss_post, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000772
773 /* Convenience methods -- wrap a couple of ioctls together */
Greg Wardad4d9b92002-12-30 03:02:22 +0000774 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000775 { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS },
776 { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS },
777 { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS },
778 { "getptr", (PyCFunction)oss_getptr, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000779
780 /* Aliases for backwards compatibility */
Greg Wardad4d9b92002-12-30 03:02:22 +0000781 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000782
Greg Wardad4d9b92002-12-30 03:02:22 +0000783 { NULL, NULL} /* sentinel */
Greg Ward04613a92002-11-30 22:47:45 +0000784};
785
Greg Ward3d9994d2002-12-11 15:12:01 +0000786static PyMethodDef oss_mixer_methods[] = {
787 /* Regular file method - OSS mixers are ioctl-only interface */
Georg Brandl96a8c392006-05-29 21:04:52 +0000788 { "close", (PyCFunction)oss_mixer_close, METH_NOARGS },
789 { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000790
791 /* Simple ioctl wrappers */
Guido van Rossum0741f802003-06-02 14:15:34 +0000792 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
Greg Ward2d6f9a92002-12-31 02:54:43 +0000793 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
Guido van Rossum0741f802003-06-02 14:15:34 +0000794 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
Greg Wardad4d9b92002-12-30 03:02:22 +0000795 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
796 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
Greg Wardf05aa102002-12-30 23:19:32 +0000797 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
798 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
Guido van Rossum0741f802003-06-02 14:15:34 +0000799
Greg Wardad4d9b92002-12-30 03:02:22 +0000800 { NULL, NULL}
Greg Ward3d9994d2002-12-11 15:12:01 +0000801};
802
Greg Ward04613a92002-11-30 22:47:45 +0000803static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000804oss_getattr(oss_audio_t *self, char *name)
Greg Ward04613a92002-11-30 22:47:45 +0000805{
Greg Ward50682d02005-03-07 01:41:11 +0000806 PyObject * rval = NULL;
807 if (strcmp(name, "closed") == 0) {
808 rval = (self->fd == -1) ? Py_True : Py_False;
809 Py_INCREF(rval);
810 }
811 else if (strcmp(name, "name") == 0) {
812 rval = PyString_FromString(self->devicename);
813 }
814 else if (strcmp(name, "mode") == 0) {
815 /* No need for a "default" in this switch: from newossobject(),
816 self->mode can only be one of these three values. */
817 switch(self->mode) {
818 case O_RDONLY:
819 rval = PyString_FromString("r");
820 break;
821 case O_RDWR:
822 rval = PyString_FromString("rw");
823 break;
824 case O_WRONLY:
825 rval = PyString_FromString("w");
826 break;
827 }
828 }
829 else {
830 rval = Py_FindMethod(oss_methods, (PyObject *)self, name);
831 }
832 return rval;
Greg Ward04613a92002-11-30 22:47:45 +0000833}
834
Greg Ward3d9994d2002-12-11 15:12:01 +0000835static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000836oss_mixer_getattr(oss_mixer_t *self, char *name)
Greg Ward3d9994d2002-12-11 15:12:01 +0000837{
Greg Ward58ae13c2002-12-31 03:07:21 +0000838 return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name);
Greg Ward3d9994d2002-12-11 15:12:01 +0000839}
840
Greg Ward499b73e2002-12-31 03:04:52 +0000841static PyTypeObject OSSAudioType = {
Greg Ward04613a92002-11-30 22:47:45 +0000842 PyObject_HEAD_INIT(&PyType_Type)
Greg Wardad4d9b92002-12-30 03:02:22 +0000843 0, /*ob_size*/
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*/
850 (getattrfunc)oss_getattr, /*tp_getattr*/
851 0, /*tp_setattr*/
852 0, /*tp_compare*/
853 0, /*tp_repr*/
Greg Ward04613a92002-11-30 22:47:45 +0000854};
855
Greg Ward3d9994d2002-12-11 15:12:01 +0000856static PyTypeObject OSSMixerType = {
857 PyObject_HEAD_INIT(&PyType_Type)
Greg Wardad4d9b92002-12-30 03:02:22 +0000858 0, /*ob_size*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000859 "ossaudiodev.oss_mixer_device", /*tp_name*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000860 sizeof(oss_mixer_t), /*tp_size*/
861 0, /*tp_itemsize*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000862 /* methods */
863 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000864 0, /*tp_print*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000865 (getattrfunc)oss_mixer_getattr, /*tp_getattr*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000866 0, /*tp_setattr*/
867 0, /*tp_compare*/
868 0, /*tp_repr*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000869};
870
871
Greg Ward04613a92002-11-30 22:47:45 +0000872static PyObject *
Greg Ward9a568eb2002-11-30 23:20:09 +0000873ossopen(PyObject *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000874{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000875 return (PyObject *)newossobject(args);
Greg Ward04613a92002-11-30 22:47:45 +0000876}
877
Greg Ward3d9994d2002-12-11 15:12:01 +0000878static PyObject *
879ossopenmixer(PyObject *self, PyObject *args)
880{
881 return (PyObject *)newossmixerobject(args);
882}
883
Greg Ward9a568eb2002-11-30 23:20:09 +0000884static PyMethodDef ossaudiodev_methods[] = {
885 { "open", ossopen, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000886 { "openmixer", ossopenmixer, METH_VARARGS },
Greg Ward04613a92002-11-30 22:47:45 +0000887 { 0, 0 },
888};
889
Greg Ward1e0f57d2002-11-30 23:05:26 +0000890
891#define _EXPORT_INT(mod, name) \
892 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
893
Greg Ward744f0fd2002-12-31 03:23:59 +0000894
895static char *control_labels[] = SOUND_DEVICE_LABELS;
896static char *control_names[] = SOUND_DEVICE_NAMES;
897
898
899static int
900build_namelists (PyObject *module)
901{
902 PyObject *labels;
903 PyObject *names;
904 PyObject *s;
905 int num_controls;
906 int i;
907
908 num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
909 assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
910
911 labels = PyList_New(num_controls);
912 names = PyList_New(num_controls);
Georg Brandl5c170fd2006-03-17 19:03:25 +0000913 if (labels == NULL || names == NULL)
914 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000915 for (i = 0; i < num_controls; i++) {
916 s = PyString_FromString(control_labels[i]);
917 if (s == NULL)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000918 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000919 PyList_SET_ITEM(labels, i, s);
Guido van Rossum0741f802003-06-02 14:15:34 +0000920
Greg Ward744f0fd2002-12-31 03:23:59 +0000921 s = PyString_FromString(control_names[i]);
922 if (s == NULL)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000923 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000924 PyList_SET_ITEM(names, i, s);
925 }
926
927 if (PyModule_AddObject(module, "control_labels", labels) == -1)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000928 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000929 if (PyModule_AddObject(module, "control_names", names) == -1)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000930 goto error1;
Greg Ward744f0fd2002-12-31 03:23:59 +0000931
932 return 0;
Georg Brandl5c170fd2006-03-17 19:03:25 +0000933
934error2:
935 Py_XDECREF(labels);
936error1:
937 Py_XDECREF(names);
938 return -1;
Guido van Rossum0741f802003-06-02 14:15:34 +0000939}
Greg Ward744f0fd2002-12-31 03:23:59 +0000940
941
Greg Ward04613a92002-11-30 22:47:45 +0000942void
Greg Ward9a568eb2002-11-30 23:20:09 +0000943initossaudiodev(void)
Greg Ward04613a92002-11-30 22:47:45 +0000944{
945 PyObject *m;
Guido van Rossum0741f802003-06-02 14:15:34 +0000946
Greg Ward9a568eb2002-11-30 23:20:09 +0000947 m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
Neal Norwitz1ac754f2006-01-19 06:09:39 +0000948 if (m == NULL)
949 return;
Greg Ward04613a92002-11-30 22:47:45 +0000950
Guido van Rossum0741f802003-06-02 14:15:34 +0000951 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
952 NULL, NULL);
Greg Wardd6769062003-05-29 21:53:06 +0000953 if (OSSAudioError) {
Guido van Rossum0741f802003-06-02 14:15:34 +0000954 /* Each call to PyModule_AddObject decrefs it; compensate: */
955 Py_INCREF(OSSAudioError);
956 Py_INCREF(OSSAudioError);
Greg Wardad4d9b92002-12-30 03:02:22 +0000957 PyModule_AddObject(m, "error", OSSAudioError);
Greg Wardd6769062003-05-29 21:53:06 +0000958 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
959 }
Greg Ward04613a92002-11-30 22:47:45 +0000960
Greg Ward744f0fd2002-12-31 03:23:59 +0000961 /* Build 'control_labels' and 'control_names' lists and add them
962 to the module. */
963 if (build_namelists(m) == -1) /* XXX what to do here? */
964 return;
965
Greg Ward1e0f57d2002-11-30 23:05:26 +0000966 /* Expose the audio format numbers -- essential! */
967 _EXPORT_INT(m, AFMT_QUERY);
968 _EXPORT_INT(m, AFMT_MU_LAW);
969 _EXPORT_INT(m, AFMT_A_LAW);
970 _EXPORT_INT(m, AFMT_IMA_ADPCM);
971 _EXPORT_INT(m, AFMT_U8);
972 _EXPORT_INT(m, AFMT_S16_LE);
973 _EXPORT_INT(m, AFMT_S16_BE);
974 _EXPORT_INT(m, AFMT_S8);
975 _EXPORT_INT(m, AFMT_U16_LE);
976 _EXPORT_INT(m, AFMT_U16_BE);
977 _EXPORT_INT(m, AFMT_MPEG);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000978#ifdef AFMT_AC3
Greg Ward1e0f57d2002-11-30 23:05:26 +0000979 _EXPORT_INT(m, AFMT_AC3);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000980#endif
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000981#ifdef AFMT_S16_NE
Greg Ward1e0f57d2002-11-30 23:05:26 +0000982 _EXPORT_INT(m, AFMT_S16_NE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000983#endif
Greg Ward0f260542005-03-28 02:40:46 +0000984#ifdef AFMT_U16_NE
985 _EXPORT_INT(m, AFMT_U16_NE);
986#endif
987#ifdef AFMT_S32_LE
988 _EXPORT_INT(m, AFMT_S32_LE);
989#endif
990#ifdef AFMT_S32_BE
991 _EXPORT_INT(m, AFMT_S32_BE);
992#endif
993#ifdef AFMT_MPEG
994 _EXPORT_INT(m, AFMT_MPEG);
995#endif
Guido van Rossum0741f802003-06-02 14:15:34 +0000996
Greg Ward37897c22002-12-30 02:43:36 +0000997 /* Expose the sound mixer device numbers. */
Greg Ward7b43c682002-12-30 02:29:28 +0000998 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
Greg Ward3d9994d2002-12-11 15:12:01 +0000999 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1000 _EXPORT_INT(m, SOUND_MIXER_BASS);
1001 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1002 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1003 _EXPORT_INT(m, SOUND_MIXER_PCM);
1004 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1005 _EXPORT_INT(m, SOUND_MIXER_LINE);
1006 _EXPORT_INT(m, SOUND_MIXER_MIC);
1007 _EXPORT_INT(m, SOUND_MIXER_CD);
1008 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1009 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1010 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1011 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1012 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1013 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1014 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1015 _EXPORT_INT(m, SOUND_MIXER_LINE3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001016#ifdef SOUND_MIXER_DIGITAL1
Greg Ward3d9994d2002-12-11 15:12:01 +00001017 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
Greg Wardfd0283e2004-05-11 01:34:55 +00001018#endif
1019#ifdef SOUND_MIXER_DIGITAL2
Greg Ward3d9994d2002-12-11 15:12:01 +00001020 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
Greg Wardfd0283e2004-05-11 01:34:55 +00001021#endif
1022#ifdef SOUND_MIXER_DIGITAL3
Greg Ward3d9994d2002-12-11 15:12:01 +00001023 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001024#endif
1025#ifdef SOUND_MIXER_PHONEIN
Greg Ward3d9994d2002-12-11 15:12:01 +00001026 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
Greg Wardfd0283e2004-05-11 01:34:55 +00001027#endif
1028#ifdef SOUND_MIXER_PHONEOUT
Greg Ward3d9994d2002-12-11 15:12:01 +00001029 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
Greg Wardfd0283e2004-05-11 01:34:55 +00001030#endif
1031#ifdef SOUND_MIXER_VIDEO
Greg Ward3d9994d2002-12-11 15:12:01 +00001032 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001033#endif
1034#ifdef SOUND_MIXER_RADIO
Greg Ward3d9994d2002-12-11 15:12:01 +00001035 _EXPORT_INT(m, SOUND_MIXER_RADIO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001036#endif
1037#ifdef SOUND_MIXER_MONITOR
Greg Ward3d9994d2002-12-11 15:12:01 +00001038 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
Greg Wardfd0283e2004-05-11 01:34:55 +00001039#endif
Greg Ward04613a92002-11-30 22:47:45 +00001040
Greg Ward1e0f57d2002-11-30 23:05:26 +00001041 /* Expose all the ioctl numbers for masochists who like to do this
1042 stuff directly. */
1043 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1044 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1045 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1046 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1047 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1048 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1049 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1050 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1051 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1052 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001053#ifdef SNDCTL_DSP_BIND_CHANNEL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001054 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001055#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001056 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1057 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1058 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001059#ifdef SNDCTL_DSP_GETCHANNELMASK
Greg Ward1e0f57d2002-11-30 23:05:26 +00001060 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001061#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001062 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1063 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1064 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
Greg Wardfd0283e2004-05-11 01:34:55 +00001065#ifdef SNDCTL_DSP_GETODELAY
Greg Ward1e0f57d2002-11-30 23:05:26 +00001066 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
Greg Wardfd0283e2004-05-11 01:34:55 +00001067#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001068 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1069 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001070#ifdef SNDCTL_DSP_GETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001071 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001072#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001073 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1074 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1075 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1076 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1077 _EXPORT_INT(m, SNDCTL_DSP_POST);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001078#ifdef SNDCTL_DSP_PROFILE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001079 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001080#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001081 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1082 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1083 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1084 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1085 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001086#ifdef SNDCTL_DSP_SETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001087 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001088#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001089 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1090 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1091 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1092 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1093 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1094 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1095 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1096 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1097 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1098 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1099 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1100 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1101 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1102 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1103 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001104#ifdef SNDCTL_SEQ_GETTIME
Greg Ward1e0f57d2002-11-30 23:05:26 +00001105 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001106#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001107 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1108 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1109 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1110 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1111 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1112 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1113 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1114 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1115 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1116 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001117#ifdef SNDCTL_SYNTH_CONTROL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001118 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001119#endif
1120#ifdef SNDCTL_SYNTH_ID
Greg Ward1e0f57d2002-11-30 23:05:26 +00001121 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001122#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001123 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1124 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001125#ifdef SNDCTL_SYNTH_REMOVESAMPLE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001126 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001127#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001128 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1129 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1130 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1131 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1132 _EXPORT_INT(m, SNDCTL_TMR_START);
1133 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1134 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1135 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
Greg Ward04613a92002-11-30 22:47:45 +00001136}