Mercurial > cpython-lru_cache-weakref
annotate Modules/linuxaudiodev.c @ 17581:c1937faabb23 2.1
Added support for optional explanation parameter to the \versionadded
macro.
Refactored do_cmd_versionadded() and do_cmd_versionchanged() to do most
of the work in a helper function, with the do_cmd_*() wrappers just supplying
a portion of the replacement text.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 18 Apr 2001 17:29:14 +0000 |
| parents | 03ba06247486 |
| children | 0102692417af |
| 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_UNISTD_H |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 #include <unistd.h> |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 #endif |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 #ifdef HAVE_FCNTL_H |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 #include <fcntl.h> |
| 15062 | 25 #else |
| 26 #define O_RDONLY 00 | |
| 27 #define O_WRONLY 01 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 #endif |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
| 15062 | 30 |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 #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
|
32 #if defined(linux) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 #include <linux/soundcard.h> |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 typedef unsigned long uint32_t; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 |
|
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
|
37 #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
|
38 #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
|
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 #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
|
41 #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
|
42 #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
|
43 |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
44 #endif |
|
62ec0bfd93f8
This module has a poor name, since it can be used under FreeBSD and
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14057
diff
changeset
|
45 |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 typedef struct { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
47 PyObject_HEAD; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
48 int x_fd; /* The open file */ |
| 15062 | 49 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
|
50 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
|
51 int x_ocount; /* Output count */ |
| 15062 | 52 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
|
53 } lad_t; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 |
| 15062 | 55 /* XXX several format defined in soundcard.h are not supported, |
| 56 including _NE (native endian) options and S32 options | |
| 57 */ | |
| 58 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 static struct { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
60 int a_bps; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
61 uint32_t a_fmt; |
| 15062 | 62 char *a_name; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 } audio_types[] = { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
64 { 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
|
65 { 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
|
66 { 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
|
67 { 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
|
68 { 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
|
69 { 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
|
70 { 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
|
71 { 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
|
72 { 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
|
73 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
| 15062 | 75 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
|
76 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 staticforward PyTypeObject Ladtype; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 static PyObject *LinuxAudioError; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 static lad_t * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 newladobject(PyObject *arg) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
84 lad_t *xp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
85 int fd, afmts, imode; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
86 char *mode; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
87 char *basedev; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
89 /* Check arg for r/w/rw */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
90 if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
91 if (strcmp(mode, "r") == 0) |
| 15062 | 92 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
|
93 else if (strcmp(mode, "w") == 0) |
| 15062 | 94 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
|
95 else { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
96 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
|
97 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
98 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
100 /* Open the correct device. The base device name comes from the |
| 15062 | 101 * 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
|
102 * control device tacks "ctl" onto the base device name. |
| 15062 | 103 * |
| 104 * Note that the only difference between /dev/audio and /dev/dsp | |
| 105 * is that the former uses logarithmic mu-law encoding and the | |
| 106 * 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
|
107 */ |
| 15062 | 108 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
109 basedev = getenv("AUDIODEV"); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
110 if (!basedev) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
111 basedev = "/dev/dsp"; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
| 15062 | 113 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
|
114 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
|
115 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
116 } |
| 15062 | 117 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
|
118 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
|
119 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
120 } |
| 15062 | 121 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
|
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 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
125 /* 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
|
126 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
|
127 close(fd); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
128 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
129 } |
| 15062 | 130 xp->x_fd = fd; |
| 131 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
|
132 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
|
133 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
|
134 return xp; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 static void |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 lad_dealloc(lad_t *xp) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 { |
|
14057
ca8dc1bae67d
lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents:
13651
diff
changeset
|
140 /* 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
|
141 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
|
142 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
|
143 PyObject_Del(xp); |
|
12191
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 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 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
|
148 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
149 int size, count; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
150 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
151 PyObject *rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
153 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
|
154 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
155 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
|
156 if (rv == NULL) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
157 return NULL; |
| 15062 | 158 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
|
159 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
|
160 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
161 Py_DECREF(rv); |
|
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 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
164 self->x_icount += count; |
| 15062 | 165 if (_PyString_Resize(&rv, count) == -1) |
| 166 return NULL; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
167 return rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 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
|
172 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
173 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
174 int rv, size; |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
175 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
|
176 struct timeval tv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
177 int select_retval; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
178 |
| 15062 | 179 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) |
| 180 return NULL; | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
182 /* 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
|
183 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
|
184 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
|
185 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
|
186 tv.tv_usec = 0; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
187 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
188 while (size > 0) { |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
189 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
|
190 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
|
191 if (select_retval) { |
| 15062 | 192 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
|
193 if (errno != EAGAIN) { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
194 PyErr_SetFromErrno(LinuxAudioError); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
195 return NULL; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
196 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
197 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
|
198 } |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
199 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
200 self->x_ocount += rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
201 size -= rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
202 cp += rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
203 } |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
204 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
205 /* 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
|
206 PyErr_SetFromErrno(LinuxAudioError); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
207 return NULL; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
208 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 } |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
210 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
|
211 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 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
|
216 { |
| 15062 | 217 if (!PyArg_ParseTuple(args, ":close")) |
| 218 return NULL; | |
| 219 | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
224 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
|
225 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 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
|
230 { |
| 15062 | 231 if (!PyArg_ParseTuple(args, ":fileno")) |
| 232 return NULL; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
233 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
|
234 } |
|
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 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 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
|
238 { |
| 15062 | 239 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
|
240 |
| 15062 | 241 if (!PyArg_ParseTuple(args, "iiii|i:setparameters", |
| 242 &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
|
243 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
244 |
| 15062 | 245 if (rate < 0) { |
| 246 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", | |
| 247 rate); | |
| 248 return NULL; | |
| 249 } | |
| 250 if (ssize < 0) { | |
| 251 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", | |
| 252 ssize); | |
| 253 return NULL; | |
| 254 } | |
| 255 if (nchannels != 1 && nchannels != 2) { | |
| 256 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", | |
| 257 nchannels); | |
| 258 return NULL; | |
| 259 } | |
| 260 | |
| 261 if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) { | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
262 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
263 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
264 } |
| 15062 | 265 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
266 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
267 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
268 } |
| 15062 | 269 |
| 270 for (n = 0; n < n_audio_types; n++) | |
| 271 if (fmt == audio_types[n].a_fmt) | |
| 272 break; | |
| 273 if (n == n_audio_types) { | |
| 274 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); | |
| 275 return NULL; | |
| 276 } | |
| 277 if (audio_types[n].a_bps != ssize) { | |
| 278 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
279 "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
|
280 audio_types[n].a_name, audio_types[n].a_bps, ssize); |
| 15062 | 281 return NULL; |
| 282 } | |
| 283 | |
| 284 if (emulate == 0) { | |
| 285 if ((self->x_afmts & audio_types[n].a_fmt) == 0) { | |
| 286 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
287 "%s format not supported by device", |
| 15062 | 288 audio_types[n].a_name); |
| 289 return NULL; | |
| 290 } | |
| 291 } | |
| 292 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, | |
| 293 &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
|
294 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
295 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
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 *nchannels = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
330 if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
331 return -errno; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
332 return 0; |
|
12191
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 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 /* 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
|
337 of samples */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 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
|
340 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
341 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
|
342 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
344 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
|
345 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
346 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
|
347 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
348 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
349 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
350 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
|
351 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
352 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
353 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
354 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
|
355 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 /* 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
|
358 hardware for playing */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 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
|
361 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
362 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
|
363 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
365 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
|
366 return NULL; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
368 if (_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
|
369 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
370 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
371 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
372 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
|
373 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
374 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
375 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
376 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
|
377 (ssize * nchannels)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 /* 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
|
381 blocking */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 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
|
384 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
385 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
|
386 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
388 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
|
389 return NULL; |
|
12191
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 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
|
392 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
393 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
394 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
395 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
|
396 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
397 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
398 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
399 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
|
400 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 /* Flush the device */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 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
|
405 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
406 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
|
407 |
| 15062 | 408 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
|
409 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
410 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
411 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
412 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
|
413 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 |
| 15062 | 416 static PyObject * |
| 417 lad_getptr(lad_t *self, PyObject *args) | |
| 418 { | |
| 419 count_info info; | |
| 420 int req; | |
| 421 | |
| 422 if (!PyArg_ParseTuple(args, ":getptr")) | |
| 423 return NULL; | |
| 424 | |
| 425 if (self->x_mode == O_RDONLY) | |
| 426 req = SNDCTL_DSP_GETIPTR; | |
| 427 else | |
| 428 req = SNDCTL_DSP_GETOPTR; | |
| 429 if (ioctl(self->x_fd, req, &info) == -1) { | |
| 430 PyErr_SetFromErrno(LinuxAudioError); | |
| 431 return NULL; | |
| 432 } | |
| 433 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); | |
| 434 } | |
| 435 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 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
|
437 { "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
|
438 { "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
|
439 { "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
|
440 { "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
|
441 { "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
|
442 { "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
|
443 { "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
|
444 { "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
|
445 { "fileno", (PyCFunction)lad_fileno, METH_VARARGS }, |
| 15062 | 446 { "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
|
447 { NULL, NULL} /* sentinel */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 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
|
452 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
453 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
|
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 PyTypeObject Ladtype = { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
457 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
|
458 0, /*ob_size*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
459 "linux_audio_device", /*tp_name*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
460 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
|
461 0, /*tp_itemsize*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
462 /* methods */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
463 (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
|
464 0, /*tp_print*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
465 (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
|
466 0, /*tp_setattr*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
467 0, /*tp_compare*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
468 0, /*tp_repr*/ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 ladopen(PyObject *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
474 return (PyObject *)newladobject(args); |
|
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 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
|
478 { "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
|
479 { 0, 0 }, |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 }; |
|
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 void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13543
diff
changeset
|
483 initlinuxaudiodev(void) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 { |
| 15062 | 485 PyObject *m; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
487 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
|
488 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
489 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
|
490 if (LinuxAudioError) |
| 15062 | 491 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
|
492 |
| 15062 | 493 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) |
| 494 return; | |
| 495 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) | |
| 496 return; | |
| 497 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) | |
| 498 return; | |
| 499 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) | |
| 500 return; | |
| 501 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) | |
| 502 return; | |
| 503 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) | |
| 504 return; | |
| 505 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) | |
| 506 return; | |
| 507 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) | |
| 508 return; | |
|
15095
c199460ccde9
Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
509 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
|
510 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 |
|
14346
5397fdf88ec2
Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents:
14306
diff
changeset
|
512 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 } |
