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