blob: 0661fb78ab1ab2e13d91deec694350723378698e [file] [log] [blame]
Guido van Rossumb130dc72000-03-30 23:25:49 +00001/* Hey Emacs, this is -*-C-*-
2 ******************************************************************************
3 * linuxaudiodev.c -- Linux audio device for python.
4 *
5 * Author : Peter Bosch
6 * Created On : Thu Mar 2 21:10:33 2000
7 * Last Modified By: Peter Bosch
8 * Last Modified On: Fri Mar 24 11:27:00 2000
9 * Status : Unknown, Use with caution!
10 *
11 * Unless other notices are present in any part of this file
12 * explicitly claiming copyrights for other people and/or
13 * organizations, the contents of this file is fully copyright
14 * (C) 2000 Peter Bosch, all rights reserved.
15 ******************************************************************************
16 */
17
18#include "Python.h"
19#include "structmember.h"
20
21#ifdef HAVE_UNISTD_H
22#include <unistd.h>
23#endif
24
25#ifdef HAVE_FCNTL_H
26#include <fcntl.h>
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000027#else
28#define O_RDONLY 00
29#define O_WRONLY 01
Guido van Rossumb130dc72000-03-30 23:25:49 +000030#endif
31
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000032
Guido van Rossumb130dc72000-03-30 23:25:49 +000033#include <sys/ioctl.h>
Jeremy Hyltona3895c02000-08-31 18:11:07 +000034#if defined(linux)
Guido van Rossumb130dc72000-03-30 23:25:49 +000035#include <linux/soundcard.h>
36
37typedef unsigned long uint32_t;
38
Jeremy Hyltona3895c02000-08-31 18:11:07 +000039#elif defined(__FreeBSD__)
40#include <machine/soundcard.h>
41
42#ifndef SNDCTL_DSP_CHANNELS
43#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
44#endif
45
46#endif
47
Guido van Rossumb130dc72000-03-30 23:25:49 +000048typedef struct {
Fred Drakeda940d82000-07-08 06:05:58 +000049 PyObject_HEAD;
50 int x_fd; /* The open file */
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000051 int x_mode; /* file mode */
Fred Drakeda940d82000-07-08 06:05:58 +000052 int x_icount; /* Input count */
53 int x_ocount; /* Output count */
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000054 uint32_t x_afmts; /* Audio formats supported by hardware*/
Guido van Rossumb130dc72000-03-30 23:25:49 +000055} lad_t;
56
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000057/* XXX several format defined in soundcard.h are not supported,
58 including _NE (native endian) options and S32 options
59*/
60
Guido van Rossumb130dc72000-03-30 23:25:49 +000061static struct {
Fred Drakeda940d82000-07-08 06:05:58 +000062 int a_bps;
63 uint32_t a_fmt;
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000064 char *a_name;
Guido van Rossumb130dc72000-03-30 23:25:49 +000065} audio_types[] = {
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000066 { 8, AFMT_MU_LAW, "Logarithmic mu-law audio" },
67 { 8, AFMT_A_LAW, "Logarithmic A-law audio" },
68 { 8, AFMT_U8, "Standard unsigned 8-bit audio" },
69 { 8, AFMT_S8, "Standard signed 8-bit audio" },
70 { 16, AFMT_U16_BE, "Big-endian 16-bit unsigned format" },
71 { 16, AFMT_U16_LE, "Little-endian 16-bit unsigned format" },
72 { 16, AFMT_S16_BE, "Big-endian 16-bit signed format" },
73 { 16, AFMT_S16_LE, "Little-endian 16-bit signed format" },
Guido van Rossumb130dc72000-03-30 23:25:49 +000074};
75
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000076static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]);
Guido van Rossumb130dc72000-03-30 23:25:49 +000077
78staticforward PyTypeObject Ladtype;
79
80static PyObject *LinuxAudioError;
81
82static lad_t *
83newladobject(PyObject *arg)
84{
Fred Drakeda940d82000-07-08 06:05:58 +000085 lad_t *xp;
86 int fd, afmts, imode;
87 char *mode;
88 char *basedev;
Guido van Rossumb130dc72000-03-30 23:25:49 +000089
Fred Drakeda940d82000-07-08 06:05:58 +000090 /* Check arg for r/w/rw */
91 if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL;
92 if (strcmp(mode, "r") == 0)
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000093 imode = O_RDONLY;
Fred Drakeda940d82000-07-08 06:05:58 +000094 else if (strcmp(mode, "w") == 0)
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +000095 imode = O_WRONLY;
Fred Drakeda940d82000-07-08 06:05:58 +000096 else {
97 PyErr_SetString(LinuxAudioError, "Mode should be one of 'r', or 'w'");
98 return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +000099 }
Guido van Rossumb130dc72000-03-30 23:25:49 +0000100
Fred Drakeda940d82000-07-08 06:05:58 +0000101 /* Open the correct device. The base device name comes from the
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000102 * AUDIODEV environment variable first, then /dev/dsp. The
Fred Drakeda940d82000-07-08 06:05:58 +0000103 * control device tacks "ctl" onto the base device name.
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000104 *
105 * Note that the only difference between /dev/audio and /dev/dsp
106 * is that the former uses logarithmic mu-law encoding and the
107 * latter uses 8-bit unsigned encoding.
Fred Drakeda940d82000-07-08 06:05:58 +0000108 */
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000109
Fred Drakeda940d82000-07-08 06:05:58 +0000110 basedev = getenv("AUDIODEV");
111 if (!basedev)
112 basedev = "/dev/dsp";
Guido van Rossumb130dc72000-03-30 23:25:49 +0000113
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000114 if ((fd = open(basedev, imode)) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000115 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
116 return NULL;
117 }
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000118 if (imode == O_WRONLY && ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000119 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
120 return NULL;
121 }
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000122 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000123 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
124 return NULL;
125 }
126 /* Create and initialize the object */
127 if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) {
128 close(fd);
129 return NULL;
130 }
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000131 xp->x_fd = fd;
132 xp->x_mode = imode;
Fred Drakeda940d82000-07-08 06:05:58 +0000133 xp->x_icount = xp->x_ocount = 0;
134 xp->x_afmts = afmts;
135 return xp;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000136}
137
138static void
139lad_dealloc(lad_t *xp)
140{
Barry Warsaw4ddd8202000-08-18 05:10:45 +0000141 /* if already closed, don't reclose it */
142 if (xp->x_fd != -1)
143 close(xp->x_fd);
Fred Drakeda940d82000-07-08 06:05:58 +0000144 PyObject_Del(xp);
Guido van Rossumb130dc72000-03-30 23:25:49 +0000145}
146
147static PyObject *
148lad_read(lad_t *self, PyObject *args)
149{
Fred Drakeda940d82000-07-08 06:05:58 +0000150 int size, count;
151 char *cp;
152 PyObject *rv;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000153
Fred Drakeda940d82000-07-08 06:05:58 +0000154 if (!PyArg_ParseTuple(args, "i:read", &size))
155 return NULL;
156 rv = PyString_FromStringAndSize(NULL, size);
157 if (rv == NULL)
158 return NULL;
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000159 cp = PyString_AS_STRING(rv);
Fred Drakeda940d82000-07-08 06:05:58 +0000160 if ((count = read(self->x_fd, cp, size)) < 0) {
161 PyErr_SetFromErrno(LinuxAudioError);
162 Py_DECREF(rv);
163 return NULL;
164 }
165 self->x_icount += count;
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000166 if (_PyString_Resize(&rv, count) == -1)
167 return NULL;
Fred Drakeda940d82000-07-08 06:05:58 +0000168 return rv;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000169}
170
171static PyObject *
172lad_write(lad_t *self, PyObject *args)
173{
Fred Drakeda940d82000-07-08 06:05:58 +0000174 char *cp;
175 int rv, size;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000176
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000177 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
178 return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000179
Fred Drakeda940d82000-07-08 06:05:58 +0000180 while (size > 0) {
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000181 if ((rv = write(self->x_fd, cp, size)) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000182 PyErr_SetFromErrno(LinuxAudioError);
183 return NULL;
184 }
185 self->x_ocount += rv;
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000186 size -= rv;
187 cp += rv;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000188 }
Fred Drakeda940d82000-07-08 06:05:58 +0000189 Py_INCREF(Py_None);
190 return Py_None;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000191}
192
193static PyObject *
194lad_close(lad_t *self, PyObject *args)
195{
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000196 if (!PyArg_ParseTuple(args, ":close"))
197 return NULL;
198
Fred Drakeda940d82000-07-08 06:05:58 +0000199 if (self->x_fd >= 0) {
200 close(self->x_fd);
201 self->x_fd = -1;
202 }
203 Py_INCREF(Py_None);
204 return Py_None;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000205}
206
207static PyObject *
208lad_fileno(lad_t *self, PyObject *args)
209{
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000210 if (!PyArg_ParseTuple(args, ":fileno"))
211 return NULL;
Fred Drakeda940d82000-07-08 06:05:58 +0000212 return PyInt_FromLong(self->x_fd);
Guido van Rossumb130dc72000-03-30 23:25:49 +0000213}
214
215static PyObject *
216lad_setparameters(lad_t *self, PyObject *args)
217{
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000218 int rate, ssize, nchannels, n, fmt, emulate=0;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000219
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000220 if (!PyArg_ParseTuple(args, "iiii|i:setparameters",
221 &rate, &ssize, &nchannels, &fmt, &emulate))
Fred Drakeda940d82000-07-08 06:05:58 +0000222 return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000223
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000224 if (rate < 0) {
225 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
226 rate);
227 return NULL;
228 }
229 if (ssize < 0) {
230 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
231 ssize);
232 return NULL;
233 }
234 if (nchannels != 1 && nchannels != 2) {
235 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
236 nchannels);
237 return NULL;
238 }
239
240 if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000241 PyErr_SetFromErrno(LinuxAudioError);
242 return NULL;
243 }
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000244 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000245 PyErr_SetFromErrno(LinuxAudioError);
246 return NULL;
247 }
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000248
249 for (n = 0; n < n_audio_types; n++)
Fred Drakeda940d82000-07-08 06:05:58 +0000250 if (fmt == audio_types[n].a_fmt)
251 break;
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000252 if (n == n_audio_types) {
253 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
254 return NULL;
255 }
256 if (audio_types[n].a_bps != ssize) {
257 PyErr_Format(PyExc_ValueError,
258 "sample size %d expected for %s: %d received",
259 audio_types[n].a_bps, audio_types[n].a_name, ssize);
260 return NULL;
261 }
Guido van Rossumb130dc72000-03-30 23:25:49 +0000262
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000263 if (emulate == 0) {
264 if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
265 PyErr_Format(PyExc_ValueError,
266 "format not supported by device: %s",
267 audio_types[n].a_name);
268 return NULL;
269 }
270 }
271 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
272 &audio_types[n].a_fmt) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000273 PyErr_SetFromErrno(LinuxAudioError);
274 return NULL;
275 }
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000276
Fred Drakeda940d82000-07-08 06:05:58 +0000277 Py_INCREF(Py_None);
278 return Py_None;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000279}
280
281static int
282_ssize(lad_t *self, int *nchannels, int *ssize)
283{
Fred Drakeda940d82000-07-08 06:05:58 +0000284 int fmt;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000285
Fred Drakeda940d82000-07-08 06:05:58 +0000286 fmt = 0;
287 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
288 return -errno;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000289
Fred Drakeda940d82000-07-08 06:05:58 +0000290 switch (fmt) {
291 case AFMT_MU_LAW:
292 case AFMT_A_LAW:
293 case AFMT_U8:
294 case AFMT_S8:
295 *ssize = sizeof(char);
296 break;
297 case AFMT_S16_LE:
298 case AFMT_S16_BE:
299 case AFMT_U16_LE:
300 case AFMT_U16_BE:
301 *ssize = sizeof(short);
302 break;
303 case AFMT_MPEG:
304 case AFMT_IMA_ADPCM:
305 default:
306 return -EOPNOTSUPP;
307 }
308 *nchannels = 0;
309 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
310 return -errno;
311 return 0;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000312}
313
314
315/* bufsize returns the size of the hardware audio buffer in number
Fred Drakeda940d82000-07-08 06:05:58 +0000316 of samples */
Guido van Rossumb130dc72000-03-30 23:25:49 +0000317static PyObject *
318lad_bufsize(lad_t *self, PyObject *args)
319{
Fred Drakeda940d82000-07-08 06:05:58 +0000320 audio_buf_info ai;
321 int nchannels, ssize;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000322
Fred Drakeda940d82000-07-08 06:05:58 +0000323 if (!PyArg_ParseTuple(args, ":bufsize")) return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000324
Fred Drakeda940d82000-07-08 06:05:58 +0000325 if (_ssize(self, &nchannels, &ssize) < 0) {
326 PyErr_SetFromErrno(LinuxAudioError);
327 return NULL;
328 }
329 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
330 PyErr_SetFromErrno(LinuxAudioError);
331 return NULL;
332 }
333 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
Guido van Rossumb130dc72000-03-30 23:25:49 +0000334}
335
336/* obufcount returns the number of samples that are available in the
337 hardware for playing */
338static PyObject *
339lad_obufcount(lad_t *self, PyObject *args)
340{
Fred Drakeda940d82000-07-08 06:05:58 +0000341 audio_buf_info ai;
342 int nchannels, ssize;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000343
Fred Drakeda940d82000-07-08 06:05:58 +0000344 if (!PyArg_ParseTuple(args, ":obufcount"))
345 return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000346
Fred Drakeda940d82000-07-08 06:05:58 +0000347 if (_ssize(self, &nchannels, &ssize) < 0) {
348 PyErr_SetFromErrno(LinuxAudioError);
349 return NULL;
350 }
351 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
352 PyErr_SetFromErrno(LinuxAudioError);
353 return NULL;
354 }
355 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
356 (ssize * nchannels));
Guido van Rossumb130dc72000-03-30 23:25:49 +0000357}
358
359/* obufcount returns the number of samples that can be played without
Fred Drakeda940d82000-07-08 06:05:58 +0000360 blocking */
Guido van Rossumb130dc72000-03-30 23:25:49 +0000361static PyObject *
362lad_obuffree(lad_t *self, PyObject *args)
363{
Fred Drakeda940d82000-07-08 06:05:58 +0000364 audio_buf_info ai;
365 int nchannels, ssize;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000366
Fred Drakeda940d82000-07-08 06:05:58 +0000367 if (!PyArg_ParseTuple(args, ":obuffree"))
368 return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000369
Fred Drakeda940d82000-07-08 06:05:58 +0000370 if (_ssize(self, &nchannels, &ssize) < 0) {
371 PyErr_SetFromErrno(LinuxAudioError);
372 return NULL;
373 }
374 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
375 PyErr_SetFromErrno(LinuxAudioError);
376 return NULL;
377 }
378 return PyInt_FromLong(ai.bytes / (ssize * nchannels));
Guido van Rossumb130dc72000-03-30 23:25:49 +0000379}
380
381/* Flush the device */
382static PyObject *
383lad_flush(lad_t *self, PyObject *args)
384{
Fred Drakeda940d82000-07-08 06:05:58 +0000385 if (!PyArg_ParseTuple(args, ":flush")) return NULL;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000386
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000387 if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) == -1) {
Fred Drakeda940d82000-07-08 06:05:58 +0000388 PyErr_SetFromErrno(LinuxAudioError);
389 return NULL;
390 }
391 Py_INCREF(Py_None);
392 return Py_None;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000393}
394
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000395static PyObject *
396lad_getptr(lad_t *self, PyObject *args)
397{
398 count_info info;
399 int req;
400
401 if (!PyArg_ParseTuple(args, ":getptr"))
402 return NULL;
403
404 if (self->x_mode == O_RDONLY)
405 req = SNDCTL_DSP_GETIPTR;
406 else
407 req = SNDCTL_DSP_GETOPTR;
408 if (ioctl(self->x_fd, req, &info) == -1) {
409 PyErr_SetFromErrno(LinuxAudioError);
410 return NULL;
411 }
412 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
413}
414
Guido van Rossumb130dc72000-03-30 23:25:49 +0000415static PyMethodDef lad_methods[] = {
Fred Drakeda940d82000-07-08 06:05:58 +0000416 { "read", (PyCFunction)lad_read, METH_VARARGS },
417 { "write", (PyCFunction)lad_write, METH_VARARGS },
418 { "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS },
419 { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS },
420 { "obufcount", (PyCFunction)lad_obufcount, METH_VARARGS },
421 { "obuffree", (PyCFunction)lad_obuffree, METH_VARARGS },
422 { "flush", (PyCFunction)lad_flush, METH_VARARGS },
423 { "close", (PyCFunction)lad_close, METH_VARARGS },
424 { "fileno", (PyCFunction)lad_fileno, METH_VARARGS },
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000425 { "getptr", (PyCFunction)lad_getptr, METH_VARARGS },
Fred Drakeda940d82000-07-08 06:05:58 +0000426 { NULL, NULL} /* sentinel */
Guido van Rossumb130dc72000-03-30 23:25:49 +0000427};
428
429static PyObject *
430lad_getattr(lad_t *xp, char *name)
431{
Fred Drakeda940d82000-07-08 06:05:58 +0000432 return Py_FindMethod(lad_methods, (PyObject *)xp, name);
Guido van Rossumb130dc72000-03-30 23:25:49 +0000433}
434
435static PyTypeObject Ladtype = {
Fred Drakeda940d82000-07-08 06:05:58 +0000436 PyObject_HEAD_INIT(&PyType_Type)
437 0, /*ob_size*/
438 "linux_audio_device", /*tp_name*/
439 sizeof(lad_t), /*tp_size*/
440 0, /*tp_itemsize*/
441 /* methods */
442 (destructor)lad_dealloc, /*tp_dealloc*/
443 0, /*tp_print*/
444 (getattrfunc)lad_getattr, /*tp_getattr*/
445 0, /*tp_setattr*/
446 0, /*tp_compare*/
447 0, /*tp_repr*/
Guido van Rossumb130dc72000-03-30 23:25:49 +0000448};
449
450static PyObject *
451ladopen(PyObject *self, PyObject *args)
452{
Fred Drakeda940d82000-07-08 06:05:58 +0000453 return (PyObject *)newladobject(args);
Guido van Rossumb130dc72000-03-30 23:25:49 +0000454}
455
456static PyMethodDef linuxaudiodev_methods[] = {
Fred Drakeda940d82000-07-08 06:05:58 +0000457 { "open", ladopen, METH_VARARGS },
458 { 0, 0 },
Guido van Rossumb130dc72000-03-30 23:25:49 +0000459};
460
Guido van Rossumb130dc72000-03-30 23:25:49 +0000461void
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000462initlinuxaudiodev(void)
Guido van Rossumb130dc72000-03-30 23:25:49 +0000463{
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000464 PyObject *m;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000465
Fred Drakeda940d82000-07-08 06:05:58 +0000466 m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
Guido van Rossumb130dc72000-03-30 23:25:49 +0000467
Fred Drakeda940d82000-07-08 06:05:58 +0000468 LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
469 if (LinuxAudioError)
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000470 PyModule_AddObject(m, "error", LinuxAudioError);
Guido van Rossumb130dc72000-03-30 23:25:49 +0000471
Jeremy Hyltone2b7c4d2000-10-06 19:39:55 +0000472 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1)
473 return;
474 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1)
475 return;
476 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1)
477 return;
478 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1)
479 return;
480 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1)
481 return;
482 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1)
483 return;
484 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1)
485 return;
486 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1)
487 return;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000488
Barry Warsaw9bfd2bf2000-09-01 09:01:32 +0000489 return;
Guido van Rossumb130dc72000-03-30 23:25:49 +0000490}