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. |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 12 | * |
| 13 | * (c) 2000 Peter Bosch. All Rights Reserved. |
| 14 | * (c) 2002 Gregory P. Ward. All Rights Reserved. |
| 15 | * (c) 2002 Python Software Foundation. All Rights Reserved. |
| 16 | * |
| 17 | * XXX need a license statement |
| 18 | * |
| 19 | * $Id$ |
| 20 | */ |
| 21 | |
| 22 | #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 | |
| 37 | typedef unsigned long uint32_t; |
| 38 | |
| 39 | #elif defined(__FreeBSD__) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 40 | |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 41 | # ifndef SNDCTL_DSP_CHANNELS |
| 42 | # define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS |
| 43 | # endif |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 44 | |
| 45 | #endif |
| 46 | |
| 47 | typedef struct { |
| 48 | PyObject_HEAD; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 49 | int fd; /* The open file */ |
| 50 | int mode; /* file mode */ |
| 51 | int icount; /* Input count */ |
| 52 | int ocount; /* Output count */ |
| 53 | uint32_t afmts; /* Audio formats supported by hardware */ |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 54 | } oss_audio_t; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 55 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 56 | typedef struct { |
| 57 | PyObject_HEAD; |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 58 | int fd; /* The open mixer device */ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 59 | } oss_mixer_t; |
| 60 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 61 | /* XXX several format defined in soundcard.h are not supported, |
| 62 | including _NE (native endian) options and S32 options |
| 63 | */ |
| 64 | |
| 65 | static struct { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 66 | int a_bps; |
| 67 | uint32_t a_fmt; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 68 | char *a_name; |
| 69 | } audio_types[] = { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 70 | { 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" }, |
| 71 | { 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" }, |
| 72 | { 8, AFMT_U8, "linear unsigned 8-bit audio" }, |
| 73 | { 8, AFMT_S8, "linear signed 8-bit audio" }, |
| 74 | { 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" }, |
| 75 | { 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" }, |
| 76 | { 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" }, |
| 77 | { 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" }, |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 78 | #ifdef AFMT_S16_NE |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 79 | { 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" }, |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 80 | #endif |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]); |
| 84 | |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 85 | static PyTypeObject OSSAudioType; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 86 | static PyTypeObject OSSMixerType; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 87 | |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 88 | static PyObject *OSSAudioError; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 89 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 90 | |
| 91 | /* ---------------------------------------------------------------------- |
| 92 | * DSP object initialization/deallocation |
| 93 | */ |
| 94 | |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 95 | static oss_audio_t * |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 96 | newossobject(PyObject *arg) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 97 | { |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 98 | oss_audio_t *self; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 99 | int fd, afmts, imode; |
| 100 | char *basedev = NULL; |
| 101 | char *mode = NULL; |
| 102 | |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 103 | /* Two ways to call open(): |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 104 | open(device, mode) (for consistency with builtin open()) |
| 105 | open(mode) (for backwards compatibility) |
| 106 | because the *first* argument is optional, parsing args is |
| 107 | a wee bit tricky. */ |
| 108 | if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode)) |
| 109 | return NULL; |
| 110 | if (mode == NULL) { /* only one arg supplied */ |
| 111 | mode = basedev; |
| 112 | basedev = NULL; |
| 113 | } |
| 114 | |
| 115 | if (strcmp(mode, "r") == 0) |
| 116 | imode = O_RDONLY; |
| 117 | else if (strcmp(mode, "w") == 0) |
| 118 | imode = O_WRONLY; |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 119 | else if (strcmp(mode, "rw") == 0) |
| 120 | imode = O_RDWR; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 121 | else { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 122 | PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'"); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 123 | return NULL; |
| 124 | } |
| 125 | |
Greg Ward | 5c5c577 | 2002-12-30 02:58:04 +0000 | [diff] [blame] | 126 | /* Open the correct device: either the 'device' argument, |
| 127 | or the AUDIODEV environment variable, or "/dev/dsp". */ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 128 | if (basedev == NULL) { /* called with one arg */ |
| 129 | basedev = getenv("AUDIODEV"); |
| 130 | if (basedev == NULL) /* $AUDIODEV not set */ |
| 131 | basedev = "/dev/dsp"; |
| 132 | } |
| 133 | |
Greg Ward | 5c49ef2 | 2003-03-11 16:53:13 +0000 | [diff] [blame] | 134 | /* Open with O_NONBLOCK to avoid hanging on devices that only allow |
| 135 | one open at a time. This does *not* affect later I/O; OSS |
| 136 | provides a special ioctl() for non-blocking read/write, which is |
| 137 | exposed via oss_nonblock() below. */ |
| 138 | if ((fd = open(basedev, imode|O_NONBLOCK)) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 139 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 140 | return NULL; |
| 141 | } |
Greg Ward | 76ffb19 | 2003-04-04 01:47:42 +0000 | [diff] [blame] | 142 | |
| 143 | /* And (try to) put it back in blocking mode so we get the |
| 144 | expected write() semantics. */ |
| 145 | if (fcntl(fd, F_SETFL, 0) == -1) { |
| 146 | close(fd); |
| 147 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev); |
| 148 | return NULL; |
| 149 | } |
| 150 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 151 | if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 152 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 153 | return NULL; |
| 154 | } |
| 155 | /* Create and initialize the object */ |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 156 | if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) { |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 157 | close(fd); |
| 158 | return NULL; |
| 159 | } |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 160 | self->fd = fd; |
| 161 | self->mode = imode; |
| 162 | self->icount = self->ocount = 0; |
| 163 | self->afmts = afmts; |
| 164 | return self; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static void |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 168 | oss_dealloc(oss_audio_t *self) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 169 | { |
| 170 | /* if already closed, don't reclose it */ |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 171 | if (self->fd != -1) |
| 172 | close(self->fd); |
| 173 | PyObject_Del(self); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 176 | |
| 177 | /* ---------------------------------------------------------------------- |
| 178 | * Mixer object initialization/deallocation |
| 179 | */ |
| 180 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 181 | static oss_mixer_t * |
| 182 | newossmixerobject(PyObject *arg) |
| 183 | { |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 184 | char *basedev = NULL; |
| 185 | int fd; |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 186 | oss_mixer_t *self; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 187 | |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 188 | if (!PyArg_ParseTuple(arg, "|s", &basedev)) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 189 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | if (basedev == NULL) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 193 | basedev = getenv("MIXERDEV"); |
| 194 | if (basedev == NULL) /* MIXERDEV not set */ |
| 195 | basedev = "/dev/mixer"; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 198 | if ((fd = open(basedev, O_RDWR)) == -1) { |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 199 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev); |
| 200 | return NULL; |
| 201 | } |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 202 | |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 203 | if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) { |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 204 | close(fd); |
| 205 | return NULL; |
| 206 | } |
| 207 | |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 208 | self->fd = fd; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 209 | |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 210 | return self; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static void |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 214 | oss_mixer_dealloc(oss_mixer_t *self) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 215 | { |
| 216 | /* if already closed, don't reclose it */ |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 217 | if (self->fd != -1) |
| 218 | close(self->fd); |
| 219 | PyObject_Del(self); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 222 | |
| 223 | /* Methods to wrap the OSS ioctls. The calling convention is pretty |
| 224 | simple: |
| 225 | nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK) |
| 226 | fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) |
| 227 | etc. |
| 228 | */ |
| 229 | |
| 230 | |
| 231 | /* _do_ioctl_1() is a private helper function used for the OSS ioctls -- |
| 232 | SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C |
| 233 | like this: |
| 234 | ioctl(fd, SNDCTL_DSP_cmd, &arg) |
| 235 | |
| 236 | where arg is the value to set, and on return the driver sets arg to |
| 237 | the value that was actually set. Mapping this to Python is obvious: |
| 238 | arg = dsp.xxx(arg) |
| 239 | */ |
| 240 | static PyObject * |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 241 | _do_ioctl_1(int fd, PyObject *args, char *fname, int cmd) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 242 | { |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 243 | char argfmt[33] = "i:"; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 244 | int arg; |
| 245 | |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 246 | assert(strlen(fname) <= 30); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 247 | strcat(argfmt, fname); |
| 248 | if (!PyArg_ParseTuple(args, argfmt, &arg)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 249 | return NULL; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 250 | |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 251 | if (ioctl(fd, cmd, &arg) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 252 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 253 | return PyInt_FromLong(arg); |
| 254 | } |
| 255 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 256 | |
| 257 | /* ---------------------------------------------------------------------- |
| 258 | * Helper functions |
| 259 | */ |
| 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 | */ |
| 269 | |
| 270 | static PyObject * |
| 271 | _do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd) |
| 272 | { |
| 273 | char argfmt[32] = ":"; |
| 274 | int arg = 0; |
| 275 | |
| 276 | assert(strlen(fname) <= 30); |
| 277 | strcat(argfmt, fname); |
| 278 | if (!PyArg_ParseTuple(args, argfmt, &arg)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 279 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 280 | |
| 281 | if (ioctl(fd, cmd, &arg) == -1) |
| 282 | return PyErr_SetFromErrno(PyExc_IOError); |
| 283 | return PyInt_FromLong(arg); |
| 284 | } |
| 285 | |
| 286 | |
| 287 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 288 | /* _do_ioctl_0() is a private helper for the no-argument ioctls: |
| 289 | SNDCTL_DSP_{SYNC,RESET,POST}. */ |
| 290 | static PyObject * |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 291 | _do_ioctl_0(int fd, PyObject *args, char *fname, int cmd) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 292 | { |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 293 | char argfmt[32] = ":"; |
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); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 296 | strcat(argfmt, fname); |
| 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 | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 300 | if (ioctl(fd, cmd, 0) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 301 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 302 | Py_INCREF(Py_None); |
| 303 | return Py_None; |
| 304 | } |
| 305 | |
| 306 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 307 | /* ---------------------------------------------------------------------- |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 308 | * Methods of DSP objects (OSSAudioType) |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 309 | */ |
| 310 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 311 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 312 | oss_nonblock(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 313 | { |
| 314 | /* Hmmm: it doesn't appear to be possible to return to blocking |
| 315 | mode once we're in non-blocking mode! */ |
| 316 | if (!PyArg_ParseTuple(args, ":nonblock")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 317 | return NULL; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 318 | if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 319 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 320 | Py_INCREF(Py_None); |
| 321 | return Py_None; |
| 322 | } |
| 323 | |
| 324 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 325 | oss_setfmt(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 326 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 327 | return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 331 | oss_getfmts(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 332 | { |
| 333 | int mask; |
| 334 | if (!PyArg_ParseTuple(args, ":getfmts")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 335 | return NULL; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 336 | if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 337 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 338 | return PyInt_FromLong(mask); |
| 339 | } |
| 340 | |
| 341 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 342 | oss_channels(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 343 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 344 | return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 348 | oss_speed(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 349 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 350 | return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 354 | oss_sync(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 355 | { |
Greg Ward | b804390 | 2003-05-26 22:47:30 +0000 | [diff] [blame^] | 356 | int rv; |
| 357 | |
| 358 | Py_BEGIN_ALLOW_THREADS |
| 359 | rv = _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC); |
| 360 | Py_END_ALLOW_THREADS |
| 361 | return rv; |
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_reset(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 366 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 367 | return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 371 | oss_post(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 372 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 373 | return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
| 377 | /* Regular file methods: read(), write(), close(), etc. as well |
| 378 | as one convenience method, writeall(). */ |
| 379 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 380 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 381 | oss_read(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 382 | { |
| 383 | int size, count; |
| 384 | char *cp; |
| 385 | PyObject *rv; |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 386 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 387 | if (!PyArg_ParseTuple(args, "i:read", &size)) |
| 388 | return NULL; |
| 389 | rv = PyString_FromStringAndSize(NULL, size); |
| 390 | if (rv == NULL) |
| 391 | return NULL; |
| 392 | cp = PyString_AS_STRING(rv); |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 393 | |
| 394 | Py_BEGIN_ALLOW_THREADS |
| 395 | count = read(self->fd, cp, size); |
| 396 | Py_END_ALLOW_THREADS |
| 397 | |
| 398 | if (count < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 399 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 400 | Py_DECREF(rv); |
| 401 | return NULL; |
| 402 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 403 | self->icount += count; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 404 | _PyString_Resize(&rv, count); |
| 405 | return rv; |
| 406 | } |
| 407 | |
| 408 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 409 | oss_write(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 410 | { |
| 411 | char *cp; |
| 412 | int rv, size; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 413 | |
| 414 | if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 415 | return NULL; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 416 | } |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 417 | |
| 418 | Py_BEGIN_ALLOW_THREADS |
| 419 | rv = write(self->fd, cp, size); |
| 420 | Py_END_ALLOW_THREADS |
| 421 | |
| 422 | if (rv == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 423 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 424 | } else { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 425 | self->ocount += rv; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 426 | } |
| 427 | return PyInt_FromLong(rv); |
| 428 | } |
| 429 | |
| 430 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 431 | oss_writeall(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 432 | { |
| 433 | char *cp; |
| 434 | int rv, size; |
| 435 | fd_set write_set_fds; |
| 436 | int select_rv; |
| 437 | |
| 438 | /* NB. writeall() is only useful in non-blocking mode: according to |
| 439 | Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list |
| 440 | (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that |
| 441 | write() in blocking mode consumes the whole buffer. In blocking |
| 442 | mode, the behaviour of write() and writeall() from Python is |
| 443 | indistinguishable. */ |
| 444 | |
| 445 | if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) |
| 446 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 447 | |
| 448 | /* use select to wait for audio device to be available */ |
| 449 | FD_ZERO(&write_set_fds); |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 450 | FD_SET(self->fd, &write_set_fds); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 451 | |
| 452 | while (size > 0) { |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 453 | Py_BEGIN_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 454 | select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL); |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 455 | Py_END_ALLOW_THREADS |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 456 | assert(select_rv != 0); /* no timeout, can't expire */ |
| 457 | if (select_rv == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 458 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 459 | |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 460 | Py_BEGIN_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 461 | rv = write(self->fd, cp, size); |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 462 | Py_END_ALLOW_THREADS |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 463 | if (rv == -1) { |
| 464 | if (errno == EAGAIN) { /* buffer is full, try again */ |
| 465 | errno = 0; |
| 466 | continue; |
| 467 | } else /* it's a real error */ |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 468 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 469 | } else { /* wrote rv bytes */ |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 470 | self->ocount += rv; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 471 | size -= rv; |
| 472 | cp += rv; |
| 473 | } |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 474 | } |
| 475 | Py_INCREF(Py_None); |
| 476 | return Py_None; |
| 477 | } |
| 478 | |
| 479 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 480 | oss_close(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 481 | { |
| 482 | if (!PyArg_ParseTuple(args, ":close")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 483 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 484 | |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 485 | if (self->fd >= 0) { |
Greg Ward | b804390 | 2003-05-26 22:47:30 +0000 | [diff] [blame^] | 486 | Py_BEGIN_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 487 | close(self->fd); |
Greg Ward | b804390 | 2003-05-26 22:47:30 +0000 | [diff] [blame^] | 488 | Py_END_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 489 | self->fd = -1; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 490 | } |
| 491 | Py_INCREF(Py_None); |
| 492 | return Py_None; |
| 493 | } |
| 494 | |
| 495 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 496 | oss_fileno(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 497 | { |
| 498 | if (!PyArg_ParseTuple(args, ":fileno")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 499 | return NULL; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 500 | return PyInt_FromLong(self->fd); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 503 | |
| 504 | /* Convenience methods: these generally wrap a couple of ioctls into one |
| 505 | common task. */ |
| 506 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 507 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 508 | oss_setparameters(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 509 | { |
| 510 | int rate, ssize, nchannels, n, fmt, emulate=0; |
| 511 | |
| 512 | if (!PyArg_ParseTuple(args, "iiii|i:setparameters", |
| 513 | &rate, &ssize, &nchannels, &fmt, &emulate)) |
| 514 | return NULL; |
| 515 | |
| 516 | if (rate < 0) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 517 | PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", |
| 518 | rate); |
| 519 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 520 | } |
| 521 | if (ssize < 0) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 522 | PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", |
| 523 | ssize); |
| 524 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 525 | } |
| 526 | if (nchannels != 1 && nchannels != 2) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 527 | PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", |
| 528 | nchannels); |
| 529 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | for (n = 0; n < n_audio_types; n++) |
| 533 | if (fmt == audio_types[n].a_fmt) |
| 534 | break; |
| 535 | if (n == n_audio_types) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 536 | PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); |
| 537 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 538 | } |
| 539 | if (audio_types[n].a_bps != ssize) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 540 | PyErr_Format(PyExc_ValueError, |
| 541 | "for %s, expected sample size %d, not %d", |
| 542 | audio_types[n].a_name, audio_types[n].a_bps, ssize); |
| 543 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | if (emulate == 0) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 547 | if ((self->afmts & audio_types[n].a_fmt) == 0) { |
| 548 | PyErr_Format(PyExc_ValueError, |
| 549 | "%s format not supported by device", |
| 550 | audio_types[n].a_name); |
| 551 | return NULL; |
| 552 | } |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 553 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 554 | if (ioctl(self->fd, SNDCTL_DSP_SETFMT, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 555 | &audio_types[n].a_fmt) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 556 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 557 | return NULL; |
| 558 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 559 | if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 560 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 561 | return NULL; |
| 562 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 563 | if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 564 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 565 | return NULL; |
| 566 | } |
| 567 | |
| 568 | Py_INCREF(Py_None); |
| 569 | return Py_None; |
| 570 | } |
| 571 | |
| 572 | static int |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 573 | _ssize(oss_audio_t *self, int *nchannels, int *ssize) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 574 | { |
| 575 | int fmt; |
| 576 | |
| 577 | fmt = 0; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 578 | if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 579 | return -errno; |
| 580 | |
| 581 | switch (fmt) { |
| 582 | case AFMT_MU_LAW: |
| 583 | case AFMT_A_LAW: |
| 584 | case AFMT_U8: |
| 585 | case AFMT_S8: |
| 586 | *ssize = sizeof(char); |
| 587 | break; |
| 588 | case AFMT_S16_LE: |
| 589 | case AFMT_S16_BE: |
| 590 | case AFMT_U16_LE: |
| 591 | case AFMT_U16_BE: |
| 592 | *ssize = sizeof(short); |
| 593 | break; |
| 594 | case AFMT_MPEG: |
| 595 | case AFMT_IMA_ADPCM: |
| 596 | default: |
| 597 | return -EOPNOTSUPP; |
| 598 | } |
| 599 | *nchannels = 0; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 600 | if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 601 | return -errno; |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | |
| 606 | /* bufsize returns the size of the hardware audio buffer in number |
| 607 | of samples */ |
| 608 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 609 | oss_bufsize(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 610 | { |
| 611 | audio_buf_info ai; |
| 612 | int nchannels, ssize; |
| 613 | |
| 614 | if (!PyArg_ParseTuple(args, ":bufsize")) return NULL; |
| 615 | |
| 616 | if (_ssize(self, &nchannels, &ssize) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 617 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 618 | return NULL; |
| 619 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 620 | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 621 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 622 | return NULL; |
| 623 | } |
| 624 | return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize)); |
| 625 | } |
| 626 | |
| 627 | /* obufcount returns the number of samples that are available in the |
| 628 | hardware for playing */ |
| 629 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 630 | oss_obufcount(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 631 | { |
| 632 | audio_buf_info ai; |
| 633 | int nchannels, ssize; |
| 634 | |
| 635 | if (!PyArg_ParseTuple(args, ":obufcount")) |
| 636 | return NULL; |
| 637 | |
| 638 | if (_ssize(self, &nchannels, &ssize) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 639 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 640 | return NULL; |
| 641 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 642 | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 643 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 644 | return NULL; |
| 645 | } |
| 646 | return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / |
| 647 | (ssize * nchannels)); |
| 648 | } |
| 649 | |
| 650 | /* obufcount returns the number of samples that can be played without |
| 651 | blocking */ |
| 652 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 653 | oss_obuffree(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 654 | { |
| 655 | audio_buf_info ai; |
| 656 | int nchannels, ssize; |
| 657 | |
| 658 | if (!PyArg_ParseTuple(args, ":obuffree")) |
| 659 | return NULL; |
| 660 | |
| 661 | if (_ssize(self, &nchannels, &ssize) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 662 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 663 | return NULL; |
| 664 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 665 | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
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 | } |
| 669 | return PyInt_FromLong(ai.bytes / (ssize * nchannels)); |
| 670 | } |
| 671 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 672 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 673 | oss_getptr(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 674 | { |
| 675 | count_info info; |
| 676 | int req; |
| 677 | |
| 678 | if (!PyArg_ParseTuple(args, ":getptr")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 679 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 680 | |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 681 | if (self->mode == O_RDONLY) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 682 | req = SNDCTL_DSP_GETIPTR; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 683 | else |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 684 | req = SNDCTL_DSP_GETOPTR; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 685 | if (ioctl(self->fd, req, &info) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 686 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 687 | return NULL; |
| 688 | } |
| 689 | return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); |
| 690 | } |
| 691 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 692 | |
| 693 | /* ---------------------------------------------------------------------- |
| 694 | * Methods of mixer objects (OSSMixerType) |
| 695 | */ |
| 696 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 697 | static PyObject * |
| 698 | oss_mixer_close(oss_mixer_t *self, PyObject *args) |
| 699 | { |
| 700 | if (!PyArg_ParseTuple(args, ":close")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 701 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 702 | |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 703 | if (self->fd >= 0) { |
| 704 | close(self->fd); |
| 705 | self->fd = -1; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 706 | } |
| 707 | Py_INCREF(Py_None); |
| 708 | return Py_None; |
| 709 | } |
| 710 | |
| 711 | static PyObject * |
| 712 | oss_mixer_fileno(oss_mixer_t *self, PyObject *args) |
| 713 | { |
| 714 | if (!PyArg_ParseTuple(args, ":fileno")) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 715 | return NULL; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 716 | return PyInt_FromLong(self->fd); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /* Simple mixer interface methods */ |
| 720 | |
| 721 | static PyObject * |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 722 | oss_mixer_controls(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 723 | { |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 724 | return _do_ioctl_1_internal(self->fd, args, "controls", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 725 | SOUND_MIXER_READ_DEVMASK); |
| 726 | } |
| 727 | |
| 728 | static PyObject * |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 729 | oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 730 | { |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 731 | return _do_ioctl_1_internal(self->fd, args, "stereocontrols", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 732 | SOUND_MIXER_READ_STEREODEVS); |
| 733 | } |
| 734 | |
| 735 | static PyObject * |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 736 | oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 737 | { |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 738 | return _do_ioctl_1_internal(self->fd, args, "reccontrols", |
Greg Ward | b69bb3d | 2002-12-12 17:35:45 +0000 | [diff] [blame] | 739 | SOUND_MIXER_READ_RECMASK); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static PyObject * |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 743 | oss_mixer_get(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 744 | { |
| 745 | int channel, volume; |
| 746 | |
| 747 | /* Can't use _do_ioctl_1 because of encoded arg thingy. */ |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 748 | if (!PyArg_ParseTuple(args, "i:get", &channel)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 749 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 750 | |
| 751 | if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 752 | PyErr_SetString(OSSAudioError, "Invalid mixer channel specified."); |
| 753 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 756 | if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 757 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 758 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 759 | return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static PyObject * |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 763 | oss_mixer_set(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 764 | { |
| 765 | int channel, volume, leftVol, rightVol; |
| 766 | |
| 767 | /* Can't use _do_ioctl_1 because of encoded arg thingy. */ |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 768 | if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 769 | return NULL; |
| 770 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 771 | if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 772 | PyErr_SetString(OSSAudioError, "Invalid mixer channel specified."); |
| 773 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 777 | PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100."); |
| 778 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | volume = (rightVol << 8) | leftVol; |
| 782 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 783 | if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 784 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 785 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 786 | return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | static PyObject * |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 790 | oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 791 | { |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 792 | return _do_ioctl_1_internal(self->fd, args, "get_recsrc", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 793 | SOUND_MIXER_READ_RECSRC); |
| 794 | } |
| 795 | |
| 796 | static PyObject * |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 797 | oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 798 | { |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 799 | return _do_ioctl_1(self->fd, args, "set_recsrc", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 800 | SOUND_MIXER_WRITE_RECSRC); |
| 801 | } |
| 802 | |
| 803 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 804 | /* ---------------------------------------------------------------------- |
| 805 | * Method tables and other bureaucracy |
| 806 | */ |
| 807 | |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 808 | static PyMethodDef oss_methods[] = { |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 809 | /* Regular file methods */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 810 | { "read", (PyCFunction)oss_read, METH_VARARGS }, |
| 811 | { "write", (PyCFunction)oss_write, METH_VARARGS }, |
| 812 | { "writeall", (PyCFunction)oss_writeall, METH_VARARGS }, |
| 813 | { "close", (PyCFunction)oss_close, METH_VARARGS }, |
| 814 | { "fileno", (PyCFunction)oss_fileno, METH_VARARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 815 | |
| 816 | /* Simple ioctl wrappers */ |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 817 | { "nonblock", (PyCFunction)oss_nonblock, METH_VARARGS }, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 818 | { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS }, |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 819 | { "getfmts", (PyCFunction)oss_getfmts, METH_VARARGS }, |
| 820 | { "channels", (PyCFunction)oss_channels, METH_VARARGS }, |
| 821 | { "speed", (PyCFunction)oss_speed, METH_VARARGS }, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 822 | { "sync", (PyCFunction)oss_sync, METH_VARARGS }, |
| 823 | { "reset", (PyCFunction)oss_reset, METH_VARARGS }, |
| 824 | { "post", (PyCFunction)oss_post, METH_VARARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 825 | |
| 826 | /* Convenience methods -- wrap a couple of ioctls together */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 827 | { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS }, |
| 828 | { "bufsize", (PyCFunction)oss_bufsize, METH_VARARGS }, |
| 829 | { "obufcount", (PyCFunction)oss_obufcount, METH_VARARGS }, |
| 830 | { "obuffree", (PyCFunction)oss_obuffree, METH_VARARGS }, |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 831 | { "getptr", (PyCFunction)oss_getptr, METH_VARARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 832 | |
| 833 | /* Aliases for backwards compatibility */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 834 | { "flush", (PyCFunction)oss_sync, METH_VARARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 835 | |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 836 | { NULL, NULL} /* sentinel */ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 837 | }; |
| 838 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 839 | static PyMethodDef oss_mixer_methods[] = { |
| 840 | /* Regular file method - OSS mixers are ioctl-only interface */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 841 | { "close", (PyCFunction)oss_mixer_close, METH_VARARGS }, |
| 842 | { "fileno", (PyCFunction)oss_mixer_fileno, METH_VARARGS }, |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 843 | |
| 844 | /* Simple ioctl wrappers */ |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 845 | { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS }, |
| 846 | { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS}, |
| 847 | { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS}, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 848 | { "get", (PyCFunction)oss_mixer_get, METH_VARARGS }, |
| 849 | { "set", (PyCFunction)oss_mixer_set, METH_VARARGS }, |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 850 | { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS }, |
| 851 | { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS }, |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 852 | |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 853 | { NULL, NULL} |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 854 | }; |
| 855 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 856 | static PyObject * |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 857 | oss_getattr(oss_audio_t *self, char *name) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 858 | { |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 859 | return Py_FindMethod(oss_methods, (PyObject *)self, name); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 862 | static PyObject * |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 863 | oss_mixer_getattr(oss_mixer_t *self, char *name) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 864 | { |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 865 | return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 866 | } |
| 867 | |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 868 | static PyTypeObject OSSAudioType = { |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 869 | PyObject_HEAD_INIT(&PyType_Type) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 870 | 0, /*ob_size*/ |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 871 | "ossaudiodev.oss_audio_device", /*tp_name*/ |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 872 | sizeof(oss_audio_t), /*tp_size*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 873 | 0, /*tp_itemsize*/ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 874 | /* methods */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 875 | (destructor)oss_dealloc, /*tp_dealloc*/ |
| 876 | 0, /*tp_print*/ |
| 877 | (getattrfunc)oss_getattr, /*tp_getattr*/ |
| 878 | 0, /*tp_setattr*/ |
| 879 | 0, /*tp_compare*/ |
| 880 | 0, /*tp_repr*/ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 881 | }; |
| 882 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 883 | static PyTypeObject OSSMixerType = { |
| 884 | PyObject_HEAD_INIT(&PyType_Type) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 885 | 0, /*ob_size*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 886 | "ossaudiodev.oss_mixer_device", /*tp_name*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 887 | sizeof(oss_mixer_t), /*tp_size*/ |
| 888 | 0, /*tp_itemsize*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 889 | /* methods */ |
| 890 | (destructor)oss_mixer_dealloc, /*tp_dealloc*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 891 | 0, /*tp_print*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 892 | (getattrfunc)oss_mixer_getattr, /*tp_getattr*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 893 | 0, /*tp_setattr*/ |
| 894 | 0, /*tp_compare*/ |
| 895 | 0, /*tp_repr*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 896 | }; |
| 897 | |
| 898 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 899 | static PyObject * |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 900 | ossopen(PyObject *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 901 | { |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 902 | return (PyObject *)newossobject(args); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 905 | static PyObject * |
| 906 | ossopenmixer(PyObject *self, PyObject *args) |
| 907 | { |
| 908 | return (PyObject *)newossmixerobject(args); |
| 909 | } |
| 910 | |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 911 | static PyMethodDef ossaudiodev_methods[] = { |
| 912 | { "open", ossopen, METH_VARARGS }, |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 913 | { "openmixer", ossopenmixer, METH_VARARGS }, |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 914 | { 0, 0 }, |
| 915 | }; |
| 916 | |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 917 | |
| 918 | #define _EXPORT_INT(mod, name) \ |
| 919 | if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return; |
| 920 | |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 921 | |
| 922 | static char *control_labels[] = SOUND_DEVICE_LABELS; |
| 923 | static char *control_names[] = SOUND_DEVICE_NAMES; |
| 924 | |
| 925 | |
| 926 | static int |
| 927 | build_namelists (PyObject *module) |
| 928 | { |
| 929 | PyObject *labels; |
| 930 | PyObject *names; |
| 931 | PyObject *s; |
| 932 | int num_controls; |
| 933 | int i; |
| 934 | |
| 935 | num_controls = sizeof(control_labels) / sizeof(control_labels[0]); |
| 936 | assert(num_controls == sizeof(control_names) / sizeof(control_names[0])); |
| 937 | |
| 938 | labels = PyList_New(num_controls); |
| 939 | names = PyList_New(num_controls); |
| 940 | for (i = 0; i < num_controls; i++) { |
| 941 | s = PyString_FromString(control_labels[i]); |
| 942 | if (s == NULL) |
| 943 | return -1; |
| 944 | PyList_SET_ITEM(labels, i, s); |
| 945 | |
| 946 | s = PyString_FromString(control_names[i]); |
| 947 | if (s == NULL) |
| 948 | return -1; |
| 949 | PyList_SET_ITEM(names, i, s); |
| 950 | } |
| 951 | |
| 952 | if (PyModule_AddObject(module, "control_labels", labels) == -1) |
| 953 | return -1; |
| 954 | if (PyModule_AddObject(module, "control_names", names) == -1) |
| 955 | return -1; |
| 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 961 | void |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 962 | initossaudiodev(void) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 963 | { |
| 964 | PyObject *m; |
| 965 | |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 966 | m = Py_InitModule("ossaudiodev", ossaudiodev_methods); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 967 | |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 968 | OSSAudioError = PyErr_NewException("ossaudiodev.error", NULL, NULL); |
| 969 | if (OSSAudioError) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 970 | PyModule_AddObject(m, "error", OSSAudioError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 971 | |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 972 | /* Build 'control_labels' and 'control_names' lists and add them |
| 973 | to the module. */ |
| 974 | if (build_namelists(m) == -1) /* XXX what to do here? */ |
| 975 | return; |
| 976 | |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 977 | /* Expose the audio format numbers -- essential! */ |
| 978 | _EXPORT_INT(m, AFMT_QUERY); |
| 979 | _EXPORT_INT(m, AFMT_MU_LAW); |
| 980 | _EXPORT_INT(m, AFMT_A_LAW); |
| 981 | _EXPORT_INT(m, AFMT_IMA_ADPCM); |
| 982 | _EXPORT_INT(m, AFMT_U8); |
| 983 | _EXPORT_INT(m, AFMT_S16_LE); |
| 984 | _EXPORT_INT(m, AFMT_S16_BE); |
| 985 | _EXPORT_INT(m, AFMT_S8); |
| 986 | _EXPORT_INT(m, AFMT_U16_LE); |
| 987 | _EXPORT_INT(m, AFMT_U16_BE); |
| 988 | _EXPORT_INT(m, AFMT_MPEG); |
Andrew M. Kuchling | fe62bc9 | 2003-02-13 13:27:07 +0000 | [diff] [blame] | 989 | #ifdef AFMT_AC3 |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 990 | _EXPORT_INT(m, AFMT_AC3); |
Andrew M. Kuchling | fe62bc9 | 2003-02-13 13:27:07 +0000 | [diff] [blame] | 991 | #endif |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 992 | #ifdef AFMT_S16_NE |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 993 | _EXPORT_INT(m, AFMT_S16_NE); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 994 | #endif |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 995 | |
Greg Ward | 37897c2 | 2002-12-30 02:43:36 +0000 | [diff] [blame] | 996 | /* Expose the sound mixer device numbers. */ |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 997 | _EXPORT_INT(m, SOUND_MIXER_NRDEVICES); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 998 | _EXPORT_INT(m, SOUND_MIXER_VOLUME); |
| 999 | _EXPORT_INT(m, SOUND_MIXER_BASS); |
| 1000 | _EXPORT_INT(m, SOUND_MIXER_TREBLE); |
| 1001 | _EXPORT_INT(m, SOUND_MIXER_SYNTH); |
| 1002 | _EXPORT_INT(m, SOUND_MIXER_PCM); |
| 1003 | _EXPORT_INT(m, SOUND_MIXER_SPEAKER); |
| 1004 | _EXPORT_INT(m, SOUND_MIXER_LINE); |
| 1005 | _EXPORT_INT(m, SOUND_MIXER_MIC); |
| 1006 | _EXPORT_INT(m, SOUND_MIXER_CD); |
| 1007 | _EXPORT_INT(m, SOUND_MIXER_IMIX); |
| 1008 | _EXPORT_INT(m, SOUND_MIXER_ALTPCM); |
| 1009 | _EXPORT_INT(m, SOUND_MIXER_RECLEV); |
| 1010 | _EXPORT_INT(m, SOUND_MIXER_IGAIN); |
| 1011 | _EXPORT_INT(m, SOUND_MIXER_OGAIN); |
| 1012 | _EXPORT_INT(m, SOUND_MIXER_LINE1); |
| 1013 | _EXPORT_INT(m, SOUND_MIXER_LINE2); |
| 1014 | _EXPORT_INT(m, SOUND_MIXER_LINE3); |
| 1015 | _EXPORT_INT(m, SOUND_MIXER_DIGITAL1); |
| 1016 | _EXPORT_INT(m, SOUND_MIXER_DIGITAL2); |
| 1017 | _EXPORT_INT(m, SOUND_MIXER_DIGITAL3); |
| 1018 | _EXPORT_INT(m, SOUND_MIXER_PHONEIN); |
| 1019 | _EXPORT_INT(m, SOUND_MIXER_PHONEOUT); |
| 1020 | _EXPORT_INT(m, SOUND_MIXER_VIDEO); |
| 1021 | _EXPORT_INT(m, SOUND_MIXER_RADIO); |
| 1022 | _EXPORT_INT(m, SOUND_MIXER_MONITOR); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 1023 | |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1024 | /* Expose all the ioctl numbers for masochists who like to do this |
| 1025 | stuff directly. */ |
| 1026 | _EXPORT_INT(m, SNDCTL_COPR_HALT); |
| 1027 | _EXPORT_INT(m, SNDCTL_COPR_LOAD); |
| 1028 | _EXPORT_INT(m, SNDCTL_COPR_RCODE); |
| 1029 | _EXPORT_INT(m, SNDCTL_COPR_RCVMSG); |
| 1030 | _EXPORT_INT(m, SNDCTL_COPR_RDATA); |
| 1031 | _EXPORT_INT(m, SNDCTL_COPR_RESET); |
| 1032 | _EXPORT_INT(m, SNDCTL_COPR_RUN); |
| 1033 | _EXPORT_INT(m, SNDCTL_COPR_SENDMSG); |
| 1034 | _EXPORT_INT(m, SNDCTL_COPR_WCODE); |
| 1035 | _EXPORT_INT(m, SNDCTL_COPR_WDATA); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1036 | #ifdef SNDCTL_DSP_BIND_CHANNEL |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1037 | _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1038 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1039 | _EXPORT_INT(m, SNDCTL_DSP_CHANNELS); |
| 1040 | _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE); |
| 1041 | _EXPORT_INT(m, SNDCTL_DSP_GETCAPS); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1042 | #ifdef SNDCTL_DSP_GETCHANNELMASK |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1043 | _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1044 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1045 | _EXPORT_INT(m, SNDCTL_DSP_GETFMTS); |
| 1046 | _EXPORT_INT(m, SNDCTL_DSP_GETIPTR); |
| 1047 | _EXPORT_INT(m, SNDCTL_DSP_GETISPACE); |
| 1048 | _EXPORT_INT(m, SNDCTL_DSP_GETODELAY); |
| 1049 | _EXPORT_INT(m, SNDCTL_DSP_GETOPTR); |
| 1050 | _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1051 | #ifdef SNDCTL_DSP_GETSPDIF |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1052 | _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1053 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1054 | _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER); |
| 1055 | _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF); |
| 1056 | _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF); |
| 1057 | _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK); |
| 1058 | _EXPORT_INT(m, SNDCTL_DSP_POST); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1059 | #ifdef SNDCTL_DSP_PROFILE |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1060 | _EXPORT_INT(m, SNDCTL_DSP_PROFILE); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1061 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1062 | _EXPORT_INT(m, SNDCTL_DSP_RESET); |
| 1063 | _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE); |
| 1064 | _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX); |
| 1065 | _EXPORT_INT(m, SNDCTL_DSP_SETFMT); |
| 1066 | _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1067 | #ifdef SNDCTL_DSP_SETSPDIF |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1068 | _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1069 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1070 | _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO); |
| 1071 | _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER); |
| 1072 | _EXPORT_INT(m, SNDCTL_DSP_SPEED); |
| 1073 | _EXPORT_INT(m, SNDCTL_DSP_STEREO); |
| 1074 | _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE); |
| 1075 | _EXPORT_INT(m, SNDCTL_DSP_SYNC); |
| 1076 | _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE); |
| 1077 | _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR); |
| 1078 | _EXPORT_INT(m, SNDCTL_MIDI_INFO); |
| 1079 | _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD); |
| 1080 | _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE); |
| 1081 | _EXPORT_INT(m, SNDCTL_MIDI_PRETIME); |
| 1082 | _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE); |
| 1083 | _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT); |
| 1084 | _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1085 | #ifdef SNDCTL_SEQ_GETTIME |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1086 | _EXPORT_INT(m, SNDCTL_SEQ_GETTIME); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1087 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1088 | _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS); |
| 1089 | _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS); |
| 1090 | _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND); |
| 1091 | _EXPORT_INT(m, SNDCTL_SEQ_PANIC); |
| 1092 | _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE); |
| 1093 | _EXPORT_INT(m, SNDCTL_SEQ_RESET); |
| 1094 | _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES); |
| 1095 | _EXPORT_INT(m, SNDCTL_SEQ_SYNC); |
| 1096 | _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI); |
| 1097 | _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1098 | #ifdef SNDCTL_SYNTH_CONTROL |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1099 | _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1100 | #endif |
| 1101 | #ifdef SNDCTL_SYNTH_ID |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1102 | _EXPORT_INT(m, SNDCTL_SYNTH_ID); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1103 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1104 | _EXPORT_INT(m, SNDCTL_SYNTH_INFO); |
| 1105 | _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1106 | #ifdef SNDCTL_SYNTH_REMOVESAMPLE |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1107 | _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1108 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1109 | _EXPORT_INT(m, SNDCTL_TMR_CONTINUE); |
| 1110 | _EXPORT_INT(m, SNDCTL_TMR_METRONOME); |
| 1111 | _EXPORT_INT(m, SNDCTL_TMR_SELECT); |
| 1112 | _EXPORT_INT(m, SNDCTL_TMR_SOURCE); |
| 1113 | _EXPORT_INT(m, SNDCTL_TMR_START); |
| 1114 | _EXPORT_INT(m, SNDCTL_TMR_STOP); |
| 1115 | _EXPORT_INT(m, SNDCTL_TMR_TEMPO); |
| 1116 | _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 1117 | } |