blob: 647a21e811b4972660a2bbdbd28c319e782b6ce8 [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
Armin Rigo0d2f4982006-10-04 10:23:57 +000037#ifndef HAVE_STDINT_H
Greg Ward04613a92002-11-30 22:47:45 +000038typedef unsigned long uint32_t;
Armin Rigo0d2f4982006-10-04 10:23:57 +000039#endif
Greg Ward04613a92002-11-30 22:47:45 +000040
41#elif defined(__FreeBSD__)
Greg Ward04613a92002-11-30 22:47:45 +000042
Greg Ward0b6dfb82003-03-10 03:17:06 +000043# ifndef SNDCTL_DSP_CHANNELS
44# define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
45# endif
Greg Ward04613a92002-11-30 22:47:45 +000046
47#endif
48
49typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000050 PyObject_HEAD
Greg Ward50682d02005-03-07 01:41:11 +000051 char *devicename; /* name of the device file */
52 int fd; /* file descriptor */
53 int mode; /* file mode (O_RDONLY, etc.) */
54 int icount; /* input count */
55 int ocount; /* output count */
56 uint32_t afmts; /* audio formats supported by hardware */
Greg Ward499b73e2002-12-31 03:04:52 +000057} oss_audio_t;
Greg Ward04613a92002-11-30 22:47:45 +000058
Greg Ward3d9994d2002-12-11 15:12:01 +000059typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000060 PyObject_HEAD
Greg Wardad4d9b92002-12-30 03:02:22 +000061 int fd; /* The open mixer device */
Greg Ward3d9994d2002-12-11 15:12:01 +000062} oss_mixer_t;
63
Greg Ward04613a92002-11-30 22:47:45 +000064
Greg Ward499b73e2002-12-31 03:04:52 +000065static PyTypeObject OSSAudioType;
Greg Ward3d9994d2002-12-11 15:12:01 +000066static PyTypeObject OSSMixerType;
Greg Ward04613a92002-11-30 22:47:45 +000067
Greg Ward97708bc2002-11-30 23:17:10 +000068static PyObject *OSSAudioError;
Greg Ward04613a92002-11-30 22:47:45 +000069
Greg Wardda1cacb2002-12-31 03:02:23 +000070
71/* ----------------------------------------------------------------------
72 * DSP object initialization/deallocation
73 */
74
Greg Ward499b73e2002-12-31 03:04:52 +000075static oss_audio_t *
Greg Ward8c6b6a92002-12-11 14:43:13 +000076newossobject(PyObject *arg)
Greg Ward04613a92002-11-30 22:47:45 +000077{
Greg Ward58ae13c2002-12-31 03:07:21 +000078 oss_audio_t *self;
Greg Ward04613a92002-11-30 22:47:45 +000079 int fd, afmts, imode;
Greg Ward50682d02005-03-07 01:41:11 +000080 char *devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000081 char *mode = NULL;
82
Greg Ward9a568eb2002-11-30 23:20:09 +000083 /* Two ways to call open():
Greg Ward04613a92002-11-30 22:47:45 +000084 open(device, mode) (for consistency with builtin open())
85 open(mode) (for backwards compatibility)
86 because the *first* argument is optional, parsing args is
87 a wee bit tricky. */
Greg Ward50682d02005-03-07 01:41:11 +000088 if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
Greg Ward04613a92002-11-30 22:47:45 +000089 return NULL;
90 if (mode == NULL) { /* only one arg supplied */
Greg Ward50682d02005-03-07 01:41:11 +000091 mode = devicename;
92 devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000093 }
94
95 if (strcmp(mode, "r") == 0)
96 imode = O_RDONLY;
97 else if (strcmp(mode, "w") == 0)
98 imode = O_WRONLY;
Greg Ward1e0f57d2002-11-30 23:05:26 +000099 else if (strcmp(mode, "rw") == 0)
100 imode = O_RDWR;
Greg Ward04613a92002-11-30 22:47:45 +0000101 else {
Greg Ward97708bc2002-11-30 23:17:10 +0000102 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
Greg Ward04613a92002-11-30 22:47:45 +0000103 return NULL;
104 }
105
Greg Ward5c5c5772002-12-30 02:58:04 +0000106 /* Open the correct device: either the 'device' argument,
107 or the AUDIODEV environment variable, or "/dev/dsp". */
Greg Ward50682d02005-03-07 01:41:11 +0000108 if (devicename == NULL) { /* called with one arg */
109 devicename = getenv("AUDIODEV");
110 if (devicename == NULL) /* $AUDIODEV not set */
111 devicename = "/dev/dsp";
Greg Ward04613a92002-11-30 22:47:45 +0000112 }
113
Greg Ward5c49ef22003-03-11 16:53:13 +0000114 /* Open with O_NONBLOCK to avoid hanging on devices that only allow
115 one open at a time. This does *not* affect later I/O; OSS
116 provides a special ioctl() for non-blocking read/write, which is
117 exposed via oss_nonblock() below. */
Greg Ward50682d02005-03-07 01:41:11 +0000118 if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) {
119 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000120 return NULL;
121 }
Greg Ward76ffb192003-04-04 01:47:42 +0000122
123 /* And (try to) put it back in blocking mode so we get the
124 expected write() semantics. */
125 if (fcntl(fd, F_SETFL, 0) == -1) {
126 close(fd);
Greg Ward50682d02005-03-07 01:41:11 +0000127 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward76ffb192003-04-04 01:47:42 +0000128 return NULL;
129 }
130
Greg Ward04613a92002-11-30 22:47:45 +0000131 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
Charles-François Natali564f8902011-09-29 19:43:01 +0200132 close(fd);
Greg Ward50682d02005-03-07 01:41:11 +0000133 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000134 return NULL;
135 }
136 /* Create and initialize the object */
Greg Ward58ae13c2002-12-31 03:07:21 +0000137 if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) {
Greg Ward04613a92002-11-30 22:47:45 +0000138 close(fd);
139 return NULL;
140 }
Greg Ward50682d02005-03-07 01:41:11 +0000141 self->devicename = devicename;
Greg Ward58ae13c2002-12-31 03:07:21 +0000142 self->fd = fd;
143 self->mode = imode;
144 self->icount = self->ocount = 0;
145 self->afmts = afmts;
146 return self;
Greg Ward04613a92002-11-30 22:47:45 +0000147}
148
149static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000150oss_dealloc(oss_audio_t *self)
Greg Ward04613a92002-11-30 22:47:45 +0000151{
152 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000153 if (self->fd != -1)
154 close(self->fd);
155 PyObject_Del(self);
Greg Ward04613a92002-11-30 22:47:45 +0000156}
157
Greg Wardda1cacb2002-12-31 03:02:23 +0000158
159/* ----------------------------------------------------------------------
160 * Mixer object initialization/deallocation
161 */
162
Greg Ward3d9994d2002-12-11 15:12:01 +0000163static oss_mixer_t *
164newossmixerobject(PyObject *arg)
165{
Greg Ward50682d02005-03-07 01:41:11 +0000166 char *devicename = NULL;
Greg Ward0b6dfb82003-03-10 03:17:06 +0000167 int fd;
Greg Ward58ae13c2002-12-31 03:07:21 +0000168 oss_mixer_t *self;
Guido van Rossum0741f802003-06-02 14:15:34 +0000169
Greg Ward50682d02005-03-07 01:41:11 +0000170 if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000171 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000172 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000173
Greg Ward50682d02005-03-07 01:41:11 +0000174 if (devicename == NULL) {
175 devicename = getenv("MIXERDEV");
176 if (devicename == NULL) /* MIXERDEV not set */
177 devicename = "/dev/mixer";
Greg Ward3d9994d2002-12-11 15:12:01 +0000178 }
179
Greg Ward50682d02005-03-07 01:41:11 +0000180 if ((fd = open(devicename, O_RDWR)) == -1) {
181 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward3d9994d2002-12-11 15:12:01 +0000182 return NULL;
183 }
Greg Ward0b6dfb82003-03-10 03:17:06 +0000184
Greg Ward58ae13c2002-12-31 03:07:21 +0000185 if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
Greg Ward3d9994d2002-12-11 15:12:01 +0000186 close(fd);
187 return NULL;
188 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000189
Greg Ward58ae13c2002-12-31 03:07:21 +0000190 self->fd = fd;
Guido van Rossum0741f802003-06-02 14:15:34 +0000191
Greg Ward58ae13c2002-12-31 03:07:21 +0000192 return self;
Greg Ward3d9994d2002-12-11 15:12:01 +0000193}
194
195static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000196oss_mixer_dealloc(oss_mixer_t *self)
Greg Ward3d9994d2002-12-11 15:12:01 +0000197{
198 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000199 if (self->fd != -1)
200 close(self->fd);
201 PyObject_Del(self);
Greg Ward3d9994d2002-12-11 15:12:01 +0000202}
203
Greg Ward131bce02002-11-30 22:56:44 +0000204
205/* Methods to wrap the OSS ioctls. The calling convention is pretty
206 simple:
207 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
208 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
209 etc.
210*/
211
212
Greg Wardd6769062003-05-29 21:53:06 +0000213/* ----------------------------------------------------------------------
214 * Helper functions
215 */
216
Greg Ward131bce02002-11-30 22:56:44 +0000217/* _do_ioctl_1() is a private helper function used for the OSS ioctls --
218 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C
219 like this:
220 ioctl(fd, SNDCTL_DSP_cmd, &arg)
221
222 where arg is the value to set, and on return the driver sets arg to
223 the value that was actually set. Mapping this to Python is obvious:
224 arg = dsp.xxx(arg)
225*/
226static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000227_do_ioctl_1(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000228{
Greg Wardda9f8532002-12-11 14:49:59 +0000229 char argfmt[33] = "i:";
Greg Ward131bce02002-11-30 22:56:44 +0000230 int arg;
231
Greg Wardda9f8532002-12-11 14:49:59 +0000232 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000233 strcat(argfmt, fname);
234 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000235 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000236
Greg Wardda9f8532002-12-11 14:49:59 +0000237 if (ioctl(fd, cmd, &arg) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000238 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000239 return PyInt_FromLong(arg);
240}
241
Greg Wardda1cacb2002-12-31 03:02:23 +0000242
Greg Ward3d9994d2002-12-11 15:12:01 +0000243/* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
244 but return an output -- ie. we need to pass a pointer to a local C
245 variable so the driver can write its output there, but from Python
246 all we see is the return value. For example,
247 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
248 devices, but does not use the value of the parameter passed-in in any
249 way.
250*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000251static PyObject *
252_do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd)
253{
254 char argfmt[32] = ":";
255 int arg = 0;
256
257 assert(strlen(fname) <= 30);
258 strcat(argfmt, fname);
259 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000260 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000261
262 if (ioctl(fd, cmd, &arg) == -1)
263 return PyErr_SetFromErrno(PyExc_IOError);
264 return PyInt_FromLong(arg);
265}
266
267
268
Greg Ward131bce02002-11-30 22:56:44 +0000269/* _do_ioctl_0() is a private helper for the no-argument ioctls:
270 SNDCTL_DSP_{SYNC,RESET,POST}. */
271static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000272_do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000273{
Greg Wardda9f8532002-12-11 14:49:59 +0000274 char argfmt[32] = ":";
Greg Wardd0d592f2003-05-27 01:57:21 +0000275 int rv;
Greg Ward131bce02002-11-30 22:56:44 +0000276
Greg Wardda9f8532002-12-11 14:49:59 +0000277 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000278 strcat(argfmt, fname);
279 if (!PyArg_ParseTuple(args, argfmt))
Greg Wardad4d9b92002-12-30 03:02:22 +0000280 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000281
Greg Wardd0d592f2003-05-27 01:57:21 +0000282 /* According to hannu@opensound.com, all three of the ioctls that
283 use this function can block, so release the GIL. This is
284 especially important for SYNC, which can block for several
285 seconds. */
286 Py_BEGIN_ALLOW_THREADS
287 rv = ioctl(fd, cmd, 0);
288 Py_END_ALLOW_THREADS
289
290 if (rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000291 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000292 Py_INCREF(Py_None);
293 return Py_None;
294}
295
296
Greg Wardda1cacb2002-12-31 03:02:23 +0000297/* ----------------------------------------------------------------------
Greg Ward499b73e2002-12-31 03:04:52 +0000298 * Methods of DSP objects (OSSAudioType)
Greg Wardda1cacb2002-12-31 03:02:23 +0000299 */
300
Greg Ward131bce02002-11-30 22:56:44 +0000301static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000302oss_nonblock(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000303{
304 /* Hmmm: it doesn't appear to be possible to return to blocking
305 mode once we're in non-blocking mode! */
Greg Ward7b43c682002-12-30 02:29:28 +0000306 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000307 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000308 Py_INCREF(Py_None);
309 return Py_None;
310}
311
312static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000313oss_setfmt(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000314{
Greg Ward7b43c682002-12-30 02:29:28 +0000315 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
Greg Ward131bce02002-11-30 22:56:44 +0000316}
317
318static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000319oss_getfmts(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000320{
321 int mask;
Greg Ward7b43c682002-12-30 02:29:28 +0000322 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000323 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000324 return PyInt_FromLong(mask);
325}
326
327static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000328oss_channels(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000329{
Greg Ward7b43c682002-12-30 02:29:28 +0000330 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
Greg Ward131bce02002-11-30 22:56:44 +0000331}
332
333static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000334oss_speed(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000335{
Greg Ward7b43c682002-12-30 02:29:28 +0000336 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
Greg Ward131bce02002-11-30 22:56:44 +0000337}
338
339static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000340oss_sync(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000341{
Greg Wardd0d592f2003-05-27 01:57:21 +0000342 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
Greg Ward131bce02002-11-30 22:56:44 +0000343}
Guido van Rossum0741f802003-06-02 14:15:34 +0000344
Greg Ward131bce02002-11-30 22:56:44 +0000345static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000346oss_reset(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000347{
Greg Ward7b43c682002-12-30 02:29:28 +0000348 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
Greg Ward131bce02002-11-30 22:56:44 +0000349}
Guido van Rossum0741f802003-06-02 14:15:34 +0000350
Greg Ward131bce02002-11-30 22:56:44 +0000351static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000352oss_post(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000353{
Greg Ward7b43c682002-12-30 02:29:28 +0000354 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
Greg Ward131bce02002-11-30 22:56:44 +0000355}
356
357
358/* Regular file methods: read(), write(), close(), etc. as well
359 as one convenience method, writeall(). */
360
Greg Ward04613a92002-11-30 22:47:45 +0000361static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000362oss_read(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000363{
364 int size, count;
365 char *cp;
366 PyObject *rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000367
Greg Ward04613a92002-11-30 22:47:45 +0000368 if (!PyArg_ParseTuple(args, "i:read", &size))
369 return NULL;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000370 rv = PyString_FromStringAndSize(NULL, size);
Greg Ward04613a92002-11-30 22:47:45 +0000371 if (rv == NULL)
372 return NULL;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000373 cp = PyString_AS_STRING(rv);
Greg Ward64927852003-05-23 01:50:37 +0000374
375 Py_BEGIN_ALLOW_THREADS
376 count = read(self->fd, cp, size);
377 Py_END_ALLOW_THREADS
378
379 if (count < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000380 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000381 Py_DECREF(rv);
382 return NULL;
383 }
Greg Ward7b43c682002-12-30 02:29:28 +0000384 self->icount += count;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000385 _PyString_Resize(&rv, count);
Greg Ward04613a92002-11-30 22:47:45 +0000386 return rv;
387}
388
389static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000390oss_write(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000391{
392 char *cp;
393 int rv, size;
Greg Ward131bce02002-11-30 22:56:44 +0000394
395 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000396 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000397 }
Greg Ward64927852003-05-23 01:50:37 +0000398
399 Py_BEGIN_ALLOW_THREADS
400 rv = write(self->fd, cp, size);
401 Py_END_ALLOW_THREADS
402
403 if (rv == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000404 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000405 } else {
Greg Ward7b43c682002-12-30 02:29:28 +0000406 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000407 }
408 return PyInt_FromLong(rv);
409}
410
411static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000412oss_writeall(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000413{
414 char *cp;
415 int rv, size;
416 fd_set write_set_fds;
417 int select_rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000418
Greg Ward131bce02002-11-30 22:56:44 +0000419 /* NB. writeall() is only useful in non-blocking mode: according to
420 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
421 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
422 write() in blocking mode consumes the whole buffer. In blocking
423 mode, the behaviour of write() and writeall() from Python is
424 indistinguishable. */
425
Guido van Rossum0741f802003-06-02 14:15:34 +0000426 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
Greg Ward131bce02002-11-30 22:56:44 +0000427 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000428
Charles-François Natalifda7b372011-08-28 16:22:33 +0200429 if (!_PyIsSelectable_fd(self->fd)) {
430 PyErr_SetString(PyExc_ValueError,
431 "file descriptor out of range for select");
432 return NULL;
433 }
Greg Ward04613a92002-11-30 22:47:45 +0000434 /* use select to wait for audio device to be available */
435 FD_ZERO(&write_set_fds);
Greg Ward7b43c682002-12-30 02:29:28 +0000436 FD_SET(self->fd, &write_set_fds);
Greg Ward04613a92002-11-30 22:47:45 +0000437
438 while (size > 0) {
Greg Ward64927852003-05-23 01:50:37 +0000439 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000440 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Greg Ward64927852003-05-23 01:50:37 +0000441 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000442 assert(select_rv != 0); /* no timeout, can't expire */
443 if (select_rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000444 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000445
Greg Ward64927852003-05-23 01:50:37 +0000446 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000447 rv = write(self->fd, cp, size);
Greg Ward64927852003-05-23 01:50:37 +0000448 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000449 if (rv == -1) {
450 if (errno == EAGAIN) { /* buffer is full, try again */
451 errno = 0;
452 continue;
453 } else /* it's a real error */
Greg Ward97708bc2002-11-30 23:17:10 +0000454 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000455 } else { /* wrote rv bytes */
Greg Ward7b43c682002-12-30 02:29:28 +0000456 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000457 size -= rv;
458 cp += rv;
459 }
Greg Ward04613a92002-11-30 22:47:45 +0000460 }
461 Py_INCREF(Py_None);
462 return Py_None;
463}
464
465static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000466oss_close(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000467{
Greg Ward7b43c682002-12-30 02:29:28 +0000468 if (self->fd >= 0) {
Greg Wardb8043902003-05-26 22:47:30 +0000469 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000470 close(self->fd);
Greg Wardb8043902003-05-26 22:47:30 +0000471 Py_END_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000472 self->fd = -1;
Greg Ward04613a92002-11-30 22:47:45 +0000473 }
474 Py_INCREF(Py_None);
475 return Py_None;
476}
477
478static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000479oss_fileno(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000480{
Greg Ward7b43c682002-12-30 02:29:28 +0000481 return PyInt_FromLong(self->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000482}
483
Greg Ward131bce02002-11-30 22:56:44 +0000484
485/* Convenience methods: these generally wrap a couple of ioctls into one
486 common task. */
487
Greg Ward04613a92002-11-30 22:47:45 +0000488static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000489oss_setparameters(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000490{
Greg Wardd6769062003-05-29 21:53:06 +0000491 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
492 int fmt, channels, rate;
493 PyObject * rv; /* return tuple (fmt, channels, rate) */
Greg Ward04613a92002-11-30 22:47:45 +0000494
Greg Wardd6769062003-05-29 21:53:06 +0000495 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
496 &wanted_fmt, &wanted_channels, &wanted_rate,
497 &strict))
Greg Ward04613a92002-11-30 22:47:45 +0000498 return NULL;
Greg Wardd6769062003-05-29 21:53:06 +0000499
500 fmt = wanted_fmt;
501 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
502 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000503 }
Greg Wardd6769062003-05-29 21:53:06 +0000504 if (strict && fmt != wanted_fmt) {
505 return PyErr_Format
506 (OSSAudioError,
507 "unable to set requested format (wanted %d, got %d)",
508 wanted_fmt, fmt);
Greg Ward04613a92002-11-30 22:47:45 +0000509 }
510
Greg Wardd6769062003-05-29 21:53:06 +0000511 channels = wanted_channels;
512 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
513 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000514 }
Greg Wardd6769062003-05-29 21:53:06 +0000515 if (strict && channels != wanted_channels) {
516 return PyErr_Format
517 (OSSAudioError,
518 "unable to set requested channels (wanted %d, got %d)",
519 wanted_channels, channels);
Greg Ward04613a92002-11-30 22:47:45 +0000520 }
521
Greg Wardd6769062003-05-29 21:53:06 +0000522 rate = wanted_rate;
Greg Ward7b43c682002-12-30 02:29:28 +0000523 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Greg Wardd6769062003-05-29 21:53:06 +0000524 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000525 }
Greg Wardd6769062003-05-29 21:53:06 +0000526 if (strict && rate != wanted_rate) {
527 return PyErr_Format
528 (OSSAudioError,
529 "unable to set requested rate (wanted %d, got %d)",
530 wanted_rate, rate);
531 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000532
Greg Wardd6769062003-05-29 21:53:06 +0000533 /* Construct the return value: a (fmt, channels, rate) tuple that
534 tells what the audio hardware was actually set to. */
535 rv = PyTuple_New(3);
536 if (rv == NULL)
537 return NULL;
538 PyTuple_SET_ITEM(rv, 0, PyInt_FromLong(fmt));
539 PyTuple_SET_ITEM(rv, 1, PyInt_FromLong(channels));
540 PyTuple_SET_ITEM(rv, 2, PyInt_FromLong(rate));
541 return rv;
Greg Ward04613a92002-11-30 22:47:45 +0000542}
543
544static int
Greg Ward499b73e2002-12-31 03:04:52 +0000545_ssize(oss_audio_t *self, int *nchannels, int *ssize)
Greg Ward04613a92002-11-30 22:47:45 +0000546{
547 int fmt;
548
549 fmt = 0;
Guido van Rossum0741f802003-06-02 14:15:34 +0000550 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000551 return -errno;
552
553 switch (fmt) {
554 case AFMT_MU_LAW:
555 case AFMT_A_LAW:
556 case AFMT_U8:
557 case AFMT_S8:
Greg Ward38c92662003-05-29 21:55:41 +0000558 *ssize = 1; /* 8 bit formats: 1 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000559 break;
560 case AFMT_S16_LE:
561 case AFMT_S16_BE:
562 case AFMT_U16_LE:
563 case AFMT_U16_BE:
Greg Ward84f8ecd2003-05-29 23:44:44 +0000564 *ssize = 2; /* 16 bit formats: 2 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000565 break;
566 case AFMT_MPEG:
567 case AFMT_IMA_ADPCM:
568 default:
569 return -EOPNOTSUPP;
570 }
Greg Ward7b43c682002-12-30 02:29:28 +0000571 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000572 return -errno;
573 return 0;
574}
575
576
Guido van Rossum0741f802003-06-02 14:15:34 +0000577/* bufsize returns the size of the hardware audio buffer in number
Greg Ward04613a92002-11-30 22:47:45 +0000578 of samples */
579static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000580oss_bufsize(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000581{
582 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000583 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000584
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000585 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000586 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000587 return NULL;
588 }
Greg Ward7b43c682002-12-30 02:29:28 +0000589 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000590 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000591 return NULL;
592 }
593 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
594}
595
Guido van Rossum0741f802003-06-02 14:15:34 +0000596/* obufcount returns the number of samples that are available in the
Greg Ward04613a92002-11-30 22:47:45 +0000597 hardware for playing */
598static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000599oss_obufcount(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000600{
601 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000602 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000603
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000604 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000605 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000606 return NULL;
607 }
Greg Ward7b43c682002-12-30 02:29:28 +0000608 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000609 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000610 return NULL;
611 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000612 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
Greg Ward04613a92002-11-30 22:47:45 +0000613 (ssize * nchannels));
614}
615
616/* obufcount returns the number of samples that can be played without
617 blocking */
618static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000619oss_obuffree(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000620{
621 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000622 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000623
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000624 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000625 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000626 return NULL;
627 }
Greg Ward7b43c682002-12-30 02:29:28 +0000628 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000629 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000630 return NULL;
631 }
632 return PyInt_FromLong(ai.bytes / (ssize * nchannels));
633}
634
Greg Ward04613a92002-11-30 22:47:45 +0000635static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000636oss_getptr(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000637{
638 count_info info;
639 int req;
640
Greg Ward7b43c682002-12-30 02:29:28 +0000641 if (self->mode == O_RDONLY)
Greg Wardad4d9b92002-12-30 03:02:22 +0000642 req = SNDCTL_DSP_GETIPTR;
Greg Ward04613a92002-11-30 22:47:45 +0000643 else
Greg Wardad4d9b92002-12-30 03:02:22 +0000644 req = SNDCTL_DSP_GETOPTR;
Greg Ward7b43c682002-12-30 02:29:28 +0000645 if (ioctl(self->fd, req, &info) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000646 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000647 return NULL;
648 }
649 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
650}
651
Greg Wardda1cacb2002-12-31 03:02:23 +0000652
653/* ----------------------------------------------------------------------
654 * Methods of mixer objects (OSSMixerType)
655 */
656
Greg Ward3d9994d2002-12-11 15:12:01 +0000657static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000658oss_mixer_close(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000659{
Greg Ward7b43c682002-12-30 02:29:28 +0000660 if (self->fd >= 0) {
661 close(self->fd);
662 self->fd = -1;
Greg Ward3d9994d2002-12-11 15:12:01 +0000663 }
664 Py_INCREF(Py_None);
665 return Py_None;
666}
667
668static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000669oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000670{
Greg Ward7b43c682002-12-30 02:29:28 +0000671 return PyInt_FromLong(self->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000672}
673
674/* Simple mixer interface methods */
675
676static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000677oss_mixer_controls(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000678{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000679 return _do_ioctl_1_internal(self->fd, args, "controls",
Greg Ward3d9994d2002-12-11 15:12:01 +0000680 SOUND_MIXER_READ_DEVMASK);
681}
682
683static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000684oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000685{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000686 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
Greg Ward3d9994d2002-12-11 15:12:01 +0000687 SOUND_MIXER_READ_STEREODEVS);
688}
689
690static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000691oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000692{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000693 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
Greg Wardb69bb3d2002-12-12 17:35:45 +0000694 SOUND_MIXER_READ_RECMASK);
Greg Ward3d9994d2002-12-11 15:12:01 +0000695}
696
697static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000698oss_mixer_get(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000699{
700 int channel, volume;
Guido van Rossum0741f802003-06-02 14:15:34 +0000701
Greg Ward3d9994d2002-12-11 15:12:01 +0000702 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000703 if (!PyArg_ParseTuple(args, "i:get", &channel))
Greg Wardad4d9b92002-12-30 03:02:22 +0000704 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000705
Greg Ward3d9994d2002-12-11 15:12:01 +0000706 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000707 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
708 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000709 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000710
Greg Warde7037662002-12-30 03:01:48 +0000711 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000712 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000713
Greg Warde7037662002-12-30 03:01:48 +0000714 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000715}
716
717static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000718oss_mixer_set(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000719{
720 int channel, volume, leftVol, rightVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000721
Greg Ward3d9994d2002-12-11 15:12:01 +0000722 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000723 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
Greg Wardad4d9b92002-12-30 03:02:22 +0000724 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000725
Greg Ward3d9994d2002-12-11 15:12:01 +0000726 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000727 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
728 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000729 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000730
Greg Ward3d9994d2002-12-11 15:12:01 +0000731 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000732 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
733 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000734 }
735
736 volume = (rightVol << 8) | leftVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000737
Greg Warde7037662002-12-30 03:01:48 +0000738 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000739 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000740
Greg Warde7037662002-12-30 03:01:48 +0000741 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000742}
743
744static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000745oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000746{
Greg Wardf05aa102002-12-30 23:19:32 +0000747 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000748 SOUND_MIXER_READ_RECSRC);
749}
750
751static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000752oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000753{
Greg Wardf05aa102002-12-30 23:19:32 +0000754 return _do_ioctl_1(self->fd, args, "set_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000755 SOUND_MIXER_WRITE_RECSRC);
756}
757
758
Greg Wardda1cacb2002-12-31 03:02:23 +0000759/* ----------------------------------------------------------------------
760 * Method tables and other bureaucracy
761 */
762
Greg Ward8c6b6a92002-12-11 14:43:13 +0000763static PyMethodDef oss_methods[] = {
Greg Ward131bce02002-11-30 22:56:44 +0000764 /* Regular file methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000765 { "read", (PyCFunction)oss_read, METH_VARARGS },
766 { "write", (PyCFunction)oss_write, METH_VARARGS },
767 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000768 { "close", (PyCFunction)oss_close, METH_NOARGS },
769 { "fileno", (PyCFunction)oss_fileno, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000770
771 /* Simple ioctl wrappers */
Georg Brandl96a8c392006-05-29 21:04:52 +0000772 { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000773 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000774 { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS },
Greg Ward8c6b6a92002-12-11 14:43:13 +0000775 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
776 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000777 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
778 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
779 { "post", (PyCFunction)oss_post, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000780
781 /* Convenience methods -- wrap a couple of ioctls together */
Greg Wardad4d9b92002-12-30 03:02:22 +0000782 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000783 { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS },
784 { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS },
785 { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS },
786 { "getptr", (PyCFunction)oss_getptr, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000787
788 /* Aliases for backwards compatibility */
Greg Wardad4d9b92002-12-30 03:02:22 +0000789 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000790
Greg Wardad4d9b92002-12-30 03:02:22 +0000791 { NULL, NULL} /* sentinel */
Greg Ward04613a92002-11-30 22:47:45 +0000792};
793
Greg Ward3d9994d2002-12-11 15:12:01 +0000794static PyMethodDef oss_mixer_methods[] = {
795 /* Regular file method - OSS mixers are ioctl-only interface */
Georg Brandl96a8c392006-05-29 21:04:52 +0000796 { "close", (PyCFunction)oss_mixer_close, METH_NOARGS },
797 { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000798
799 /* Simple ioctl wrappers */
Guido van Rossum0741f802003-06-02 14:15:34 +0000800 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
Greg Ward2d6f9a92002-12-31 02:54:43 +0000801 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
Guido van Rossum0741f802003-06-02 14:15:34 +0000802 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
Greg Wardad4d9b92002-12-30 03:02:22 +0000803 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
804 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
Greg Wardf05aa102002-12-30 23:19:32 +0000805 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
806 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
Guido van Rossum0741f802003-06-02 14:15:34 +0000807
Greg Wardad4d9b92002-12-30 03:02:22 +0000808 { NULL, NULL}
Greg Ward3d9994d2002-12-11 15:12:01 +0000809};
810
Greg Ward04613a92002-11-30 22:47:45 +0000811static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000812oss_getattr(oss_audio_t *self, char *name)
Greg Ward04613a92002-11-30 22:47:45 +0000813{
Greg Ward50682d02005-03-07 01:41:11 +0000814 PyObject * rval = NULL;
815 if (strcmp(name, "closed") == 0) {
816 rval = (self->fd == -1) ? Py_True : Py_False;
817 Py_INCREF(rval);
818 }
819 else if (strcmp(name, "name") == 0) {
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000820 rval = PyString_FromString(self->devicename);
Greg Ward50682d02005-03-07 01:41:11 +0000821 }
822 else if (strcmp(name, "mode") == 0) {
823 /* No need for a "default" in this switch: from newossobject(),
824 self->mode can only be one of these three values. */
825 switch(self->mode) {
826 case O_RDONLY:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000827 rval = PyString_FromString("r");
Greg Ward50682d02005-03-07 01:41:11 +0000828 break;
829 case O_RDWR:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000830 rval = PyString_FromString("rw");
Greg Ward50682d02005-03-07 01:41:11 +0000831 break;
832 case O_WRONLY:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000833 rval = PyString_FromString("w");
Greg Ward50682d02005-03-07 01:41:11 +0000834 break;
835 }
836 }
837 else {
838 rval = Py_FindMethod(oss_methods, (PyObject *)self, name);
839 }
840 return rval;
Greg Ward04613a92002-11-30 22:47:45 +0000841}
842
Greg Ward3d9994d2002-12-11 15:12:01 +0000843static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000844oss_mixer_getattr(oss_mixer_t *self, char *name)
Greg Ward3d9994d2002-12-11 15:12:01 +0000845{
Greg Ward58ae13c2002-12-31 03:07:21 +0000846 return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name);
Greg Ward3d9994d2002-12-11 15:12:01 +0000847}
848
Greg Ward499b73e2002-12-31 03:04:52 +0000849static PyTypeObject OSSAudioType = {
Martin v. Löwis68192102007-07-21 06:55:02 +0000850 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Greg Ward9a568eb2002-11-30 23:20:09 +0000851 "ossaudiodev.oss_audio_device", /*tp_name*/
Greg Ward499b73e2002-12-31 03:04:52 +0000852 sizeof(oss_audio_t), /*tp_size*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000853 0, /*tp_itemsize*/
Greg Ward04613a92002-11-30 22:47:45 +0000854 /* methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000855 (destructor)oss_dealloc, /*tp_dealloc*/
856 0, /*tp_print*/
857 (getattrfunc)oss_getattr, /*tp_getattr*/
858 0, /*tp_setattr*/
859 0, /*tp_compare*/
860 0, /*tp_repr*/
Greg Ward04613a92002-11-30 22:47:45 +0000861};
862
Greg Ward3d9994d2002-12-11 15:12:01 +0000863static PyTypeObject OSSMixerType = {
Martin v. Löwis68192102007-07-21 06:55:02 +0000864 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Greg Ward3d9994d2002-12-11 15:12:01 +0000865 "ossaudiodev.oss_mixer_device", /*tp_name*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000866 sizeof(oss_mixer_t), /*tp_size*/
867 0, /*tp_itemsize*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000868 /* methods */
869 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000870 0, /*tp_print*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000871 (getattrfunc)oss_mixer_getattr, /*tp_getattr*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000872 0, /*tp_setattr*/
873 0, /*tp_compare*/
874 0, /*tp_repr*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000875};
876
877
Greg Ward04613a92002-11-30 22:47:45 +0000878static PyObject *
Greg Ward9a568eb2002-11-30 23:20:09 +0000879ossopen(PyObject *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000880{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000881 return (PyObject *)newossobject(args);
Greg Ward04613a92002-11-30 22:47:45 +0000882}
883
Greg Ward3d9994d2002-12-11 15:12:01 +0000884static PyObject *
885ossopenmixer(PyObject *self, PyObject *args)
886{
887 return (PyObject *)newossmixerobject(args);
888}
889
Greg Ward9a568eb2002-11-30 23:20:09 +0000890static PyMethodDef ossaudiodev_methods[] = {
891 { "open", ossopen, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000892 { "openmixer", ossopenmixer, METH_VARARGS },
Greg Ward04613a92002-11-30 22:47:45 +0000893 { 0, 0 },
894};
895
Greg Ward1e0f57d2002-11-30 23:05:26 +0000896
897#define _EXPORT_INT(mod, name) \
898 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
899
Greg Ward744f0fd2002-12-31 03:23:59 +0000900
901static char *control_labels[] = SOUND_DEVICE_LABELS;
902static char *control_names[] = SOUND_DEVICE_NAMES;
903
904
905static int
906build_namelists (PyObject *module)
907{
908 PyObject *labels;
909 PyObject *names;
910 PyObject *s;
911 int num_controls;
912 int i;
913
914 num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
915 assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
916
917 labels = PyList_New(num_controls);
918 names = PyList_New(num_controls);
Georg Brandl5c170fd2006-03-17 19:03:25 +0000919 if (labels == NULL || names == NULL)
920 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000921 for (i = 0; i < num_controls; i++) {
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000922 s = PyString_FromString(control_labels[i]);
Greg Ward744f0fd2002-12-31 03:23:59 +0000923 if (s == NULL)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000924 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000925 PyList_SET_ITEM(labels, i, s);
Guido van Rossum0741f802003-06-02 14:15:34 +0000926
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000927 s = PyString_FromString(control_names[i]);
Greg Ward744f0fd2002-12-31 03:23:59 +0000928 if (s == NULL)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000929 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000930 PyList_SET_ITEM(names, i, s);
931 }
932
933 if (PyModule_AddObject(module, "control_labels", labels) == -1)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000934 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000935 if (PyModule_AddObject(module, "control_names", names) == -1)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000936 goto error1;
Greg Ward744f0fd2002-12-31 03:23:59 +0000937
938 return 0;
Georg Brandl5c170fd2006-03-17 19:03:25 +0000939
940error2:
941 Py_XDECREF(labels);
942error1:
943 Py_XDECREF(names);
944 return -1;
Guido van Rossum0741f802003-06-02 14:15:34 +0000945}
Greg Ward744f0fd2002-12-31 03:23:59 +0000946
947
Greg Ward04613a92002-11-30 22:47:45 +0000948void
Greg Ward9a568eb2002-11-30 23:20:09 +0000949initossaudiodev(void)
Greg Ward04613a92002-11-30 22:47:45 +0000950{
951 PyObject *m;
Guido van Rossum0741f802003-06-02 14:15:34 +0000952
Greg Ward9a568eb2002-11-30 23:20:09 +0000953 m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
Neal Norwitz1ac754f2006-01-19 06:09:39 +0000954 if (m == NULL)
955 return;
Greg Ward04613a92002-11-30 22:47:45 +0000956
Guido van Rossum0741f802003-06-02 14:15:34 +0000957 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
958 NULL, NULL);
Greg Wardd6769062003-05-29 21:53:06 +0000959 if (OSSAudioError) {
Guido van Rossum0741f802003-06-02 14:15:34 +0000960 /* Each call to PyModule_AddObject decrefs it; compensate: */
961 Py_INCREF(OSSAudioError);
962 Py_INCREF(OSSAudioError);
Greg Wardad4d9b92002-12-30 03:02:22 +0000963 PyModule_AddObject(m, "error", OSSAudioError);
Greg Wardd6769062003-05-29 21:53:06 +0000964 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
965 }
Greg Ward04613a92002-11-30 22:47:45 +0000966
Greg Ward744f0fd2002-12-31 03:23:59 +0000967 /* Build 'control_labels' and 'control_names' lists and add them
968 to the module. */
969 if (build_namelists(m) == -1) /* XXX what to do here? */
970 return;
971
Greg Ward1e0f57d2002-11-30 23:05:26 +0000972 /* Expose the audio format numbers -- essential! */
973 _EXPORT_INT(m, AFMT_QUERY);
974 _EXPORT_INT(m, AFMT_MU_LAW);
975 _EXPORT_INT(m, AFMT_A_LAW);
976 _EXPORT_INT(m, AFMT_IMA_ADPCM);
977 _EXPORT_INT(m, AFMT_U8);
978 _EXPORT_INT(m, AFMT_S16_LE);
979 _EXPORT_INT(m, AFMT_S16_BE);
980 _EXPORT_INT(m, AFMT_S8);
981 _EXPORT_INT(m, AFMT_U16_LE);
982 _EXPORT_INT(m, AFMT_U16_BE);
983 _EXPORT_INT(m, AFMT_MPEG);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000984#ifdef AFMT_AC3
Greg Ward1e0f57d2002-11-30 23:05:26 +0000985 _EXPORT_INT(m, AFMT_AC3);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000986#endif
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000987#ifdef AFMT_S16_NE
Greg Ward1e0f57d2002-11-30 23:05:26 +0000988 _EXPORT_INT(m, AFMT_S16_NE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000989#endif
Greg Ward0f260542005-03-28 02:40:46 +0000990#ifdef AFMT_U16_NE
991 _EXPORT_INT(m, AFMT_U16_NE);
992#endif
993#ifdef AFMT_S32_LE
994 _EXPORT_INT(m, AFMT_S32_LE);
995#endif
996#ifdef AFMT_S32_BE
997 _EXPORT_INT(m, AFMT_S32_BE);
998#endif
999#ifdef AFMT_MPEG
1000 _EXPORT_INT(m, AFMT_MPEG);
1001#endif
Guido van Rossum0741f802003-06-02 14:15:34 +00001002
Greg Ward37897c22002-12-30 02:43:36 +00001003 /* Expose the sound mixer device numbers. */
Greg Ward7b43c682002-12-30 02:29:28 +00001004 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
Greg Ward3d9994d2002-12-11 15:12:01 +00001005 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1006 _EXPORT_INT(m, SOUND_MIXER_BASS);
1007 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1008 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1009 _EXPORT_INT(m, SOUND_MIXER_PCM);
1010 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1011 _EXPORT_INT(m, SOUND_MIXER_LINE);
1012 _EXPORT_INT(m, SOUND_MIXER_MIC);
1013 _EXPORT_INT(m, SOUND_MIXER_CD);
1014 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1015 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1016 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1017 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1018 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1019 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1020 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1021 _EXPORT_INT(m, SOUND_MIXER_LINE3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001022#ifdef SOUND_MIXER_DIGITAL1
Greg Ward3d9994d2002-12-11 15:12:01 +00001023 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
Greg Wardfd0283e2004-05-11 01:34:55 +00001024#endif
1025#ifdef SOUND_MIXER_DIGITAL2
Greg Ward3d9994d2002-12-11 15:12:01 +00001026 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
Greg Wardfd0283e2004-05-11 01:34:55 +00001027#endif
1028#ifdef SOUND_MIXER_DIGITAL3
Greg Ward3d9994d2002-12-11 15:12:01 +00001029 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001030#endif
1031#ifdef SOUND_MIXER_PHONEIN
Greg Ward3d9994d2002-12-11 15:12:01 +00001032 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
Greg Wardfd0283e2004-05-11 01:34:55 +00001033#endif
1034#ifdef SOUND_MIXER_PHONEOUT
Greg Ward3d9994d2002-12-11 15:12:01 +00001035 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
Greg Wardfd0283e2004-05-11 01:34:55 +00001036#endif
1037#ifdef SOUND_MIXER_VIDEO
Greg Ward3d9994d2002-12-11 15:12:01 +00001038 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001039#endif
1040#ifdef SOUND_MIXER_RADIO
Greg Ward3d9994d2002-12-11 15:12:01 +00001041 _EXPORT_INT(m, SOUND_MIXER_RADIO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001042#endif
1043#ifdef SOUND_MIXER_MONITOR
Greg Ward3d9994d2002-12-11 15:12:01 +00001044 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
Greg Wardfd0283e2004-05-11 01:34:55 +00001045#endif
Greg Ward04613a92002-11-30 22:47:45 +00001046
Greg Ward1e0f57d2002-11-30 23:05:26 +00001047 /* Expose all the ioctl numbers for masochists who like to do this
1048 stuff directly. */
1049 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1050 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1051 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1052 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1053 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1054 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1055 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1056 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1057 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1058 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001059#ifdef SNDCTL_DSP_BIND_CHANNEL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001060 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001061#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001062 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1063 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1064 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001065#ifdef SNDCTL_DSP_GETCHANNELMASK
Greg Ward1e0f57d2002-11-30 23:05:26 +00001066 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001067#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001068 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1069 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1070 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
Greg Wardfd0283e2004-05-11 01:34:55 +00001071#ifdef SNDCTL_DSP_GETODELAY
Greg Ward1e0f57d2002-11-30 23:05:26 +00001072 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
Greg Wardfd0283e2004-05-11 01:34:55 +00001073#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001074 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1075 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001076#ifdef SNDCTL_DSP_GETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001077 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001078#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001079 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1080 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1081 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1082 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1083 _EXPORT_INT(m, SNDCTL_DSP_POST);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001084#ifdef SNDCTL_DSP_PROFILE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001085 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001086#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001087 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1088 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1089 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1090 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1091 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001092#ifdef SNDCTL_DSP_SETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001093 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001094#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001095 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1096 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1097 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1098 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1099 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1100 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1101 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1102 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1103 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1104 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1105 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1106 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1107 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1108 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1109 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001110#ifdef SNDCTL_SEQ_GETTIME
Greg Ward1e0f57d2002-11-30 23:05:26 +00001111 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001112#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001113 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1114 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1115 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1116 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1117 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1118 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1119 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1120 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1121 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1122 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001123#ifdef SNDCTL_SYNTH_CONTROL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001124 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001125#endif
1126#ifdef SNDCTL_SYNTH_ID
Greg Ward1e0f57d2002-11-30 23:05:26 +00001127 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001128#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001129 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1130 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001131#ifdef SNDCTL_SYNTH_REMOVESAMPLE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001132 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001133#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001134 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1135 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1136 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1137 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1138 _EXPORT_INT(m, SNDCTL_TMR_START);
1139 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1140 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1141 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
Greg Ward04613a92002-11-30 22:47:45 +00001142}