Mercurial > cpython-lru_cache-weakref
annotate Modules/linuxaudiodev.c @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | 3fe3ccdf0155 |
| children | 0c36410c39e8 |
| 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 * Status : Unknown, Use with caution! |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * (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
|
13 ****************************************************************************** |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 */ |
|
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 #include "Python.h" |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 #include "structmember.h" |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 #ifdef HAVE_FCNTL_H |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 #include <fcntl.h> |
| 15062 | 21 #else |
| 22 #define O_RDONLY 00 | |
| 23 #define O_WRONLY 01 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 #endif |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
| 15062 | 26 |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 #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
|
28 #if defined(linux) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 #include <linux/soundcard.h> |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 typedef unsigned long uint32_t; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
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
|
33 #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
|
34 #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
|
35 |
|
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
|
36 #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
|
37 #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
|
38 #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
|
39 |
|
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 #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
|
41 |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 typedef struct { |
|
36221
a1b1e451d82e
Fix icc warnings: extra semi-colon
Neal Norwitz <nnorwitz@gmail.com>
parents:
26453
diff
changeset
|
43 PyObject_HEAD |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
44 int x_fd; /* The open file */ |
| 15062 | 45 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
|
46 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
|
47 int x_ocount; /* Output count */ |
| 15062 | 48 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
|
49 } lad_t; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 |
| 15062 | 51 /* XXX several format defined in soundcard.h are not supported, |
| 52 including _NE (native endian) options and S32 options | |
| 53 */ | |
| 54 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 static struct { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
56 int a_bps; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
57 uint32_t a_fmt; |
| 15062 | 58 char *a_name; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 } audio_types[] = { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
60 { 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
|
61 { 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
|
62 { 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
|
63 { 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
|
64 { 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
|
65 { 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
|
66 { 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
|
67 { 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
|
68 { 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
|
69 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 |
| 15062 | 71 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
|
72 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23295
diff
changeset
|
73 static PyTypeObject Ladtype; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 static PyObject *LinuxAudioError; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 static lad_t * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 newladobject(PyObject *arg) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
80 lad_t *xp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
81 int fd, afmts, imode; |
|
26453
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
82 char *basedev = NULL; |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
83 char *mode = NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 |
|
26453
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
85 /* Two ways to call linuxaudiodev.open(): |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
86 open(device, mode) (for consistency with builtin open()) |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
87 open(mode) (for backwards compatibility) |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
88 because the *first* argument is optional, parsing args is |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
89 a wee bit tricky. */ |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
90 if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode)) |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
91 return NULL; |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
92 if (mode == NULL) { /* only one arg supplied */ |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
93 mode = basedev; |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
94 basedev = NULL; |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
95 } |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
96 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
97 if (strcmp(mode, "r") == 0) |
| 15062 | 98 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
|
99 else if (strcmp(mode, "w") == 0) |
| 15062 | 100 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
|
101 else { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
102 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
|
103 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
104 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
106 /* Open the correct device. The base device name comes from the |
| 15062 | 107 * 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
|
108 * control device tacks "ctl" onto the base device name. |
| 15062 | 109 * |
| 110 * Note that the only difference between /dev/audio and /dev/dsp | |
| 111 * is that the former uses logarithmic mu-law encoding and the | |
| 112 * 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
|
113 */ |
| 15062 | 114 |
|
26453
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
115 if (basedev == NULL) { /* called with one arg */ |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
116 basedev = getenv("AUDIODEV"); |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
117 if (basedev == NULL) /* $AUDIODEV not set */ |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
118 basedev = "/dev/dsp"; |
|
60e57797b8e6
Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents:
24280
diff
changeset
|
119 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 |
| 15062 | 121 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
|
122 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
|
123 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
124 } |
| 15062 | 125 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
|
126 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
|
127 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
128 } |
| 15062 | 129 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
|
130 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
|
131 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
132 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
133 /* 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
|
134 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
|
135 close(fd); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
136 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
137 } |
| 15062 | 138 xp->x_fd = fd; |
| 139 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
|
140 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
|
141 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
|
142 return xp; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 static void |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 lad_dealloc(lad_t *xp) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 { |
|
14057
ca8dc1bae67d
lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents:
13651
diff
changeset
|
148 /* 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
|
149 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
|
150 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
|
151 PyObject_Del(xp); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 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
|
156 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
157 int size, count; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
158 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
159 PyObject *rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
161 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
|
162 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
163 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
|
164 if (rv == NULL) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
165 return NULL; |
| 15062 | 166 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
|
167 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
|
168 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
169 Py_DECREF(rv); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
170 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
171 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
172 self->x_icount += count; |
|
23295
6fa76b4e59fe
Repair widespread misuse of _PyString_Resize. Since it's clear people
Tim Peters <tim.peters@gmail.com>
parents:
21712
diff
changeset
|
173 _PyString_Resize(&rv, count); |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
174 return rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 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
|
179 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
180 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
181 int rv, size; |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
182 fd_set write_set_fds; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
183 struct timeval tv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
184 int select_retval; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
185 |
| 15062 | 186 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) |
| 187 return NULL; | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
189 /* use select to wait for audio device to be available */ |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
190 FD_ZERO(&write_set_fds); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
191 FD_SET(self->x_fd, &write_set_fds); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
192 tv.tv_sec = 4; /* timeout values */ |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
193 tv.tv_usec = 0; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
194 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
195 while (size > 0) { |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
196 select_retval = select(self->x_fd+1, NULL, &write_set_fds, NULL, &tv); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
197 tv.tv_sec = 1; tv.tv_usec = 0; /* willing to wait this long next time*/ |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
198 if (select_retval) { |
| 15062 | 199 if ((rv = write(self->x_fd, cp, size)) == -1) { |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
200 if (errno != EAGAIN) { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
201 PyErr_SetFromErrno(LinuxAudioError); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
202 return NULL; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
203 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
204 errno = 0; /* EAGAIN: buffer is full, try again */ |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
205 } |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
206 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
207 self->x_ocount += rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
208 size -= rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
209 cp += rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
210 } |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
211 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
212 /* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */ |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
213 PyErr_SetFromErrno(LinuxAudioError); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
214 return NULL; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
215 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 } |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
217 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
|
218 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
222 lad_close(lad_t *self, PyObject *unused) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 } |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
228 Py_RETURN_NONE; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
232 lad_fileno(lad_t *self, PyObject *unused) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
234 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
|
235 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 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
|
239 { |
| 15062 | 240 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
|
241 |
| 15062 | 242 if (!PyArg_ParseTuple(args, "iiii|i:setparameters", |
| 243 &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
|
244 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
245 |
| 15062 | 246 if (rate < 0) { |
| 247 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", | |
| 248 rate); | |
| 249 return NULL; | |
| 250 } | |
| 251 if (ssize < 0) { | |
| 252 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", | |
| 253 ssize); | |
| 254 return NULL; | |
| 255 } | |
| 256 if (nchannels != 1 && nchannels != 2) { | |
| 257 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", | |
| 258 nchannels); | |
| 259 return NULL; | |
| 260 } | |
| 261 | |
| 262 for (n = 0; n < n_audio_types; n++) | |
| 263 if (fmt == audio_types[n].a_fmt) | |
| 264 break; | |
| 265 if (n == n_audio_types) { | |
| 266 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); | |
| 267 return NULL; | |
| 268 } | |
| 269 if (audio_types[n].a_bps != ssize) { | |
| 270 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
271 "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
|
272 audio_types[n].a_name, audio_types[n].a_bps, ssize); |
| 15062 | 273 return NULL; |
| 274 } | |
| 275 | |
| 276 if (emulate == 0) { | |
| 277 if ((self->x_afmts & audio_types[n].a_fmt) == 0) { | |
| 278 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
279 "%s format not supported by device", |
| 15062 | 280 audio_types[n].a_name); |
| 281 return NULL; | |
| 282 } | |
| 283 } | |
| 284 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, | |
| 285 &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
|
286 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
287 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
288 } |
|
21312
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
289 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) { |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
290 PyErr_SetFromErrno(LinuxAudioError); |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
291 return NULL; |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
292 } |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
293 if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) { |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
294 PyErr_SetFromErrno(LinuxAudioError); |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
295 return NULL; |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
296 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
298 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
|
299 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 static int |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 _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
|
304 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
305 int fmt; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
307 fmt = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
308 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
|
309 return -errno; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
311 switch (fmt) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
312 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
|
313 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
|
314 case AFMT_U8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
315 case AFMT_S8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
316 *ssize = sizeof(char); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
317 break; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 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
|
322 *ssize = sizeof(short); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
323 break; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
324 case AFMT_MPEG: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
325 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
|
326 default: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
327 return -EOPNOTSUPP; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
328 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
329 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
|
330 return -errno; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
331 return 0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 /* 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
|
336 of samples */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
338 lad_bufsize(lad_t *self, PyObject *unused) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
340 audio_buf_info ai; |
|
36785
6e285c69efc0
Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
341 int nchannels=0, ssize=0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 |
|
36785
6e285c69efc0
Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
343 if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
344 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
345 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
346 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
347 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
|
348 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
349 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
350 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
351 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
|
352 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 /* 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
|
355 hardware for playing */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
357 lad_obufcount(lad_t *self, PyObject *unused) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
359 audio_buf_info ai; |
|
36785
6e285c69efc0
Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
360 int nchannels=0, ssize=0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 |
|
36785
6e285c69efc0
Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
362 if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
363 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
364 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
365 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
366 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
|
367 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
368 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
369 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
370 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
|
371 (ssize * nchannels)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 /* 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
|
375 blocking */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
377 lad_obuffree(lad_t *self, PyObject *unused) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
379 audio_buf_info ai; |
|
36785
6e285c69efc0
Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
380 int nchannels=0, ssize=0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 |
|
36785
6e285c69efc0
Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents:
36324
diff
changeset
|
382 if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
383 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
384 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
385 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
386 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
|
387 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
388 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
389 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
390 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
|
391 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 /* Flush the device */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
395 lad_flush(lad_t *self, PyObject *unused) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 { |
| 15062 | 397 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
|
398 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
399 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
400 } |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
401 Py_RETURN_NONE; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 |
| 15062 | 404 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
405 lad_getptr(lad_t *self, PyObject *unused) |
| 15062 | 406 { |
| 407 count_info info; | |
| 408 int req; | |
| 409 | |
| 410 if (self->x_mode == O_RDONLY) | |
| 411 req = SNDCTL_DSP_GETIPTR; | |
| 412 else | |
| 413 req = SNDCTL_DSP_GETOPTR; | |
| 414 if (ioctl(self->x_fd, req, &info) == -1) { | |
| 415 PyErr_SetFromErrno(LinuxAudioError); | |
| 416 return NULL; | |
| 417 } | |
| 418 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); | |
| 419 } | |
| 420 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 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
|
422 { "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
|
423 { "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
|
424 { "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
|
425 { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS }, |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
426 { "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS }, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
427 { "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS }, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
428 { "flush", (PyCFunction)lad_flush, METH_NOARGS }, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
429 { "close", (PyCFunction)lad_close, METH_NOARGS }, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
430 { "fileno", (PyCFunction)lad_fileno, METH_NOARGS }, |
|
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
36785
diff
changeset
|
431 { "getptr", (PyCFunction)lad_getptr, METH_NOARGS }, |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
432 { NULL, NULL} /* sentinel */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 }; |
|
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 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 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
|
437 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
438 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
|
439 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 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
|
442 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
|
443 0, /*ob_size*/ |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
21312
diff
changeset
|
444 "linuxaudiodev.linux_audio_device", /*tp_name*/ |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
445 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
|
446 0, /*tp_itemsize*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
447 /* methods */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
448 (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
|
449 0, /*tp_print*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
450 (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
|
451 0, /*tp_setattr*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
452 0, /*tp_compare*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
453 0, /*tp_repr*/ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 }; |
|
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 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 ladopen(PyObject *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
459 return (PyObject *)newladobject(args); |
|
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 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
|
463 { "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
|
464 { 0, 0 }, |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13543
diff
changeset
|
468 initlinuxaudiodev(void) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 { |
| 15062 | 470 PyObject *m; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
472 m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36221
diff
changeset
|
473 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36221
diff
changeset
|
474 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
476 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
|
477 if (LinuxAudioError) |
| 15062 | 478 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
|
479 |
| 15062 | 480 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) |
| 481 return; | |
| 482 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) | |
| 483 return; | |
| 484 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) | |
| 485 return; | |
| 486 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) | |
| 487 return; | |
| 488 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) | |
| 489 return; | |
| 490 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) | |
| 491 return; | |
| 492 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) | |
| 493 return; | |
| 494 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) | |
| 495 return; | |
|
15095
c199460ccde9
Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
496 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
|
497 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 |
|
14346
5397fdf88ec2
Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents:
14306
diff
changeset
|
499 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 } |
