Mercurial > cpython-lru_cache-weakref
annotate Modules/linuxaudiodev.c @ 16798:258dcafe2d0b legacy-trunk
Gustavo Niemeyer <niemeyer@conectiva.com>:
Fixed recno support (keys are integers rather than strings).
Work around DB bug that cause stdin to be closed by rnopen() when the
DB file needed to exist but did not (no longer segfaults).
This closes SF tracker patch #403445.
Also wrapped some long lines and added whitespace around operators -- FLD.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Tue, 27 Feb 2001 18:56:46 +0000 |
| parents | c8205552dde1 |
| children | 03ba06247486 |
| rev | line source |
|---|---|
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /* Hey Emacs, this is -*-C-*- |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 ****************************************************************************** |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 * linuxaudiodev.c -- Linux audio device for python. |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 * Author : Peter Bosch |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 * Created On : Thu Mar 2 21:10:33 2000 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 * Last Modified By: Peter Bosch |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 * Last Modified On: Fri Mar 24 11:27:00 2000 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 * Status : Unknown, Use with caution! |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 * Unless other notices are present in any part of this file |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 * explicitly claiming copyrights for other people and/or |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 * organizations, the contents of this file is fully copyright |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 * (C) 2000 Peter Bosch, all rights reserved. |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 ****************************************************************************** |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 #include "Python.h" |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 #include "structmember.h" |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 #ifdef HAVE_UNISTD_H |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 #include <unistd.h> |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 #endif |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 #ifdef HAVE_FCNTL_H |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 #include <fcntl.h> |
| 15062 | 27 #else |
| 28 #define O_RDONLY 00 | |
| 29 #define O_WRONLY 01 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 #endif |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
| 15062 | 32 |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 #include <sys/ioctl.h> |
|
14306
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
34 #if defined(linux) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 #include <linux/soundcard.h> |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 typedef unsigned long uint32_t; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 |
|
14306
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
39 #elif defined(__FreeBSD__) |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
40 #include <machine/soundcard.h> |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
41 |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
42 #ifndef SNDCTL_DSP_CHANNELS |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
43 #define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
44 #endif |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
45 |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
46 #endif |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
47 |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 typedef struct { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
49 PyObject_HEAD; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
50 int x_fd; /* The open file */ |
| 15062 | 51 int x_mode; /* file mode */ |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
52 int x_icount; /* Input count */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
53 int x_ocount; /* Output count */ |
| 15062 | 54 uint32_t x_afmts; /* Audio formats supported by hardware*/ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 } lad_t; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 |
| 15062 | 57 /* XXX several format defined in soundcard.h are not supported, |
| 58 including _NE (native endian) options and S32 options | |
| 59 */ | |
| 60 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 static struct { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
62 int a_bps; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
63 uint32_t a_fmt; |
| 15062 | 64 char *a_name; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 } audio_types[] = { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
66 { 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
67 { 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
68 { 8, AFMT_U8, "linear unsigned 8-bit audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
69 { 8, AFMT_S8, "linear signed 8-bit audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
70 { 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
71 { 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
72 { 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" }, |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
73 { 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" }, |
|
15958
c8205552dde1
Restore lost AFMT_S16_NE entry.
Ka-Ping Yee <ping@zesty.ca>
parents:
15900
diff
changeset
|
74 { 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" }, |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 |
| 15062 | 77 static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 staticforward PyTypeObject Ladtype; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 static PyObject *LinuxAudioError; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 static lad_t * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 newladobject(PyObject *arg) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
86 lad_t *xp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
87 int fd, afmts, imode; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
88 char *mode; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
89 char *basedev; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
91 /* Check arg for r/w/rw */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
92 if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
93 if (strcmp(mode, "r") == 0) |
| 15062 | 94 imode = O_RDONLY; |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
95 else if (strcmp(mode, "w") == 0) |
| 15062 | 96 imode = O_WRONLY; |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
97 else { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
98 PyErr_SetString(LinuxAudioError, "mode should be 'r' or 'w'"); |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
99 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
100 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
102 /* Open the correct device. The base device name comes from the |
| 15062 | 103 * AUDIODEV environment variable first, then /dev/dsp. The |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
104 * control device tacks "ctl" onto the base device name. |
| 15062 | 105 * |
| 106 * Note that the only difference between /dev/audio and /dev/dsp | |
| 107 * is that the former uses logarithmic mu-law encoding and the | |
| 108 * latter uses 8-bit unsigned encoding. | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
109 */ |
| 15062 | 110 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
111 basedev = getenv("AUDIODEV"); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
112 if (!basedev) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
113 basedev = "/dev/dsp"; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 |
| 15062 | 115 if ((fd = open(basedev, imode)) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
116 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
117 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
118 } |
| 15062 | 119 if (imode == O_WRONLY && ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
120 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
121 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
122 } |
| 15062 | 123 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
124 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
125 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
126 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
127 /* Create and initialize the object */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
128 if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
129 close(fd); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
130 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
131 } |
| 15062 | 132 xp->x_fd = fd; |
| 133 xp->x_mode = imode; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
134 xp->x_icount = xp->x_ocount = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
135 xp->x_afmts = afmts; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
136 return xp; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 static void |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 lad_dealloc(lad_t *xp) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 { |
|
14057
ca8dc1bae67d
lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents:
13651
diff
changeset
|
142 /* if already closed, don't reclose it */ |
|
ca8dc1bae67d
lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents:
13651
diff
changeset
|
143 if (xp->x_fd != -1) |
|
ca8dc1bae67d
lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents:
13651
diff
changeset
|
144 close(xp->x_fd); |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
145 PyObject_Del(xp); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 lad_read(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
151 int size, count; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
152 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
153 PyObject *rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
155 if (!PyArg_ParseTuple(args, "i:read", &size)) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
156 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
157 rv = PyString_FromStringAndSize(NULL, size); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
158 if (rv == NULL) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
159 return NULL; |
| 15062 | 160 cp = PyString_AS_STRING(rv); |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
161 if ((count = read(self->x_fd, cp, size)) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
162 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
163 Py_DECREF(rv); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
164 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
165 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
166 self->x_icount += count; |
| 15062 | 167 if (_PyString_Resize(&rv, count) == -1) |
| 168 return NULL; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
169 return rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 lad_write(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
175 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
176 int rv, size; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 |
| 15062 | 178 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) |
| 179 return NULL; | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
181 while (size > 0) { |
| 15062 | 182 if ((rv = write(self->x_fd, cp, size)) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
183 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
184 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
185 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
186 self->x_ocount += rv; |
| 15062 | 187 size -= rv; |
| 188 cp += rv; | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 } |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
190 Py_INCREF(Py_None); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
191 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 lad_close(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 { |
| 15062 | 197 if (!PyArg_ParseTuple(args, ":close")) |
| 198 return NULL; | |
| 199 | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
200 if (self->x_fd >= 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
201 close(self->x_fd); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
202 self->x_fd = -1; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
203 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
204 Py_INCREF(Py_None); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
205 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 lad_fileno(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 { |
| 15062 | 211 if (!PyArg_ParseTuple(args, ":fileno")) |
| 212 return NULL; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
213 return PyInt_FromLong(self->x_fd); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 lad_setparameters(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 { |
| 15062 | 219 int rate, ssize, nchannels, n, fmt, emulate=0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
| 15062 | 221 if (!PyArg_ParseTuple(args, "iiii|i:setparameters", |
| 222 &rate, &ssize, &nchannels, &fmt, &emulate)) | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
223 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
224 |
| 15062 | 225 if (rate < 0) { |
| 226 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", | |
| 227 rate); | |
| 228 return NULL; | |
| 229 } | |
| 230 if (ssize < 0) { | |
| 231 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", | |
| 232 ssize); | |
| 233 return NULL; | |
| 234 } | |
| 235 if (nchannels != 1 && nchannels != 2) { | |
| 236 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", | |
| 237 nchannels); | |
| 238 return NULL; | |
| 239 } | |
| 240 | |
| 241 if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) { | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
242 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
243 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
244 } |
| 15062 | 245 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
246 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
247 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
248 } |
| 15062 | 249 |
| 250 for (n = 0; n < n_audio_types; n++) | |
| 251 if (fmt == audio_types[n].a_fmt) | |
| 252 break; | |
| 253 if (n == n_audio_types) { | |
| 254 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); | |
| 255 return NULL; | |
| 256 } | |
| 257 if (audio_types[n].a_bps != ssize) { | |
| 258 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
259 "for %s, expected sample size %d, not %d", |
|
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
260 audio_types[n].a_name, audio_types[n].a_bps, ssize); |
| 15062 | 261 return NULL; |
| 262 } | |
| 263 | |
| 264 if (emulate == 0) { | |
| 265 if ((self->x_afmts & audio_types[n].a_fmt) == 0) { | |
| 266 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
267 "%s format not supported by device", |
| 15062 | 268 audio_types[n].a_name); |
| 269 return NULL; | |
| 270 } | |
| 271 } | |
| 272 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, | |
| 273 &audio_types[n].a_fmt) == -1) { | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
274 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
275 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
276 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
278 Py_INCREF(Py_None); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
279 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 static int |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 _ssize(lad_t *self, int *nchannels, int *ssize) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
285 int fmt; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
286 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
287 fmt = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
288 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
289 return -errno; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
291 switch (fmt) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
292 case AFMT_MU_LAW: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
293 case AFMT_A_LAW: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
294 case AFMT_U8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
295 case AFMT_S8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
296 *ssize = sizeof(char); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
297 break; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
298 case AFMT_S16_LE: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
299 case AFMT_S16_BE: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
300 case AFMT_U16_LE: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
301 case AFMT_U16_BE: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
302 *ssize = sizeof(short); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
303 break; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
304 case AFMT_MPEG: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
305 case AFMT_IMA_ADPCM: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
306 default: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
307 return -EOPNOTSUPP; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
308 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
309 *nchannels = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
310 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
311 return -errno; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
312 return 0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 /* bufsize returns the size of the hardware audio buffer in number |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
317 of samples */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 lad_bufsize(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
321 audio_buf_info ai; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
322 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
324 if (!PyArg_ParseTuple(args, ":bufsize")) return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
326 if (_ssize(self, &nchannels, &ssize) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
327 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
328 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
329 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
330 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
331 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
332 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
333 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
334 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 /* obufcount returns the number of samples that are available in the |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 hardware for playing */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 lad_obufcount(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
342 audio_buf_info ai; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
343 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
345 if (!PyArg_ParseTuple(args, ":obufcount")) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
346 return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
348 if (_ssize(self, &nchannels, &ssize) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
349 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
350 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
351 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
352 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
353 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
354 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
355 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
356 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
357 (ssize * nchannels)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 /* obufcount returns the number of samples that can be played without |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
361 blocking */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 lad_obuffree(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
365 audio_buf_info ai; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
366 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
368 if (!PyArg_ParseTuple(args, ":obuffree")) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
369 return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
371 if (_ssize(self, &nchannels, &ssize) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
372 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
373 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
374 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
375 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
376 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
377 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
378 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
379 return PyInt_FromLong(ai.bytes / (ssize * nchannels)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 /* Flush the device */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 lad_flush(lad_t *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
386 if (!PyArg_ParseTuple(args, ":flush")) return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 |
| 15062 | 388 if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
389 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
390 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
391 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
392 Py_INCREF(Py_None); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
393 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 |
| 15062 | 396 static PyObject * |
| 397 lad_getptr(lad_t *self, PyObject *args) | |
| 398 { | |
| 399 count_info info; | |
| 400 int req; | |
| 401 | |
| 402 if (!PyArg_ParseTuple(args, ":getptr")) | |
| 403 return NULL; | |
| 404 | |
| 405 if (self->x_mode == O_RDONLY) | |
| 406 req = SNDCTL_DSP_GETIPTR; | |
| 407 else | |
| 408 req = SNDCTL_DSP_GETOPTR; | |
| 409 if (ioctl(self->x_fd, req, &info) == -1) { | |
| 410 PyErr_SetFromErrno(LinuxAudioError); | |
| 411 return NULL; | |
| 412 } | |
| 413 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); | |
| 414 } | |
| 415 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 static PyMethodDef lad_methods[] = { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
417 { "read", (PyCFunction)lad_read, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
418 { "write", (PyCFunction)lad_write, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
419 { "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
420 { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
421 { "obufcount", (PyCFunction)lad_obufcount, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
422 { "obuffree", (PyCFunction)lad_obuffree, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
423 { "flush", (PyCFunction)lad_flush, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
424 { "close", (PyCFunction)lad_close, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
425 { "fileno", (PyCFunction)lad_fileno, METH_VARARGS }, |
| 15062 | 426 { "getptr", (PyCFunction)lad_getptr, METH_VARARGS }, |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
427 { NULL, NULL} /* sentinel */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 lad_getattr(lad_t *xp, char *name) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
433 return Py_FindMethod(lad_methods, (PyObject *)xp, name); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 static PyTypeObject Ladtype = { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
437 PyObject_HEAD_INIT(&PyType_Type) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
438 0, /*ob_size*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
439 "linux_audio_device", /*tp_name*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
440 sizeof(lad_t), /*tp_size*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
441 0, /*tp_itemsize*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
442 /* methods */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
443 (destructor)lad_dealloc, /*tp_dealloc*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
444 0, /*tp_print*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
445 (getattrfunc)lad_getattr, /*tp_getattr*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
446 0, /*tp_setattr*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
447 0, /*tp_compare*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
448 0, /*tp_repr*/ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 ladopen(PyObject *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
454 return (PyObject *)newladobject(args); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 static PyMethodDef linuxaudiodev_methods[] = { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
458 { "open", ladopen, METH_VARARGS }, |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
459 { 0, 0 }, |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13543
diff
changeset
|
463 initlinuxaudiodev(void) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 { |
| 15062 | 465 PyObject *m; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
467 m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
469 LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
470 if (LinuxAudioError) |
| 15062 | 471 PyModule_AddObject(m, "error", LinuxAudioError); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 |
| 15062 | 473 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) |
| 474 return; | |
| 475 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) | |
| 476 return; | |
| 477 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) | |
| 478 return; | |
| 479 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) | |
| 480 return; | |
| 481 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) | |
| 482 return; | |
| 483 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) | |
| 484 return; | |
| 485 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) | |
| 486 return; | |
| 487 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) | |
| 488 return; | |
|
15095
c199460ccde9
Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
489 if (PyModule_AddIntConstant(m, "AFMT_S16_NE", (long)AFMT_S16_NE) == -1) |
|
c199460ccde9
Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
490 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 |
|
14346
5397fdf88ec2
Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents:
14306
diff
changeset
|
492 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 } |
