1 /*
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.
11 * Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002.
12 *
13 * (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 #define PY_SSIZE_T_CLEAN
23 #include "Python.h"
24 #include "structmember.h"
25
26 #ifdef HAVE_FCNTL_H
27 #include <fcntl.h>
28 #else
29 #define O_RDONLY 00
30 #define O_WRONLY 01
31 #endif
32
33 #include <sys/ioctl.h>
34 #ifdef __ANDROID__
35 #include <linux/soundcard.h>
36 #else
37 #include <sys/soundcard.h>
38 #endif
39
40 #ifdef __linux__
41
42 #ifndef HAVE_STDINT_H
43 typedef unsigned long uint32_t;
44 #endif
45
46 #elif defined(__FreeBSD__)
47
48 # ifndef SNDCTL_DSP_CHANNELS
49 # define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
50 # endif
51
52 #endif
53
54 typedef struct {
55 PyObject_HEAD
56 const char *devicename; /* name of the device file */
57 int fd; /* file descriptor */
58 int mode; /* file mode (O_RDONLY, etc.) */
59 Py_ssize_t icount; /* input count */
60 Py_ssize_t ocount; /* output count */
61 uint32_t afmts; /* audio formats supported by hardware */
62 } oss_audio_t;
63
64 typedef struct {
65 PyObject_HEAD
66 int fd; /* The open mixer device */
67 } oss_mixer_t;
68
69
70 static PyTypeObject OSSAudioType;
71 static PyTypeObject OSSMixerType;
72
73 static PyObject *OSSAudioError;
74
75
76 /* ----------------------------------------------------------------------
77 * DSP object initialization/deallocation
78 */
79
80 static oss_audio_t *
newossobject(PyObject * arg)81 newossobject(PyObject *arg)
82 {
83 oss_audio_t *self;
84 int fd, afmts, imode;
85 const char *devicename = NULL;
86 const char *mode = NULL;
87
88 /* Two ways to call open():
89 open(device, mode) (for consistency with builtin open())
90 open(mode) (for backwards compatibility)
91 because the *first* argument is optional, parsing args is
92 a wee bit tricky. */
93 if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
94 return NULL;
95 if (mode == NULL) { /* only one arg supplied */
96 mode = devicename;
97 devicename = NULL;
98 }
99
100 if (strcmp(mode, "r") == 0)
101 imode = O_RDONLY;
102 else if (strcmp(mode, "w") == 0)
103 imode = O_WRONLY;
104 else if (strcmp(mode, "rw") == 0)
105 imode = O_RDWR;
106 else {
107 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
108 return NULL;
109 }
110
111 /* Open the correct device: either the 'device' argument,
112 or the AUDIODEV environment variable, or "/dev/dsp". */
113 if (devicename == NULL) { /* called with one arg */
114 devicename = getenv("AUDIODEV");
115 if (devicename == NULL) /* $AUDIODEV not set */
116 devicename = "/dev/dsp";
117 }
118
119 /* Open with O_NONBLOCK to avoid hanging on devices that only allow
120 one open at a time. This does *not* affect later I/O; OSS
121 provides a special ioctl() for non-blocking read/write, which is
122 exposed via oss_nonblock() below. */
123 fd = _Py_open(devicename, imode|O_NONBLOCK);
124 if (fd == -1)
125 return NULL;
126
127 /* And (try to) put it back in blocking mode so we get the
128 expected write() semantics. */
129 if (fcntl(fd, F_SETFL, 0) == -1) {
130 close(fd);
131 PyErr_SetFromErrnoWithFilename(PyExc_OSError, devicename);
132 return NULL;
133 }
134
135 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
136 close(fd);
137 PyErr_SetFromErrnoWithFilename(PyExc_OSError, devicename);
138 return NULL;
139 }
140 /* Create and initialize the object */
141 if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) {
142 close(fd);
143 return NULL;
144 }
145 self->devicename = devicename;
146 self->fd = fd;
147 self->mode = imode;
148 self->icount = self->ocount = 0;
149 self->afmts = afmts;
150 return self;
151 }
152
153 static void
oss_dealloc(oss_audio_t * self)154 oss_dealloc(oss_audio_t *self)
155 {
156 /* if already closed, don't reclose it */
157 if (self->fd != -1)
158 close(self->fd);
159 PyObject_Del(self);
160 }
161
162
163 /* ----------------------------------------------------------------------
164 * Mixer object initialization/deallocation
165 */
166
167 static oss_mixer_t *
newossmixerobject(PyObject * arg)168 newossmixerobject(PyObject *arg)
169 {
170 const char *devicename = NULL;
171 int fd;
172 oss_mixer_t *self;
173
174 if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
175 return NULL;
176 }
177
178 if (devicename == NULL) {
179 devicename = getenv("MIXERDEV");
180 if (devicename == NULL) /* MIXERDEV not set */
181 devicename = "/dev/mixer";
182 }
183
184 fd = _Py_open(devicename, O_RDWR);
185 if (fd == -1)
186 return NULL;
187
188 if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
189 close(fd);
190 return NULL;
191 }
192
193 self->fd = fd;
194
195 return self;
196 }
197
198 static void
oss_mixer_dealloc(oss_mixer_t * self)199 oss_mixer_dealloc(oss_mixer_t *self)
200 {
201 /* if already closed, don't reclose it */
202 if (self->fd != -1)
203 close(self->fd);
204 PyObject_Del(self);
205 }
206
207
208 /* Methods to wrap the OSS ioctls. The calling convention is pretty
209 simple:
210 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
211 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
212 etc.
213 */
214
215
216 /* ----------------------------------------------------------------------
217 * Helper functions
218 */
219
220 /* Check if a given file descriptor is valid (i.e. hasn't been closed).
221 * If true, return 1. Otherwise, raise ValueError and return 0.
222 */
_is_fd_valid(int fd)223 static int _is_fd_valid(int fd)
224 {
225 /* the FD is set to -1 in oss_close()/oss_mixer_close() */
226 if (fd >= 0) {
227 return 1;
228 } else {
229 PyErr_SetString(PyExc_ValueError,
230 "Operation on closed OSS device.");
231 return 0;
232 }
233 }
234
235 /* _do_ioctl_1() is a private helper function used for the OSS ioctls --
236 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that are called from C
237 like this:
238 ioctl(fd, SNDCTL_DSP_cmd, &arg)
239
240 where arg is the value to set, and on return the driver sets arg to
241 the value that was actually set. Mapping this to Python is obvious:
242 arg = dsp.xxx(arg)
243 */
244 static PyObject *
_do_ioctl_1(int fd,PyObject * args,char * fname,unsigned long cmd)245 _do_ioctl_1(int fd, PyObject *args, char *fname, unsigned long cmd)
246 {
247 char argfmt[33] = "i:";
248 int arg;
249
250 assert(strlen(fname) <= 30);
251 strncat(argfmt, fname, 30);
252 if (!PyArg_ParseTuple(args, argfmt, &arg))
253 return NULL;
254
255 if (ioctl(fd, cmd, &arg) == -1)
256 return PyErr_SetFromErrno(PyExc_OSError);
257 return PyLong_FromLong(arg);
258 }
259
260
261 /* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
262 but return an output -- ie. we need to pass a pointer to a local C
263 variable so the driver can write its output there, but from Python
264 all we see is the return value. For example,
265 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
266 devices, but does not use the value of the parameter passed-in in any
267 way.
268 */
269 static PyObject *
_do_ioctl_1_internal(int fd,PyObject * args,char * fname,unsigned long cmd)270 _do_ioctl_1_internal(int fd, PyObject *args, char *fname, unsigned long cmd)
271 {
272 char argfmt[32] = ":";
273 int arg = 0;
274
275 assert(strlen(fname) <= 30);
276 strncat(argfmt, fname, 30);
277 if (!PyArg_ParseTuple(args, argfmt, &arg))
278 return NULL;
279
280 if (ioctl(fd, cmd, &arg) == -1)
281 return PyErr_SetFromErrno(PyExc_OSError);
282 return PyLong_FromLong(arg);
283 }
284
285
286
287 /* _do_ioctl_0() is a private helper for the no-argument ioctls:
288 SNDCTL_DSP_{SYNC,RESET,POST}. */
289 static PyObject *
_do_ioctl_0(int fd,PyObject * args,char * fname,unsigned long cmd)290 _do_ioctl_0(int fd, PyObject *args, char *fname, unsigned long cmd)
291 {
292 char argfmt[32] = ":";
293 int rv;
294
295 assert(strlen(fname) <= 30);
296 strncat(argfmt, fname, 30);
297 if (!PyArg_ParseTuple(args, argfmt))
298 return NULL;
299
300 /* According to hannu@opensound.com, all three of the ioctls that
301 use this function can block, so release the GIL. This is
302 especially important for SYNC, which can block for several
303 seconds. */
304 Py_BEGIN_ALLOW_THREADS
305 rv = ioctl(fd, cmd, 0);
306 Py_END_ALLOW_THREADS
307
308 if (rv == -1)
309 return PyErr_SetFromErrno(PyExc_OSError);
310 Py_RETURN_NONE;
311 }
312
313
314 /* ----------------------------------------------------------------------
315 * Methods of DSP objects (OSSAudioType)
316 */
317
318 static PyObject *
oss_nonblock(oss_audio_t * self,PyObject * unused)319 oss_nonblock(oss_audio_t *self, PyObject *unused)
320 {
321 if (!_is_fd_valid(self->fd))
322 return NULL;
323
324 /* Hmmm: it doesn't appear to be possible to return to blocking
325 mode once we're in non-blocking mode! */
326 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
327 return PyErr_SetFromErrno(PyExc_OSError);
328 Py_RETURN_NONE;
329 }
330
331 static PyObject *
oss_setfmt(oss_audio_t * self,PyObject * args)332 oss_setfmt(oss_audio_t *self, PyObject *args)
333 {
334 if (!_is_fd_valid(self->fd))
335 return NULL;
336
337 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
338 }
339
340 static PyObject *
oss_getfmts(oss_audio_t * self,PyObject * unused)341 oss_getfmts(oss_audio_t *self, PyObject *unused)
342 {
343 int mask;
344
345 if (!_is_fd_valid(self->fd))
346 return NULL;
347
348 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
349 return PyErr_SetFromErrno(PyExc_OSError);
350 return PyLong_FromLong(mask);
351 }
352
353 static PyObject *
oss_channels(oss_audio_t * self,PyObject * args)354 oss_channels(oss_audio_t *self, PyObject *args)
355 {
356 if (!_is_fd_valid(self->fd))
357 return NULL;
358
359 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
360 }
361
362 static PyObject *
oss_speed(oss_audio_t * self,PyObject * args)363 oss_speed(oss_audio_t *self, PyObject *args)
364 {
365 if (!_is_fd_valid(self->fd))
366 return NULL;
367
368 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
369 }
370
371 static PyObject *
oss_sync(oss_audio_t * self,PyObject * args)372 oss_sync(oss_audio_t *self, PyObject *args)
373 {
374 if (!_is_fd_valid(self->fd))
375 return NULL;
376
377 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
378 }
379
380 static PyObject *
oss_reset(oss_audio_t * self,PyObject * args)381 oss_reset(oss_audio_t *self, PyObject *args)
382 {
383 if (!_is_fd_valid(self->fd))
384 return NULL;
385
386 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
387 }
388
389 static PyObject *
oss_post(oss_audio_t * self,PyObject * args)390 oss_post(oss_audio_t *self, PyObject *args)
391 {
392 if (!_is_fd_valid(self->fd))
393 return NULL;
394
395 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
396 }
397
398
399 /* Regular file methods: read(), write(), close(), etc. as well
400 as one convenience method, writeall(). */
401
402 static PyObject *
oss_read(oss_audio_t * self,PyObject * args)403 oss_read(oss_audio_t *self, PyObject *args)
404 {
405 Py_ssize_t size, count;
406 PyObject *rv;
407
408 if (!_is_fd_valid(self->fd))
409 return NULL;
410
411 if (!PyArg_ParseTuple(args, "n:read", &size))
412 return NULL;
413
414 rv = PyBytes_FromStringAndSize(NULL, size);
415 if (rv == NULL)
416 return NULL;
417
418 count = _Py_read(self->fd, PyBytes_AS_STRING(rv), size);
419 if (count == -1) {
420 Py_DECREF(rv);
421 return NULL;
422 }
423
424 self->icount += count;
425 _PyBytes_Resize(&rv, count);
426 return rv;
427 }
428
429 static PyObject *
oss_write(oss_audio_t * self,PyObject * args)430 oss_write(oss_audio_t *self, PyObject *args)
431 {
432 Py_buffer data;
433 Py_ssize_t rv;
434
435 if (!_is_fd_valid(self->fd))
436 return NULL;
437
438 if (!PyArg_ParseTuple(args, "y*:write", &data)) {
439 return NULL;
440 }
441
442 rv = _Py_write(self->fd, data.buf, data.len);
443 PyBuffer_Release(&data);
444 if (rv == -1)
445 return NULL;
446
447 self->ocount += rv;
448 return PyLong_FromLong(rv);
449 }
450
451 static PyObject *
oss_writeall(oss_audio_t * self,PyObject * args)452 oss_writeall(oss_audio_t *self, PyObject *args)
453 {
454 Py_buffer data;
455 const char *cp;
456 Py_ssize_t size;
457 Py_ssize_t rv;
458 fd_set write_set_fds;
459 int select_rv;
460
461 /* NB. writeall() is only useful in non-blocking mode: according to
462 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
463 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
464 write() in blocking mode consumes the whole buffer. In blocking
465 mode, the behaviour of write() and writeall() from Python is
466 indistinguishable. */
467
468 if (!_is_fd_valid(self->fd))
469 return NULL;
470
471 if (!PyArg_ParseTuple(args, "y*:writeall", &data))
472 return NULL;
473
474 if (!_PyIsSelectable_fd(self->fd)) {
475 PyErr_SetString(PyExc_ValueError,
476 "file descriptor out of range for select");
477 PyBuffer_Release(&data);
478 return NULL;
479 }
480 /* use select to wait for audio device to be available */
481 FD_ZERO(&write_set_fds);
482 FD_SET(self->fd, &write_set_fds);
483 cp = (const char *)data.buf;
484 size = data.len;
485
486 while (size > 0) {
487 Py_BEGIN_ALLOW_THREADS
488 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
489 Py_END_ALLOW_THREADS
490
491 assert(select_rv != 0); /* no timeout, can't expire */
492 if (select_rv == -1) {
493 PyBuffer_Release(&data);
494 return PyErr_SetFromErrno(PyExc_OSError);
495 }
496
497 rv = _Py_write(self->fd, cp, Py_MIN(size, INT_MAX));
498 if (rv == -1) {
499 /* buffer is full, try again */
500 if (errno == EAGAIN) {
501 PyErr_Clear();
502 continue;
503 }
504 /* it's a real error */
505 PyBuffer_Release(&data);
506 return NULL;
507 }
508
509 /* wrote rv bytes */
510 self->ocount += rv;
511 size -= rv;
512 cp += rv;
513 }
514 PyBuffer_Release(&data);
515 Py_RETURN_NONE;
516 }
517
518 static PyObject *
oss_close(oss_audio_t * self,PyObject * unused)519 oss_close(oss_audio_t *self, PyObject *unused)
520 {
521 if (self->fd >= 0) {
522 Py_BEGIN_ALLOW_THREADS
523 close(self->fd);
524 Py_END_ALLOW_THREADS
525 self->fd = -1;
526 }
527 Py_RETURN_NONE;
528 }
529
530 static PyObject *
oss_self(PyObject * self,PyObject * unused)531 oss_self(PyObject *self, PyObject *unused)
532 {
533 Py_INCREF(self);
534 return self;
535 }
536
537 static PyObject *
oss_exit(PyObject * self,PyObject * unused)538 oss_exit(PyObject *self, PyObject *unused)
539 {
540 _Py_IDENTIFIER(close);
541
542 PyObject *ret = _PyObject_CallMethodId(self, &PyId_close, NULL);
543 if (!ret)
544 return NULL;
545 Py_DECREF(ret);
546 Py_RETURN_NONE;
547 }
548
549 static PyObject *
oss_fileno(oss_audio_t * self,PyObject * unused)550 oss_fileno(oss_audio_t *self, PyObject *unused)
551 {
552 if (!_is_fd_valid(self->fd))
553 return NULL;
554
555 return PyLong_FromLong(self->fd);
556 }
557
558
559 /* Convenience methods: these generally wrap a couple of ioctls into one
560 common task. */
561
562 static PyObject *
oss_setparameters(oss_audio_t * self,PyObject * args)563 oss_setparameters(oss_audio_t *self, PyObject *args)
564 {
565 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
566 int fmt, channels, rate;
567
568 if (!_is_fd_valid(self->fd))
569 return NULL;
570
571 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
572 &wanted_fmt, &wanted_channels, &wanted_rate,
573 &strict))
574 return NULL;
575
576 fmt = wanted_fmt;
577 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
578 return PyErr_SetFromErrno(PyExc_OSError);
579 }
580 if (strict && fmt != wanted_fmt) {
581 return PyErr_Format
582 (OSSAudioError,
583 "unable to set requested format (wanted %d, got %d)",
584 wanted_fmt, fmt);
585 }
586
587 channels = wanted_channels;
588 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
589 return PyErr_SetFromErrno(PyExc_OSError);
590 }
591 if (strict && channels != wanted_channels) {
592 return PyErr_Format
593 (OSSAudioError,
594 "unable to set requested channels (wanted %d, got %d)",
595 wanted_channels, channels);
596 }
597
598 rate = wanted_rate;
599 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
600 return PyErr_SetFromErrno(PyExc_OSError);
601 }
602 if (strict && rate != wanted_rate) {
603 return PyErr_Format
604 (OSSAudioError,
605 "unable to set requested rate (wanted %d, got %d)",
606 wanted_rate, rate);
607 }
608
609 /* Construct the return value: a (fmt, channels, rate) tuple that
610 tells what the audio hardware was actually set to. */
611 return Py_BuildValue("(iii)", fmt, channels, rate);
612 }
613
614 static int
_ssize(oss_audio_t * self,int * nchannels,int * ssize)615 _ssize(oss_audio_t *self, int *nchannels, int *ssize)
616 {
617 int fmt;
618
619 fmt = 0;
620 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
621 return -errno;
622
623 switch (fmt) {
624 case AFMT_MU_LAW:
625 case AFMT_A_LAW:
626 case AFMT_U8:
627 case AFMT_S8:
628 *ssize = 1; /* 8 bit formats: 1 byte */
629 break;
630 case AFMT_S16_LE:
631 case AFMT_S16_BE:
632 case AFMT_U16_LE:
633 case AFMT_U16_BE:
634 *ssize = 2; /* 16 bit formats: 2 byte */
635 break;
636 case AFMT_MPEG:
637 case AFMT_IMA_ADPCM:
638 default:
639 return -EOPNOTSUPP;
640 }
641 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
642 return -errno;
643 return 0;
644 }
645
646
647 /* bufsize returns the size of the hardware audio buffer in number
648 of samples */
649 static PyObject *
oss_bufsize(oss_audio_t * self,PyObject * unused)650 oss_bufsize(oss_audio_t *self, PyObject *unused)
651 {
652 audio_buf_info ai;
653 int nchannels=0, ssize=0;
654
655 if (!_is_fd_valid(self->fd))
656 return NULL;
657
658 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
659 PyErr_SetFromErrno(PyExc_OSError);
660 return NULL;
661 }
662 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
663 PyErr_SetFromErrno(PyExc_OSError);
664 return NULL;
665 }
666 return PyLong_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
667 }
668
669 /* obufcount returns the number of samples that are available in the
670 hardware for playing */
671 static PyObject *
oss_obufcount(oss_audio_t * self,PyObject * unused)672 oss_obufcount(oss_audio_t *self, PyObject *unused)
673 {
674 audio_buf_info ai;
675 int nchannels=0, ssize=0;
676
677 if (!_is_fd_valid(self->fd))
678 return NULL;
679
680 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
681 PyErr_SetFromErrno(PyExc_OSError);
682 return NULL;
683 }
684 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
685 PyErr_SetFromErrno(PyExc_OSError);
686 return NULL;
687 }
688 return PyLong_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
689 (ssize * nchannels));
690 }
691
692 /* obufcount returns the number of samples that can be played without
693 blocking */
694 static PyObject *
oss_obuffree(oss_audio_t * self,PyObject * unused)695 oss_obuffree(oss_audio_t *self, PyObject *unused)
696 {
697 audio_buf_info ai;
698 int nchannels=0, ssize=0;
699
700 if (!_is_fd_valid(self->fd))
701 return NULL;
702
703 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
704 PyErr_SetFromErrno(PyExc_OSError);
705 return NULL;
706 }
707 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
708 PyErr_SetFromErrno(PyExc_OSError);
709 return NULL;
710 }
711 return PyLong_FromLong(ai.bytes / (ssize * nchannels));
712 }
713
714 static PyObject *
oss_getptr(oss_audio_t * self,PyObject * unused)715 oss_getptr(oss_audio_t *self, PyObject *unused)
716 {
717 count_info info;
718 int req;
719
720 if (!_is_fd_valid(self->fd))
721 return NULL;
722
723 if (self->mode == O_RDONLY)
724 req = SNDCTL_DSP_GETIPTR;
725 else
726 req = SNDCTL_DSP_GETOPTR;
727 if (ioctl(self->fd, req, &info) == -1) {
728 PyErr_SetFromErrno(PyExc_OSError);
729 return NULL;
730 }
731 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
732 }
733
734
735 /* ----------------------------------------------------------------------
736 * Methods of mixer objects (OSSMixerType)
737 */
738
739 static PyObject *
oss_mixer_close(oss_mixer_t * self,PyObject * unused)740 oss_mixer_close(oss_mixer_t *self, PyObject *unused)
741 {
742 if (self->fd >= 0) {
743 close(self->fd);
744 self->fd = -1;
745 }
746 Py_RETURN_NONE;
747 }
748
749 static PyObject *
oss_mixer_fileno(oss_mixer_t * self,PyObject * unused)750 oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
751 {
752 if (!_is_fd_valid(self->fd))
753 return NULL;
754
755 return PyLong_FromLong(self->fd);
756 }
757
758 /* Simple mixer interface methods */
759
760 static PyObject *
oss_mixer_controls(oss_mixer_t * self,PyObject * args)761 oss_mixer_controls(oss_mixer_t *self, PyObject *args)
762 {
763 if (!_is_fd_valid(self->fd))
764 return NULL;
765
766 return _do_ioctl_1_internal(self->fd, args, "controls",
767 SOUND_MIXER_READ_DEVMASK);
768 }
769
770 static PyObject *
oss_mixer_stereocontrols(oss_mixer_t * self,PyObject * args)771 oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
772 {
773 if (!_is_fd_valid(self->fd))
774 return NULL;
775
776 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
777 SOUND_MIXER_READ_STEREODEVS);
778 }
779
780 static PyObject *
oss_mixer_reccontrols(oss_mixer_t * self,PyObject * args)781 oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
782 {
783 if (!_is_fd_valid(self->fd))
784 return NULL;
785
786 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
787 SOUND_MIXER_READ_RECMASK);
788 }
789
790 static PyObject *
oss_mixer_get(oss_mixer_t * self,PyObject * args)791 oss_mixer_get(oss_mixer_t *self, PyObject *args)
792 {
793 int channel, volume;
794
795 if (!_is_fd_valid(self->fd))
796 return NULL;
797
798 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
799 if (!PyArg_ParseTuple(args, "i:get", &channel))
800 return NULL;
801
802 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
803 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
804 return NULL;
805 }
806
807 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
808 return PyErr_SetFromErrno(PyExc_OSError);
809
810 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
811 }
812
813 static PyObject *
oss_mixer_set(oss_mixer_t * self,PyObject * args)814 oss_mixer_set(oss_mixer_t *self, PyObject *args)
815 {
816 int channel, volume, leftVol, rightVol;
817
818 if (!_is_fd_valid(self->fd))
819 return NULL;
820
821 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
822 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
823 return NULL;
824
825 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
826 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
827 return NULL;
828 }
829
830 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
831 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
832 return NULL;
833 }
834
835 volume = (rightVol << 8) | leftVol;
836
837 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
838 return PyErr_SetFromErrno(PyExc_OSError);
839
840 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
841 }
842
843 static PyObject *
oss_mixer_get_recsrc(oss_mixer_t * self,PyObject * args)844 oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
845 {
846 if (!_is_fd_valid(self->fd))
847 return NULL;
848
849 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
850 SOUND_MIXER_READ_RECSRC);
851 }
852
853 static PyObject *
oss_mixer_set_recsrc(oss_mixer_t * self,PyObject * args)854 oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
855 {
856 if (!_is_fd_valid(self->fd))
857 return NULL;
858
859 return _do_ioctl_1(self->fd, args, "set_recsrc",
860 SOUND_MIXER_WRITE_RECSRC);
861 }
862
863
864 /* ----------------------------------------------------------------------
865 * Method tables and other bureaucracy
866 */
867
868 static PyMethodDef oss_methods[] = {
869 /* Regular file methods */
870 { "read", (PyCFunction)oss_read, METH_VARARGS },
871 { "write", (PyCFunction)oss_write, METH_VARARGS },
872 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
873 { "close", (PyCFunction)oss_close, METH_NOARGS },
874 { "fileno", (PyCFunction)oss_fileno, METH_NOARGS },
875
876 /* Simple ioctl wrappers */
877 { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS },
878 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
879 { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS },
880 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
881 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
882 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
883 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
884 { "post", (PyCFunction)oss_post, METH_VARARGS },
885
886 /* Convenience methods -- wrap a couple of ioctls together */
887 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
888 { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS },
889 { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS },
890 { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS },
891 { "getptr", (PyCFunction)oss_getptr, METH_NOARGS },
892
893 /* Aliases for backwards compatibility */
894 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
895
896 /* Support for the context management protocol */
897 { "__enter__", oss_self, METH_NOARGS },
898 { "__exit__", oss_exit, METH_VARARGS },
899
900 { NULL, NULL} /* sentinel */
901 };
902
903 static PyMethodDef oss_mixer_methods[] = {
904 /* Regular file method - OSS mixers are ioctl-only interface */
905 { "close", (PyCFunction)oss_mixer_close, METH_NOARGS },
906 { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS },
907
908 /* Support for the context management protocol */
909 { "__enter__", oss_self, METH_NOARGS },
910 { "__exit__", oss_exit, METH_VARARGS },
911
912 /* Simple ioctl wrappers */
913 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
914 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
915 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
916 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
917 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
918 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
919 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
920
921 { NULL, NULL}
922 };
923
924 static PyMemberDef oss_members[] = {
925 {"name", T_STRING, offsetof(oss_audio_t, devicename), READONLY, NULL},
926 {NULL}
927 };
928
929 static PyObject *
oss_closed_getter(oss_audio_t * self,void * closure)930 oss_closed_getter(oss_audio_t *self, void *closure)
931 {
932 return PyBool_FromLong(self->fd == -1);
933 }
934
935 static PyObject *
oss_mode_getter(oss_audio_t * self,void * closure)936 oss_mode_getter(oss_audio_t *self, void *closure)
937 {
938 switch(self->mode) {
939 case O_RDONLY:
940 return PyUnicode_FromString("r");
941 break;
942 case O_RDWR:
943 return PyUnicode_FromString("rw");
944 break;
945 case O_WRONLY:
946 return PyUnicode_FromString("w");
947 break;
948 default:
949 /* From newossobject(), self->mode can only be one
950 of these three values. */
951 Py_UNREACHABLE();
952 }
953 }
954
955 static PyGetSetDef oss_getsetlist[] = {
956 {"closed", (getter)oss_closed_getter, (setter)NULL, NULL},
957 {"mode", (getter)oss_mode_getter, (setter)NULL, NULL},
958 {NULL},
959 };
960
961 static PyTypeObject OSSAudioType = {
962 PyVarObject_HEAD_INIT(&PyType_Type, 0)
963 "ossaudiodev.oss_audio_device", /*tp_name*/
964 sizeof(oss_audio_t), /*tp_basicsize*/
965 0, /*tp_itemsize*/
966 /* methods */
967 (destructor)oss_dealloc, /*tp_dealloc*/
968 0, /*tp_vectorcall_offset*/
969 0, /*tp_getattr*/
970 0, /*tp_setattr*/
971 0, /*tp_as_async*/
972 0, /*tp_repr*/
973 0, /*tp_as_number*/
974 0, /*tp_as_sequence*/
975 0, /*tp_as_mapping*/
976 0, /*tp_hash*/
977 0, /*tp_call*/
978 0, /*tp_str*/
979 0, /*tp_getattro*/
980 0, /*tp_setattro*/
981 0, /*tp_as_buffer*/
982 Py_TPFLAGS_DEFAULT, /*tp_flags*/
983 0, /*tp_doc*/
984 0, /*tp_traverse*/
985 0, /*tp_clear*/
986 0, /*tp_richcompare*/
987 0, /*tp_weaklistoffset*/
988 0, /*tp_iter*/
989 0, /*tp_iternext*/
990 oss_methods, /*tp_methods*/
991 oss_members, /*tp_members*/
992 oss_getsetlist, /*tp_getset*/
993 };
994
995 static PyTypeObject OSSMixerType = {
996 PyVarObject_HEAD_INIT(&PyType_Type, 0)
997 "ossaudiodev.oss_mixer_device", /*tp_name*/
998 sizeof(oss_mixer_t), /*tp_basicsize*/
999 0, /*tp_itemsize*/
1000 /* methods */
1001 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
1002 0, /*tp_vectorcall_offset*/
1003 0, /*tp_getattr*/
1004 0, /*tp_setattr*/
1005 0, /*tp_as_async*/
1006 0, /*tp_repr*/
1007 0, /*tp_as_number*/
1008 0, /*tp_as_sequence*/
1009 0, /*tp_as_mapping*/
1010 0, /*tp_hash*/
1011 0, /*tp_call*/
1012 0, /*tp_str*/
1013 0, /*tp_getattro*/
1014 0, /*tp_setattro*/
1015 0, /*tp_as_buffer*/
1016 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1017 0, /*tp_doc*/
1018 0, /*tp_traverse*/
1019 0, /*tp_clear*/
1020 0, /*tp_richcompare*/
1021 0, /*tp_weaklistoffset*/
1022 0, /*tp_iter*/
1023 0, /*tp_iternext*/
1024 oss_mixer_methods, /*tp_methods*/
1025 };
1026
1027
1028 static PyObject *
ossopen(PyObject * self,PyObject * args)1029 ossopen(PyObject *self, PyObject *args)
1030 {
1031 return (PyObject *)newossobject(args);
1032 }
1033
1034 static PyObject *
ossopenmixer(PyObject * self,PyObject * args)1035 ossopenmixer(PyObject *self, PyObject *args)
1036 {
1037 return (PyObject *)newossmixerobject(args);
1038 }
1039
1040 static PyMethodDef ossaudiodev_methods[] = {
1041 { "open", ossopen, METH_VARARGS },
1042 { "openmixer", ossopenmixer, METH_VARARGS },
1043 { 0, 0 },
1044 };
1045
1046
1047 #define _EXPORT_INT(mod, name) \
1048 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return NULL;
1049
1050
1051 static char *control_labels[] = SOUND_DEVICE_LABELS;
1052 static char *control_names[] = SOUND_DEVICE_NAMES;
1053
1054
1055 static int
build_namelists(PyObject * module)1056 build_namelists (PyObject *module)
1057 {
1058 PyObject *labels;
1059 PyObject *names;
1060 PyObject *s;
1061 int num_controls;
1062 int i;
1063
1064 num_controls = Py_ARRAY_LENGTH(control_labels);
1065 assert(num_controls == Py_ARRAY_LENGTH(control_names));
1066
1067 labels = PyList_New(num_controls);
1068 names = PyList_New(num_controls);
1069 if (labels == NULL || names == NULL)
1070 goto error2;
1071 for (i = 0; i < num_controls; i++) {
1072 s = PyUnicode_FromString(control_labels[i]);
1073 if (s == NULL)
1074 goto error2;
1075 PyList_SET_ITEM(labels, i, s);
1076
1077 s = PyUnicode_FromString(control_names[i]);
1078 if (s == NULL)
1079 goto error2;
1080 PyList_SET_ITEM(names, i, s);
1081 }
1082
1083 if (PyModule_AddObject(module, "control_labels", labels) == -1)
1084 goto error2;
1085 if (PyModule_AddObject(module, "control_names", names) == -1)
1086 goto error1;
1087
1088 return 0;
1089
1090 error2:
1091 Py_XDECREF(labels);
1092 error1:
1093 Py_XDECREF(names);
1094 return -1;
1095 }
1096
1097
1098 static struct PyModuleDef ossaudiodevmodule = {
1099 PyModuleDef_HEAD_INIT,
1100 "ossaudiodev",
1101 NULL,
1102 -1,
1103 ossaudiodev_methods,
1104 NULL,
1105 NULL,
1106 NULL,
1107 NULL
1108 };
1109
1110 PyMODINIT_FUNC
PyInit_ossaudiodev(void)1111 PyInit_ossaudiodev(void)
1112 {
1113 PyObject *m;
1114
1115 if (PyType_Ready(&OSSAudioType) < 0)
1116 return NULL;
1117
1118 if (PyType_Ready(&OSSMixerType) < 0)
1119 return NULL;
1120
1121 m = PyModule_Create(&ossaudiodevmodule);
1122 if (m == NULL)
1123 return NULL;
1124
1125 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
1126 NULL, NULL);
1127 if (OSSAudioError) {
1128 /* Each call to PyModule_AddObject decrefs it; compensate: */
1129 Py_INCREF(OSSAudioError);
1130 Py_INCREF(OSSAudioError);
1131 PyModule_AddObject(m, "error", OSSAudioError);
1132 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
1133 }
1134
1135 /* Build 'control_labels' and 'control_names' lists and add them
1136 to the module. */
1137 if (build_namelists(m) == -1) /* XXX what to do here? */
1138 return NULL;
1139
1140 /* Expose the audio format numbers -- essential! */
1141 _EXPORT_INT(m, AFMT_QUERY);
1142 _EXPORT_INT(m, AFMT_MU_LAW);
1143 _EXPORT_INT(m, AFMT_A_LAW);
1144 _EXPORT_INT(m, AFMT_IMA_ADPCM);
1145 _EXPORT_INT(m, AFMT_U8);
1146 _EXPORT_INT(m, AFMT_S16_LE);
1147 _EXPORT_INT(m, AFMT_S16_BE);
1148 _EXPORT_INT(m, AFMT_S8);
1149 _EXPORT_INT(m, AFMT_U16_LE);
1150 _EXPORT_INT(m, AFMT_U16_BE);
1151 _EXPORT_INT(m, AFMT_MPEG);
1152 #ifdef AFMT_AC3
1153 _EXPORT_INT(m, AFMT_AC3);
1154 #endif
1155 #ifdef AFMT_S16_NE
1156 _EXPORT_INT(m, AFMT_S16_NE);
1157 #endif
1158 #ifdef AFMT_U16_NE
1159 _EXPORT_INT(m, AFMT_U16_NE);
1160 #endif
1161 #ifdef AFMT_S32_LE
1162 _EXPORT_INT(m, AFMT_S32_LE);
1163 #endif
1164 #ifdef AFMT_S32_BE
1165 _EXPORT_INT(m, AFMT_S32_BE);
1166 #endif
1167 #ifdef AFMT_MPEG
1168 _EXPORT_INT(m, AFMT_MPEG);
1169 #endif
1170
1171 /* Expose the sound mixer device numbers. */
1172 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
1173 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1174 _EXPORT_INT(m, SOUND_MIXER_BASS);
1175 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1176 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1177 _EXPORT_INT(m, SOUND_MIXER_PCM);
1178 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1179 _EXPORT_INT(m, SOUND_MIXER_LINE);
1180 _EXPORT_INT(m, SOUND_MIXER_MIC);
1181 _EXPORT_INT(m, SOUND_MIXER_CD);
1182 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1183 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1184 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1185 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1186 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1187 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1188 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1189 _EXPORT_INT(m, SOUND_MIXER_LINE3);
1190 #ifdef SOUND_MIXER_DIGITAL1
1191 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
1192 #endif
1193 #ifdef SOUND_MIXER_DIGITAL2
1194 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
1195 #endif
1196 #ifdef SOUND_MIXER_DIGITAL3
1197 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
1198 #endif
1199 #ifdef SOUND_MIXER_PHONEIN
1200 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
1201 #endif
1202 #ifdef SOUND_MIXER_PHONEOUT
1203 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
1204 #endif
1205 #ifdef SOUND_MIXER_VIDEO
1206 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
1207 #endif
1208 #ifdef SOUND_MIXER_RADIO
1209 _EXPORT_INT(m, SOUND_MIXER_RADIO);
1210 #endif
1211 #ifdef SOUND_MIXER_MONITOR
1212 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
1213 #endif
1214
1215 /* Expose all the ioctl numbers for masochists who like to do this
1216 stuff directly. */
1217 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1218 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1219 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1220 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1221 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1222 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1223 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1224 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1225 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1226 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
1227 #ifdef SNDCTL_DSP_BIND_CHANNEL
1228 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
1229 #endif
1230 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1231 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1232 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
1233 #ifdef SNDCTL_DSP_GETCHANNELMASK
1234 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
1235 #endif
1236 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1237 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1238 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
1239 #ifdef SNDCTL_DSP_GETODELAY
1240 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
1241 #endif
1242 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1243 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
1244 #ifdef SNDCTL_DSP_GETSPDIF
1245 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
1246 #endif
1247 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1248 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1249 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1250 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1251 _EXPORT_INT(m, SNDCTL_DSP_POST);
1252 #ifdef SNDCTL_DSP_PROFILE
1253 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
1254 #endif
1255 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1256 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1257 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1258 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1259 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
1260 #ifdef SNDCTL_DSP_SETSPDIF
1261 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
1262 #endif
1263 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1264 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1265 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1266 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1267 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1268 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1269 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1270 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1271 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1272 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1273 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1274 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1275 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1276 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1277 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
1278 #ifdef SNDCTL_SEQ_GETTIME
1279 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
1280 #endif
1281 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1282 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1283 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1284 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1285 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1286 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1287 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1288 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1289 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1290 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
1291 #ifdef SNDCTL_SYNTH_CONTROL
1292 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
1293 #endif
1294 #ifdef SNDCTL_SYNTH_ID
1295 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
1296 #endif
1297 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1298 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
1299 #ifdef SNDCTL_SYNTH_REMOVESAMPLE
1300 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
1301 #endif
1302 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1303 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1304 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1305 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1306 _EXPORT_INT(m, SNDCTL_TMR_START);
1307 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1308 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1309 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
1310 return m;
1311 }
1312