Mercurial > cpython-lru_cache-weakref
annotate Modules/linuxaudiodev.c @ 25135:0f0016632be4 legacy-trunk
_formatparam(), set_param(): RFC 2231 encoding support by Oleg
Broytmann in SF patch #600096. Specifically, the former function now
encodes the triplets, while the latter adds optional charset and
language arguments.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Fri, 06 Sep 2002 03:55:04 +0000 |
| parents | 1598a1e473e2 |
| children | 60e57797b8e6 |
| 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; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
82 char *mode; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
83 char *basedev; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
85 /* 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
|
86 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
|
87 if (strcmp(mode, "r") == 0) |
| 15062 | 88 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
|
89 else if (strcmp(mode, "w") == 0) |
| 15062 | 90 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
|
91 else { |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
92 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
|
93 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
94 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
96 /* Open the correct device. The base device name comes from the |
| 15062 | 97 * 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
|
98 * control device tacks "ctl" onto the base device name. |
| 15062 | 99 * |
| 100 * Note that the only difference between /dev/audio and /dev/dsp | |
| 101 * is that the former uses logarithmic mu-law encoding and the | |
| 102 * 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
|
103 */ |
| 15062 | 104 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
105 basedev = getenv("AUDIODEV"); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
106 if (!basedev) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
107 basedev = "/dev/dsp"; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 |
| 15062 | 109 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
|
110 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
|
111 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
112 } |
| 15062 | 113 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
|
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 (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
|
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 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
121 /* 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
|
122 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
|
123 close(fd); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
124 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
125 } |
| 15062 | 126 xp->x_fd = fd; |
| 127 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
|
128 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
|
129 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
|
130 return xp; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 static void |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 lad_dealloc(lad_t *xp) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 { |
|
14057
ca8dc1bae67d
lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents:
13651
diff
changeset
|
136 /* 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
|
137 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
|
138 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
|
139 PyObject_Del(xp); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 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
|
144 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
145 int size, count; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
146 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
147 PyObject *rv; |
|
12191
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 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
|
150 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
151 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
|
152 if (rv == NULL) |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
153 return NULL; |
| 15062 | 154 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
|
155 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
|
156 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
157 Py_DECREF(rv); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
158 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
159 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
160 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
|
161 _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
|
162 return rv; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 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
|
167 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
168 char *cp; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
169 int rv, size; |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
170 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
|
171 struct timeval tv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
172 int select_retval; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
173 |
| 15062 | 174 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) |
| 175 return NULL; | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
177 /* 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
|
178 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
|
179 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
|
180 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
|
181 tv.tv_usec = 0; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
182 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
183 while (size > 0) { |
|
17302
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
184 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
|
185 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
|
186 if (select_retval) { |
| 15062 | 187 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
|
188 if (errno != EAGAIN) { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
189 PyErr_SetFromErrno(LinuxAudioError); |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
190 return NULL; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
191 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
192 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
|
193 } |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
194 } else { |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
195 self->x_ocount += rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
196 size -= rv; |
|
03ba06247486
Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents:
15958
diff
changeset
|
197 cp += rv; |
|
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 /* 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
|
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 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 } |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
205 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
|
206 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 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
|
211 { |
| 15062 | 212 if (!PyArg_ParseTuple(args, ":close")) |
| 213 return NULL; | |
| 214 | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
219 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
|
220 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 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
|
225 { |
| 15062 | 226 if (!PyArg_ParseTuple(args, ":fileno")) |
| 227 return NULL; | |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
228 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
|
229 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 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
|
233 { |
| 15062 | 234 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
|
235 |
| 15062 | 236 if (!PyArg_ParseTuple(args, "iiii|i:setparameters", |
| 237 &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
|
238 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
239 |
| 15062 | 240 if (rate < 0) { |
| 241 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d", | |
| 242 rate); | |
| 243 return NULL; | |
| 244 } | |
| 245 if (ssize < 0) { | |
| 246 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d", | |
| 247 ssize); | |
| 248 return NULL; | |
| 249 } | |
| 250 if (nchannels != 1 && nchannels != 2) { | |
| 251 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d", | |
| 252 nchannels); | |
| 253 return NULL; | |
| 254 } | |
| 255 | |
| 256 for (n = 0; n < n_audio_types; n++) | |
| 257 if (fmt == audio_types[n].a_fmt) | |
| 258 break; | |
| 259 if (n == n_audio_types) { | |
| 260 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt); | |
| 261 return NULL; | |
| 262 } | |
| 263 if (audio_types[n].a_bps != ssize) { | |
| 264 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
265 "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
|
266 audio_types[n].a_name, audio_types[n].a_bps, ssize); |
| 15062 | 267 return NULL; |
| 268 } | |
| 269 | |
| 270 if (emulate == 0) { | |
| 271 if ((self->x_afmts & audio_types[n].a_fmt) == 0) { | |
| 272 PyErr_Format(PyExc_ValueError, | |
|
15900
1129e16a11df
better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents:
15095
diff
changeset
|
273 "%s format not supported by device", |
| 15062 | 274 audio_types[n].a_name); |
| 275 return NULL; | |
| 276 } | |
| 277 } | |
| 278 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, | |
| 279 &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
|
280 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
281 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
282 } |
|
21312
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
283 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
|
284 PyErr_SetFromErrno(LinuxAudioError); |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
285 return NULL; |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
286 } |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
287 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
|
288 PyErr_SetFromErrno(LinuxAudioError); |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
289 return NULL; |
|
0102692417af
SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents:
17302
diff
changeset
|
290 } |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
292 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
|
293 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 static int |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 _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
|
298 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
299 int fmt; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
301 fmt = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
302 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
|
303 return -errno; |
|
12191
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 switch (fmt) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
306 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
|
307 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
|
308 case AFMT_U8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
309 case AFMT_S8: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
310 *ssize = sizeof(char); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
311 break; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 *ssize = sizeof(short); |
|
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_MPEG: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
319 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
|
320 default: |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
321 return -EOPNOTSUPP; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
322 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
323 *nchannels = 0; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
324 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
|
325 return -errno; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
326 return 0; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 /* 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
|
331 of samples */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 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
|
334 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
335 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
|
336 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
338 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
|
339 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
340 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
|
341 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
342 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
343 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
344 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
|
345 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
346 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
347 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
348 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
|
349 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 /* 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
|
352 hardware for playing */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 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
|
355 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
356 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
|
357 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
359 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
|
360 return NULL; |
|
12191
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 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
|
363 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
364 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
365 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
366 if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
367 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
368 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
369 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
370 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
371 (ssize * nchannels)); |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 /* obufcount returns the number of samples that can be played without |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
375 blocking */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 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
|
378 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
379 audio_buf_info ai; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
380 int nchannels, ssize; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
382 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
|
383 return NULL; |
|
12191
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 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
|
386 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
387 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
388 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
389 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
|
390 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
391 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
392 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
393 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
|
394 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 /* Flush the device */ |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 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
|
399 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
400 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
|
401 |
| 15062 | 402 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
|
403 PyErr_SetFromErrno(LinuxAudioError); |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
404 return NULL; |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
405 } |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
406 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
|
407 return Py_None; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 } |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 |
| 15062 | 410 static PyObject * |
| 411 lad_getptr(lad_t *self, PyObject *args) | |
| 412 { | |
| 413 count_info info; | |
| 414 int req; | |
| 415 | |
| 416 if (!PyArg_ParseTuple(args, ":getptr")) | |
| 417 return NULL; | |
| 418 | |
| 419 if (self->x_mode == O_RDONLY) | |
| 420 req = SNDCTL_DSP_GETIPTR; | |
| 421 else | |
| 422 req = SNDCTL_DSP_GETOPTR; | |
| 423 if (ioctl(self->x_fd, req, &info) == -1) { | |
| 424 PyErr_SetFromErrno(LinuxAudioError); | |
| 425 return NULL; | |
| 426 } | |
| 427 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); | |
| 428 } | |
| 429 | |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 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
|
431 { "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
|
432 { "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
|
433 { "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
|
434 { "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
|
435 { "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
|
436 { "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
|
437 { "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
|
438 { "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
|
439 { "fileno", (PyCFunction)lad_fileno, METH_VARARGS }, |
| 15062 | 440 { "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
|
441 { NULL, NULL} /* sentinel */ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 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
|
446 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
447 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
|
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 PyTypeObject Ladtype = { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
451 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
|
452 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
|
453 "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
|
454 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
|
455 0, /*tp_itemsize*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
456 /* methods */ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
457 (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
|
458 0, /*tp_print*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
459 (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
|
460 0, /*tp_setattr*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
461 0, /*tp_compare*/ |
|
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
462 0, /*tp_repr*/ |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 }; |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 static PyObject * |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 ladopen(PyObject *self, PyObject *args) |
|
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 { |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
468 return (PyObject *)newladobject(args); |
|
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 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
|
472 { "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
|
473 { 0, 0 }, |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 }; |
|
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 void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13543
diff
changeset
|
477 initlinuxaudiodev(void) |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 { |
| 15062 | 479 PyObject *m; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
481 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
|
482 |
|
13427
618a7280f6be
Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
483 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
|
484 if (LinuxAudioError) |
| 15062 | 485 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
|
486 |
| 15062 | 487 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1) |
| 488 return; | |
| 489 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1) | |
| 490 return; | |
| 491 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1) | |
| 492 return; | |
| 493 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1) | |
| 494 return; | |
| 495 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1) | |
| 496 return; | |
| 497 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1) | |
| 498 return; | |
| 499 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1) | |
| 500 return; | |
| 501 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1) | |
| 502 return; | |
|
15095
c199460ccde9
Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents:
15062
diff
changeset
|
503 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
|
504 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 |
|
14346
5397fdf88ec2
Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents:
14306
diff
changeset
|
506 return; |
|
12191
e75ac292ef4c
This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 } |
