blob: 4c22b07fd866ecbdde707152467b23c1261e561d [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 *
Greg Ward499b73e2002-12-31 03:04:52 +0000299oss_nonblock(oss_audio_t *self, PyObject *args)
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! */
303 if (!PyArg_ParseTuple(args, ":nonblock"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000304 return NULL;
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 *
Greg Ward499b73e2002-12-31 03:04:52 +0000318oss_getfmts(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000319{
320 int mask;
321 if (!PyArg_ParseTuple(args, ":getfmts"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000322 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000323 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000324 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000325 return PyInt_FromLong(mask);
326}
327
328static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000329oss_channels(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000330{
Greg Ward7b43c682002-12-30 02:29:28 +0000331 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
Greg Ward131bce02002-11-30 22:56:44 +0000332}
333
334static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000335oss_speed(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000336{
Greg Ward7b43c682002-12-30 02:29:28 +0000337 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
Greg Ward131bce02002-11-30 22:56:44 +0000338}
339
340static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000341oss_sync(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000342{
Greg Wardd0d592f2003-05-27 01:57:21 +0000343 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
Greg Ward131bce02002-11-30 22:56:44 +0000344}
Guido van Rossum0741f802003-06-02 14:15:34 +0000345
Greg Ward131bce02002-11-30 22:56:44 +0000346static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000347oss_reset(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000348{
Greg Ward7b43c682002-12-30 02:29:28 +0000349 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
Greg Ward131bce02002-11-30 22:56:44 +0000350}
Guido van Rossum0741f802003-06-02 14:15:34 +0000351
Greg Ward131bce02002-11-30 22:56:44 +0000352static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000353oss_post(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000354{
Greg Ward7b43c682002-12-30 02:29:28 +0000355 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
Greg Ward131bce02002-11-30 22:56:44 +0000356}
357
358
359/* Regular file methods: read(), write(), close(), etc. as well
360 as one convenience method, writeall(). */
361
Greg Ward04613a92002-11-30 22:47:45 +0000362static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000363oss_read(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000364{
365 int size, count;
366 char *cp;
367 PyObject *rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000368
Greg Ward04613a92002-11-30 22:47:45 +0000369 if (!PyArg_ParseTuple(args, "i:read", &size))
370 return NULL;
371 rv = PyString_FromStringAndSize(NULL, size);
372 if (rv == NULL)
373 return NULL;
374 cp = PyString_AS_STRING(rv);
Greg Ward64927852003-05-23 01:50:37 +0000375
376 Py_BEGIN_ALLOW_THREADS
377 count = read(self->fd, cp, size);
378 Py_END_ALLOW_THREADS
379
380 if (count < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000381 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000382 Py_DECREF(rv);
383 return NULL;
384 }
Greg Ward7b43c682002-12-30 02:29:28 +0000385 self->icount += count;
Greg Ward04613a92002-11-30 22:47:45 +0000386 _PyString_Resize(&rv, count);
387 return rv;
388}
389
390static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000391oss_write(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000392{
393 char *cp;
394 int rv, size;
Greg Ward131bce02002-11-30 22:56:44 +0000395
396 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000397 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000398 }
Greg Ward64927852003-05-23 01:50:37 +0000399
400 Py_BEGIN_ALLOW_THREADS
401 rv = write(self->fd, cp, size);
402 Py_END_ALLOW_THREADS
403
404 if (rv == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000405 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000406 } else {
Greg Ward7b43c682002-12-30 02:29:28 +0000407 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000408 }
409 return PyInt_FromLong(rv);
410}
411
412static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000413oss_writeall(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000414{
415 char *cp;
416 int rv, size;
417 fd_set write_set_fds;
418 int select_rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000419
Greg Ward131bce02002-11-30 22:56:44 +0000420 /* NB. writeall() is only useful in non-blocking mode: according to
421 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
422 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
423 write() in blocking mode consumes the whole buffer. In blocking
424 mode, the behaviour of write() and writeall() from Python is
425 indistinguishable. */
426
Guido van Rossum0741f802003-06-02 14:15:34 +0000427 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
Greg Ward131bce02002-11-30 22:56:44 +0000428 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000429
430 /* use select to wait for audio device to be available */
431 FD_ZERO(&write_set_fds);
Greg Ward7b43c682002-12-30 02:29:28 +0000432 FD_SET(self->fd, &write_set_fds);
Greg Ward04613a92002-11-30 22:47:45 +0000433
434 while (size > 0) {
Greg Ward64927852003-05-23 01:50:37 +0000435 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000436 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Greg Ward64927852003-05-23 01:50:37 +0000437 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000438 assert(select_rv != 0); /* no timeout, can't expire */
439 if (select_rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000440 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000441
Greg Ward64927852003-05-23 01:50:37 +0000442 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000443 rv = write(self->fd, cp, size);
Greg Ward64927852003-05-23 01:50:37 +0000444 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000445 if (rv == -1) {
446 if (errno == EAGAIN) { /* buffer is full, try again */
447 errno = 0;
448 continue;
449 } else /* it's a real error */
Greg Ward97708bc2002-11-30 23:17:10 +0000450 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000451 } else { /* wrote rv bytes */
Greg Ward7b43c682002-12-30 02:29:28 +0000452 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000453 size -= rv;
454 cp += rv;
455 }
Greg Ward04613a92002-11-30 22:47:45 +0000456 }
457 Py_INCREF(Py_None);
458 return Py_None;
459}
460
461static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000462oss_close(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000463{
464 if (!PyArg_ParseTuple(args, ":close"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000465 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000466
Greg Ward7b43c682002-12-30 02:29:28 +0000467 if (self->fd >= 0) {
Greg Wardb8043902003-05-26 22:47:30 +0000468 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000469 close(self->fd);
Greg Wardb8043902003-05-26 22:47:30 +0000470 Py_END_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000471 self->fd = -1;
Greg Ward04613a92002-11-30 22:47:45 +0000472 }
473 Py_INCREF(Py_None);
474 return Py_None;
475}
476
477static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000478oss_fileno(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000479{
Guido van Rossum0741f802003-06-02 14:15:34 +0000480 if (!PyArg_ParseTuple(args, ":fileno"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000481 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000482 return PyInt_FromLong(self->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000483}
484
Greg Ward131bce02002-11-30 22:56:44 +0000485
486/* Convenience methods: these generally wrap a couple of ioctls into one
487 common task. */
488
Greg Ward04613a92002-11-30 22:47:45 +0000489static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000490oss_setparameters(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000491{
Greg Wardd6769062003-05-29 21:53:06 +0000492 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
493 int fmt, channels, rate;
494 PyObject * rv; /* return tuple (fmt, channels, rate) */
Greg Ward04613a92002-11-30 22:47:45 +0000495
Greg Wardd6769062003-05-29 21:53:06 +0000496 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
497 &wanted_fmt, &wanted_channels, &wanted_rate,
498 &strict))
Greg Ward04613a92002-11-30 22:47:45 +0000499 return NULL;
Greg Wardd6769062003-05-29 21:53:06 +0000500
501 fmt = wanted_fmt;
502 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
503 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000504 }
Greg Wardd6769062003-05-29 21:53:06 +0000505 if (strict && fmt != wanted_fmt) {
506 return PyErr_Format
507 (OSSAudioError,
508 "unable to set requested format (wanted %d, got %d)",
509 wanted_fmt, fmt);
Greg Ward04613a92002-11-30 22:47:45 +0000510 }
511
Greg Wardd6769062003-05-29 21:53:06 +0000512 channels = wanted_channels;
513 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
514 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000515 }
Greg Wardd6769062003-05-29 21:53:06 +0000516 if (strict && channels != wanted_channels) {
517 return PyErr_Format
518 (OSSAudioError,
519 "unable to set requested channels (wanted %d, got %d)",
520 wanted_channels, channels);
Greg Ward04613a92002-11-30 22:47:45 +0000521 }
522
Greg Wardd6769062003-05-29 21:53:06 +0000523 rate = wanted_rate;
Greg Ward7b43c682002-12-30 02:29:28 +0000524 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Greg Wardd6769062003-05-29 21:53:06 +0000525 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000526 }
Greg Wardd6769062003-05-29 21:53:06 +0000527 if (strict && rate != wanted_rate) {
528 return PyErr_Format
529 (OSSAudioError,
530 "unable to set requested rate (wanted %d, got %d)",
531 wanted_rate, rate);
532 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000533
Greg Wardd6769062003-05-29 21:53:06 +0000534 /* Construct the return value: a (fmt, channels, rate) tuple that
535 tells what the audio hardware was actually set to. */
536 rv = PyTuple_New(3);
537 if (rv == NULL)
538 return NULL;
539 PyTuple_SET_ITEM(rv, 0, PyInt_FromLong(fmt));
540 PyTuple_SET_ITEM(rv, 1, PyInt_FromLong(channels));
541 PyTuple_SET_ITEM(rv, 2, PyInt_FromLong(rate));
542 return rv;
Greg Ward04613a92002-11-30 22:47:45 +0000543}
544
545static int
Greg Ward499b73e2002-12-31 03:04:52 +0000546_ssize(oss_audio_t *self, int *nchannels, int *ssize)
Greg Ward04613a92002-11-30 22:47:45 +0000547{
548 int fmt;
549
550 fmt = 0;
Guido van Rossum0741f802003-06-02 14:15:34 +0000551 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000552 return -errno;
553
554 switch (fmt) {
555 case AFMT_MU_LAW:
556 case AFMT_A_LAW:
557 case AFMT_U8:
558 case AFMT_S8:
Greg Ward38c92662003-05-29 21:55:41 +0000559 *ssize = 1; /* 8 bit formats: 1 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000560 break;
561 case AFMT_S16_LE:
562 case AFMT_S16_BE:
563 case AFMT_U16_LE:
564 case AFMT_U16_BE:
Greg Ward84f8ecd2003-05-29 23:44:44 +0000565 *ssize = 2; /* 16 bit formats: 2 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000566 break;
567 case AFMT_MPEG:
568 case AFMT_IMA_ADPCM:
569 default:
570 return -EOPNOTSUPP;
571 }
572 *nchannels = 0;
Greg Ward7b43c682002-12-30 02:29:28 +0000573 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000574 return -errno;
575 return 0;
576}
577
578
Guido van Rossum0741f802003-06-02 14:15:34 +0000579/* bufsize returns the size of the hardware audio buffer in number
Greg Ward04613a92002-11-30 22:47:45 +0000580 of samples */
581static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000582oss_bufsize(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000583{
584 audio_buf_info ai;
585 int nchannels, ssize;
586
587 if (!PyArg_ParseTuple(args, ":bufsize")) return NULL;
588
589 if (_ssize(self, &nchannels, &ssize) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000590 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000591 return NULL;
592 }
Greg Ward7b43c682002-12-30 02:29:28 +0000593 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000594 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000595 return NULL;
596 }
597 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
598}
599
Guido van Rossum0741f802003-06-02 14:15:34 +0000600/* obufcount returns the number of samples that are available in the
Greg Ward04613a92002-11-30 22:47:45 +0000601 hardware for playing */
602static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000603oss_obufcount(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000604{
605 audio_buf_info ai;
606 int nchannels, ssize;
607
608 if (!PyArg_ParseTuple(args, ":obufcount"))
609 return NULL;
610
611 if (_ssize(self, &nchannels, &ssize) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000612 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000613 return NULL;
614 }
Greg Ward7b43c682002-12-30 02:29:28 +0000615 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000616 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000617 return NULL;
618 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000619 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
Greg Ward04613a92002-11-30 22:47:45 +0000620 (ssize * nchannels));
621}
622
623/* obufcount returns the number of samples that can be played without
624 blocking */
625static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000626oss_obuffree(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000627{
628 audio_buf_info ai;
629 int nchannels, ssize;
630
631 if (!PyArg_ParseTuple(args, ":obuffree"))
632 return NULL;
633
634 if (_ssize(self, &nchannels, &ssize) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000635 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000636 return NULL;
637 }
Greg Ward7b43c682002-12-30 02:29:28 +0000638 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000639 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000640 return NULL;
641 }
642 return PyInt_FromLong(ai.bytes / (ssize * nchannels));
643}
644
Greg Ward04613a92002-11-30 22:47:45 +0000645static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000646oss_getptr(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000647{
648 count_info info;
649 int req;
650
651 if (!PyArg_ParseTuple(args, ":getptr"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000652 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000653
Greg Ward7b43c682002-12-30 02:29:28 +0000654 if (self->mode == O_RDONLY)
Greg Wardad4d9b92002-12-30 03:02:22 +0000655 req = SNDCTL_DSP_GETIPTR;
Greg Ward04613a92002-11-30 22:47:45 +0000656 else
Greg Wardad4d9b92002-12-30 03:02:22 +0000657 req = SNDCTL_DSP_GETOPTR;
Greg Ward7b43c682002-12-30 02:29:28 +0000658 if (ioctl(self->fd, req, &info) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000659 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000660 return NULL;
661 }
662 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
663}
664
Greg Wardda1cacb2002-12-31 03:02:23 +0000665
666/* ----------------------------------------------------------------------
667 * Methods of mixer objects (OSSMixerType)
668 */
669
Greg Ward3d9994d2002-12-11 15:12:01 +0000670static PyObject *
671oss_mixer_close(oss_mixer_t *self, PyObject *args)
672{
673 if (!PyArg_ParseTuple(args, ":close"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000674 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000675
Greg Ward7b43c682002-12-30 02:29:28 +0000676 if (self->fd >= 0) {
677 close(self->fd);
678 self->fd = -1;
Greg Ward3d9994d2002-12-11 15:12:01 +0000679 }
680 Py_INCREF(Py_None);
681 return Py_None;
682}
683
684static PyObject *
685oss_mixer_fileno(oss_mixer_t *self, PyObject *args)
686{
Guido van Rossum0741f802003-06-02 14:15:34 +0000687 if (!PyArg_ParseTuple(args, ":fileno"))
Greg Wardad4d9b92002-12-30 03:02:22 +0000688 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000689 return PyInt_FromLong(self->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000690}
691
692/* Simple mixer interface methods */
693
694static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000695oss_mixer_controls(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000696{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000697 return _do_ioctl_1_internal(self->fd, args, "controls",
Greg Ward3d9994d2002-12-11 15:12:01 +0000698 SOUND_MIXER_READ_DEVMASK);
699}
700
701static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000702oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000703{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000704 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
Greg Ward3d9994d2002-12-11 15:12:01 +0000705 SOUND_MIXER_READ_STEREODEVS);
706}
707
708static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000709oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000710{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000711 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
Greg Wardb69bb3d2002-12-12 17:35:45 +0000712 SOUND_MIXER_READ_RECMASK);
Greg Ward3d9994d2002-12-11 15:12:01 +0000713}
714
715static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000716oss_mixer_get(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000717{
718 int channel, volume;
Guido van Rossum0741f802003-06-02 14:15:34 +0000719
Greg Ward3d9994d2002-12-11 15:12:01 +0000720 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000721 if (!PyArg_ParseTuple(args, "i:get", &channel))
Greg Wardad4d9b92002-12-30 03:02:22 +0000722 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000723
Greg Ward3d9994d2002-12-11 15:12:01 +0000724 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000725 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
726 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000727 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000728
Greg Warde7037662002-12-30 03:01:48 +0000729 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000730 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000731
Greg Warde7037662002-12-30 03:01:48 +0000732 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000733}
734
735static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000736oss_mixer_set(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000737{
738 int channel, volume, leftVol, rightVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000739
Greg Ward3d9994d2002-12-11 15:12:01 +0000740 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000741 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
Greg Wardad4d9b92002-12-30 03:02:22 +0000742 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000743
Greg Ward3d9994d2002-12-11 15:12:01 +0000744 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000745 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
746 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000747 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000748
Greg Ward3d9994d2002-12-11 15:12:01 +0000749 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000750 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
751 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000752 }
753
754 volume = (rightVol << 8) | leftVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000755
Greg Warde7037662002-12-30 03:01:48 +0000756 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000757 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000758
Greg Warde7037662002-12-30 03:01:48 +0000759 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000760}
761
762static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000763oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000764{
Greg Wardf05aa102002-12-30 23:19:32 +0000765 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000766 SOUND_MIXER_READ_RECSRC);
767}
768
769static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000770oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000771{
Greg Wardf05aa102002-12-30 23:19:32 +0000772 return _do_ioctl_1(self->fd, args, "set_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000773 SOUND_MIXER_WRITE_RECSRC);
774}
775
776
Greg Wardda1cacb2002-12-31 03:02:23 +0000777/* ----------------------------------------------------------------------
778 * Method tables and other bureaucracy
779 */
780
Greg Ward8c6b6a92002-12-11 14:43:13 +0000781static PyMethodDef oss_methods[] = {
Greg Ward131bce02002-11-30 22:56:44 +0000782 /* Regular file methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000783 { "read", (PyCFunction)oss_read, METH_VARARGS },
784 { "write", (PyCFunction)oss_write, METH_VARARGS },
785 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
786 { "close", (PyCFunction)oss_close, METH_VARARGS },
787 { "fileno", (PyCFunction)oss_fileno, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000788
789 /* Simple ioctl wrappers */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000790 { "nonblock", (PyCFunction)oss_nonblock, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000791 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
Greg Ward8c6b6a92002-12-11 14:43:13 +0000792 { "getfmts", (PyCFunction)oss_getfmts, METH_VARARGS },
793 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
794 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000795 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
796 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
797 { "post", (PyCFunction)oss_post, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000798
799 /* Convenience methods -- wrap a couple of ioctls together */
Greg Wardad4d9b92002-12-30 03:02:22 +0000800 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
801 { "bufsize", (PyCFunction)oss_bufsize, METH_VARARGS },
802 { "obufcount", (PyCFunction)oss_obufcount, METH_VARARGS },
803 { "obuffree", (PyCFunction)oss_obuffree, METH_VARARGS },
Greg Ward8c6b6a92002-12-11 14:43:13 +0000804 { "getptr", (PyCFunction)oss_getptr, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000805
806 /* Aliases for backwards compatibility */
Greg Wardad4d9b92002-12-30 03:02:22 +0000807 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000808
Greg Wardad4d9b92002-12-30 03:02:22 +0000809 { NULL, NULL} /* sentinel */
Greg Ward04613a92002-11-30 22:47:45 +0000810};
811
Greg Ward3d9994d2002-12-11 15:12:01 +0000812static PyMethodDef oss_mixer_methods[] = {
813 /* Regular file method - OSS mixers are ioctl-only interface */
Guido van Rossum0741f802003-06-02 14:15:34 +0000814 { "close", (PyCFunction)oss_mixer_close, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000815 { "fileno", (PyCFunction)oss_mixer_fileno, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000816
817 /* Simple ioctl wrappers */
Guido van Rossum0741f802003-06-02 14:15:34 +0000818 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
Greg Ward2d6f9a92002-12-31 02:54:43 +0000819 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
Guido van Rossum0741f802003-06-02 14:15:34 +0000820 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
Greg Wardad4d9b92002-12-30 03:02:22 +0000821 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
822 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
Greg Wardf05aa102002-12-30 23:19:32 +0000823 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
824 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
Guido van Rossum0741f802003-06-02 14:15:34 +0000825
Greg Wardad4d9b92002-12-30 03:02:22 +0000826 { NULL, NULL}
Greg Ward3d9994d2002-12-11 15:12:01 +0000827};
828
Greg Ward04613a92002-11-30 22:47:45 +0000829static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000830oss_getattr(oss_audio_t *self, char *name)
Greg Ward04613a92002-11-30 22:47:45 +0000831{
Greg Ward50682d02005-03-07 01:41:11 +0000832 PyObject * rval = NULL;
833 if (strcmp(name, "closed") == 0) {
834 rval = (self->fd == -1) ? Py_True : Py_False;
835 Py_INCREF(rval);
836 }
837 else if (strcmp(name, "name") == 0) {
838 rval = PyString_FromString(self->devicename);
839 }
840 else if (strcmp(name, "mode") == 0) {
841 /* No need for a "default" in this switch: from newossobject(),
842 self->mode can only be one of these three values. */
843 switch(self->mode) {
844 case O_RDONLY:
845 rval = PyString_FromString("r");
846 break;
847 case O_RDWR:
848 rval = PyString_FromString("rw");
849 break;
850 case O_WRONLY:
851 rval = PyString_FromString("w");
852 break;
853 }
854 }
855 else {
856 rval = Py_FindMethod(oss_methods, (PyObject *)self, name);
857 }
858 return rval;
Greg Ward04613a92002-11-30 22:47:45 +0000859}
860
Greg Ward3d9994d2002-12-11 15:12:01 +0000861static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000862oss_mixer_getattr(oss_mixer_t *self, char *name)
Greg Ward3d9994d2002-12-11 15:12:01 +0000863{
Greg Ward58ae13c2002-12-31 03:07:21 +0000864 return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name);
Greg Ward3d9994d2002-12-11 15:12:01 +0000865}
866
Greg Ward499b73e2002-12-31 03:04:52 +0000867static PyTypeObject OSSAudioType = {
Greg Ward04613a92002-11-30 22:47:45 +0000868 PyObject_HEAD_INIT(&PyType_Type)
Greg Wardad4d9b92002-12-30 03:02:22 +0000869 0, /*ob_size*/
Greg Ward9a568eb2002-11-30 23:20:09 +0000870 "ossaudiodev.oss_audio_device", /*tp_name*/
Greg Ward499b73e2002-12-31 03:04:52 +0000871 sizeof(oss_audio_t), /*tp_size*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000872 0, /*tp_itemsize*/
Greg Ward04613a92002-11-30 22:47:45 +0000873 /* methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000874 (destructor)oss_dealloc, /*tp_dealloc*/
875 0, /*tp_print*/
876 (getattrfunc)oss_getattr, /*tp_getattr*/
877 0, /*tp_setattr*/
878 0, /*tp_compare*/
879 0, /*tp_repr*/
Greg Ward04613a92002-11-30 22:47:45 +0000880};
881
Greg Ward3d9994d2002-12-11 15:12:01 +0000882static PyTypeObject OSSMixerType = {
883 PyObject_HEAD_INIT(&PyType_Type)
Greg Wardad4d9b92002-12-30 03:02:22 +0000884 0, /*ob_size*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000885 "ossaudiodev.oss_mixer_device", /*tp_name*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000886 sizeof(oss_mixer_t), /*tp_size*/
887 0, /*tp_itemsize*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000888 /* methods */
889 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000890 0, /*tp_print*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000891 (getattrfunc)oss_mixer_getattr, /*tp_getattr*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000892 0, /*tp_setattr*/
893 0, /*tp_compare*/
894 0, /*tp_repr*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000895};
896
897
Greg Ward04613a92002-11-30 22:47:45 +0000898static PyObject *
Greg Ward9a568eb2002-11-30 23:20:09 +0000899ossopen(PyObject *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000900{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000901 return (PyObject *)newossobject(args);
Greg Ward04613a92002-11-30 22:47:45 +0000902}
903
Greg Ward3d9994d2002-12-11 15:12:01 +0000904static PyObject *
905ossopenmixer(PyObject *self, PyObject *args)
906{
907 return (PyObject *)newossmixerobject(args);
908}
909
Greg Ward9a568eb2002-11-30 23:20:09 +0000910static PyMethodDef ossaudiodev_methods[] = {
911 { "open", ossopen, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000912 { "openmixer", ossopenmixer, METH_VARARGS },
Greg Ward04613a92002-11-30 22:47:45 +0000913 { 0, 0 },
914};
915
Greg Ward1e0f57d2002-11-30 23:05:26 +0000916
917#define _EXPORT_INT(mod, name) \
918 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
919
Greg Ward744f0fd2002-12-31 03:23:59 +0000920
921static char *control_labels[] = SOUND_DEVICE_LABELS;
922static char *control_names[] = SOUND_DEVICE_NAMES;
923
924
925static int
926build_namelists (PyObject *module)
927{
928 PyObject *labels;
929 PyObject *names;
930 PyObject *s;
931 int num_controls;
932 int i;
933
934 num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
935 assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
936
937 labels = PyList_New(num_controls);
938 names = PyList_New(num_controls);
939 for (i = 0; i < num_controls; i++) {
940 s = PyString_FromString(control_labels[i]);
941 if (s == NULL)
942 return -1;
943 PyList_SET_ITEM(labels, i, s);
Guido van Rossum0741f802003-06-02 14:15:34 +0000944
Greg Ward744f0fd2002-12-31 03:23:59 +0000945 s = PyString_FromString(control_names[i]);
946 if (s == NULL)
947 return -1;
948 PyList_SET_ITEM(names, i, s);
949 }
950
951 if (PyModule_AddObject(module, "control_labels", labels) == -1)
952 return -1;
953 if (PyModule_AddObject(module, "control_names", names) == -1)
954 return -1;
955
956 return 0;
Guido van Rossum0741f802003-06-02 14:15:34 +0000957}
Greg Ward744f0fd2002-12-31 03:23:59 +0000958
959
Greg Ward04613a92002-11-30 22:47:45 +0000960void
Greg Ward9a568eb2002-11-30 23:20:09 +0000961initossaudiodev(void)
Greg Ward04613a92002-11-30 22:47:45 +0000962{
963 PyObject *m;
Guido van Rossum0741f802003-06-02 14:15:34 +0000964
Greg Ward9a568eb2002-11-30 23:20:09 +0000965 m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
Neal Norwitz1ac754f2006-01-19 06:09:39 +0000966 if (m == NULL)
967 return;
Greg Ward04613a92002-11-30 22:47:45 +0000968
Guido van Rossum0741f802003-06-02 14:15:34 +0000969 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
970 NULL, NULL);
Greg Wardd6769062003-05-29 21:53:06 +0000971 if (OSSAudioError) {
Guido van Rossum0741f802003-06-02 14:15:34 +0000972 /* Each call to PyModule_AddObject decrefs it; compensate: */
973 Py_INCREF(OSSAudioError);
974 Py_INCREF(OSSAudioError);
Greg Wardad4d9b92002-12-30 03:02:22 +0000975 PyModule_AddObject(m, "error", OSSAudioError);
Greg Wardd6769062003-05-29 21:53:06 +0000976 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
977 }
Greg Ward04613a92002-11-30 22:47:45 +0000978
Greg Ward744f0fd2002-12-31 03:23:59 +0000979 /* Build 'control_labels' and 'control_names' lists and add them
980 to the module. */
981 if (build_namelists(m) == -1) /* XXX what to do here? */
982 return;
983
Greg Ward1e0f57d2002-11-30 23:05:26 +0000984 /* Expose the audio format numbers -- essential! */
985 _EXPORT_INT(m, AFMT_QUERY);
986 _EXPORT_INT(m, AFMT_MU_LAW);
987 _EXPORT_INT(m, AFMT_A_LAW);
988 _EXPORT_INT(m, AFMT_IMA_ADPCM);
989 _EXPORT_INT(m, AFMT_U8);
990 _EXPORT_INT(m, AFMT_S16_LE);
991 _EXPORT_INT(m, AFMT_S16_BE);
992 _EXPORT_INT(m, AFMT_S8);
993 _EXPORT_INT(m, AFMT_U16_LE);
994 _EXPORT_INT(m, AFMT_U16_BE);
995 _EXPORT_INT(m, AFMT_MPEG);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000996#ifdef AFMT_AC3
Greg Ward1e0f57d2002-11-30 23:05:26 +0000997 _EXPORT_INT(m, AFMT_AC3);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000998#endif
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000999#ifdef AFMT_S16_NE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001000 _EXPORT_INT(m, AFMT_S16_NE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001001#endif
Greg Ward0f260542005-03-28 02:40:46 +00001002#ifdef AFMT_U16_NE
1003 _EXPORT_INT(m, AFMT_U16_NE);
1004#endif
1005#ifdef AFMT_S32_LE
1006 _EXPORT_INT(m, AFMT_S32_LE);
1007#endif
1008#ifdef AFMT_S32_BE
1009 _EXPORT_INT(m, AFMT_S32_BE);
1010#endif
1011#ifdef AFMT_MPEG
1012 _EXPORT_INT(m, AFMT_MPEG);
1013#endif
Guido van Rossum0741f802003-06-02 14:15:34 +00001014
Greg Ward37897c22002-12-30 02:43:36 +00001015 /* Expose the sound mixer device numbers. */
Greg Ward7b43c682002-12-30 02:29:28 +00001016 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
Greg Ward3d9994d2002-12-11 15:12:01 +00001017 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1018 _EXPORT_INT(m, SOUND_MIXER_BASS);
1019 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1020 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1021 _EXPORT_INT(m, SOUND_MIXER_PCM);
1022 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1023 _EXPORT_INT(m, SOUND_MIXER_LINE);
1024 _EXPORT_INT(m, SOUND_MIXER_MIC);
1025 _EXPORT_INT(m, SOUND_MIXER_CD);
1026 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1027 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1028 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1029 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1030 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1031 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1032 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1033 _EXPORT_INT(m, SOUND_MIXER_LINE3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001034#ifdef SOUND_MIXER_DIGITAL1
Greg Ward3d9994d2002-12-11 15:12:01 +00001035 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
Greg Wardfd0283e2004-05-11 01:34:55 +00001036#endif
1037#ifdef SOUND_MIXER_DIGITAL2
Greg Ward3d9994d2002-12-11 15:12:01 +00001038 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
Greg Wardfd0283e2004-05-11 01:34:55 +00001039#endif
1040#ifdef SOUND_MIXER_DIGITAL3
Greg Ward3d9994d2002-12-11 15:12:01 +00001041 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001042#endif
1043#ifdef SOUND_MIXER_PHONEIN
Greg Ward3d9994d2002-12-11 15:12:01 +00001044 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
Greg Wardfd0283e2004-05-11 01:34:55 +00001045#endif
1046#ifdef SOUND_MIXER_PHONEOUT
Greg Ward3d9994d2002-12-11 15:12:01 +00001047 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
Greg Wardfd0283e2004-05-11 01:34:55 +00001048#endif
1049#ifdef SOUND_MIXER_VIDEO
Greg Ward3d9994d2002-12-11 15:12:01 +00001050 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001051#endif
1052#ifdef SOUND_MIXER_RADIO
Greg Ward3d9994d2002-12-11 15:12:01 +00001053 _EXPORT_INT(m, SOUND_MIXER_RADIO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001054#endif
1055#ifdef SOUND_MIXER_MONITOR
Greg Ward3d9994d2002-12-11 15:12:01 +00001056 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
Greg Wardfd0283e2004-05-11 01:34:55 +00001057#endif
Greg Ward04613a92002-11-30 22:47:45 +00001058
Greg Ward1e0f57d2002-11-30 23:05:26 +00001059 /* Expose all the ioctl numbers for masochists who like to do this
1060 stuff directly. */
1061 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1062 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1063 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1064 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1065 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1066 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1067 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1068 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1069 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1070 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001071#ifdef SNDCTL_DSP_BIND_CHANNEL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001072 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001073#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001074 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1075 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1076 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001077#ifdef SNDCTL_DSP_GETCHANNELMASK
Greg Ward1e0f57d2002-11-30 23:05:26 +00001078 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001079#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001080 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1081 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1082 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
Greg Wardfd0283e2004-05-11 01:34:55 +00001083#ifdef SNDCTL_DSP_GETODELAY
Greg Ward1e0f57d2002-11-30 23:05:26 +00001084 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
Greg Wardfd0283e2004-05-11 01:34:55 +00001085#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001086 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1087 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001088#ifdef SNDCTL_DSP_GETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001089 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001090#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001091 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1092 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1093 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1094 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1095 _EXPORT_INT(m, SNDCTL_DSP_POST);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001096#ifdef SNDCTL_DSP_PROFILE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001097 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001098#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001099 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1100 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1101 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1102 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1103 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001104#ifdef SNDCTL_DSP_SETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001105 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001106#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001107 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1108 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1109 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1110 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1111 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1112 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1113 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1114 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1115 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1116 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1117 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1118 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1119 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1120 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1121 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001122#ifdef SNDCTL_SEQ_GETTIME
Greg Ward1e0f57d2002-11-30 23:05:26 +00001123 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001124#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001125 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1126 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1127 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1128 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1129 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1130 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1131 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1132 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1133 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1134 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001135#ifdef SNDCTL_SYNTH_CONTROL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001136 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001137#endif
1138#ifdef SNDCTL_SYNTH_ID
Greg Ward1e0f57d2002-11-30 23:05:26 +00001139 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001140#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001141 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1142 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001143#ifdef SNDCTL_SYNTH_REMOVESAMPLE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001144 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001145#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001146 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1147 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1148 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1149 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1150 _EXPORT_INT(m, SNDCTL_TMR_START);
1151 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1152 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1153 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
Greg Ward04613a92002-11-30 22:47:45 +00001154}