Mercurial > cpython-lru_cache-weakref
annotate Modules/linuxaudiodev.c @ 34161:ca2ca1aeb080 2.4
Check in missing png version of pyfav.gif.
| author | Johannes Gijsbers <jlg@dds.nl> |
|---|---|
| date | Mon, 13 Dec 2004 13:11:42 +0000 |
| parents | 60e57797b8e6 |
| children | 6fb46e87d5f9 a1b1e451d82e |
| 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 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
43 PyObject_HEAD; |
|
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 * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 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
|
223 { |
| 15062 | 224 if (!PyArg_ParseTuple(args, ":close")) |
| 225 return NULL; | |
| 226 | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
231 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
|
232 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 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
|
237 { |
| 15062 | 238 if (!PyArg_ParseTuple(args, ":fileno")) |
| 239 return NULL; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
240 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
|
241 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 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
|
245 { |
| 15062 | 246 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
|
247 |
| 15062 | 248 if (!PyArg_ParseTuple(args, "iiii|i:setparameters", |
| 249 &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
|
250 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
251 |
| 15062 | 252 if (rate < 0) { |
| 253 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", | |
| 254 rate); | |
| 255 return NULL; | |
| 256 } | |
| 257 if (ssize < 0) { | |
| 258 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", | |
| 259 ssize); | |
| 260 return NULL; | |
| 261 } | |
| 262 if (nchannels != 1 && nchannels != 2) { | |
| 263 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", | |
| 264 nchannels); | |
| 265 return NULL; | |
| 266 } | |
| 267 | |
| 268 for (n = 0; n < n_audio_types; n++) | |
| 269 if (fmt == audio_types[n].a_fmt) | |
| 270 break; | |
| 271 if (n == n_audio_types) { | |
| 272 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); | |
| 273 return NULL; | |
| 274 } | |
| 275 if (audio_types[n].a_bps != ssize) { | |
| 276 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
277 "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
|
278 audio_types[n].a_name, audio_types[n].a_bps, ssize); |
| 15062 | 279 return NULL; |
| 280 } | |
| 281 | |
| 282 if (emulate == 0) { | |
| 283 if ((self->x_afmts & audio_types[n].a_fmt) == 0) { | |
| 284 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
285 "%s format not supported by device", |
| 15062 | 286 audio_types[n].a_name); |
| 287 return NULL; | |
| 288 } | |
| 289 } | |
| 290 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, | |
| 291 &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
|
292 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
293 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
294 } |
|
21312
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
295 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
|
296 PyErr_SetFromErrno(LinuxAudioError); |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
297 return NULL; |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
298 } |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
299 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
|
300 PyErr_SetFromErrno(LinuxAudioError); |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
301 return NULL; |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
302 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
304 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
|
305 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 static int |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 _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
|
310 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
311 int fmt; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
313 fmt = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
314 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
|
315 return -errno; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
317 switch (fmt) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
318 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
|
319 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
|
320 case AFMT_U8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
321 case AFMT_S8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
322 *ssize = sizeof(char); |
|
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_S16_LE: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
325 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
|
326 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
|
327 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
|
328 *ssize = sizeof(short); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
329 break; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
330 case AFMT_MPEG: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
331 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
|
332 default: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
333 return -EOPNOTSUPP; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
334 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
335 *nchannels = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
336 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
|
337 return -errno; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
338 return 0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 /* 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
|
343 of samples */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 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
|
346 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
347 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
|
348 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
350 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
|
351 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
352 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
|
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 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
|
357 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
358 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
359 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
360 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
|
361 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 /* 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
|
364 hardware for playing */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 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
|
367 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
368 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
|
369 int nchannels, ssize; |
|
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 (!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
|
372 return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
374 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
|
375 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
376 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
377 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
378 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
|
379 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
380 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
381 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
382 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
|
383 (ssize * nchannels)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 /* 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
|
387 blocking */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 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
|
390 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
391 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
|
392 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
394 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
|
395 return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
397 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
|
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 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
401 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
|
402 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
403 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
404 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
405 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
|
406 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 /* Flush the device */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 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
|
411 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
412 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
|
413 |
| 15062 | 414 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
|
415 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
416 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
417 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
418 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
|
419 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 |
| 15062 | 422 static PyObject * |
| 423 lad_getptr(lad_t *self, PyObject *args) | |
| 424 { | |
| 425 count_info info; | |
| 426 int req; | |
| 427 | |
| 428 if (!PyArg_ParseTuple(args, ":getptr")) | |
| 429 return NULL; | |
| 430 | |
| 431 if (self->x_mode == O_RDONLY) | |
| 432 req = SNDCTL_DSP_GETIPTR; | |
| 433 else | |
| 434 req = SNDCTL_DSP_GETOPTR; | |
| 435 if (ioctl(self->x_fd, req, &info) == -1) { | |
| 436 PyErr_SetFromErrno(LinuxAudioError); | |
| 437 return NULL; | |
| 438 } | |
| 439 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); | |
| 440 } | |
| 441 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 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
|
443 { "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
|
444 { "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
|
445 { "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
|
446 { "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
|
447 { "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
|
448 { "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
|
449 { "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
|
450 { "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
|
451 { "fileno", (PyCFunction)lad_fileno, METH_VARARGS }, |
| 15062 | 452 { "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
|
453 { NULL, NULL} /* sentinel */ |
|
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 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
|
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 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
|
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 PyTypeObject Ladtype = { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
463 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
|
464 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
|
465 "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
|
466 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
|
467 0, /*tp_itemsize*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
468 /* methods */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
469 (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
|
470 0, /*tp_print*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
471 (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
|
472 0, /*tp_setattr*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
473 0, /*tp_compare*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
474 0, /*tp_repr*/ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
477 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 ladopen(PyObject *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
480 return (PyObject *)newladobject(args); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
483 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
|
484 { "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
|
485 { 0, 0 }, |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
488 void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13543
diff
changeset
|
489 initlinuxaudiodev(void) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
490 { |
| 15062 | 491 PyObject *m; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
493 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
|
494 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
495 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
|
496 if (LinuxAudioError) |
| 15062 | 497 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
|
498 |
| 15062 | 499 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) |
| 500 return; | |
| 501 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) | |
| 502 return; | |
| 503 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) | |
| 504 return; | |
| 505 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) | |
| 506 return; | |
| 507 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) | |
| 508 return; | |
| 509 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) | |
| 510 return; | |
| 511 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) | |
| 512 return; | |
| 513 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) | |
| 514 return; | |
|
15095
c199460ccde9
Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
515 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
|
516 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 |
|
14346
5397fdf88ec2
Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents:
14306
diff
changeset
|
518 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
519 } |
