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