annotate Modules/linuxaudiodev.c @ 49955:878d40468c4e legacy-trunk

Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
author Vinay Sajip <vinay_sajip@yahoo.co.uk>
date Wed, 03 Dec 2008 23:22:58 +0000
parents 52294af4b663
children fd25030223b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
21 #else
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
22 #define O_RDONLY 00
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
39992
0c36410c39e8 Compilation problem caused by conflicting typedefs for uint32_t
Armin Rigo <arigo@tunes.org>
parents: 38489
diff changeset
31 #ifndef HAVE_STDINT_H
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 typedef unsigned long uint32_t;
39992
0c36410c39e8 Compilation problem caused by conflicting typedefs for uint32_t
Armin Rigo <arigo@tunes.org>
parents: 38489
diff changeset
33 #endif
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
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
35 #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
36 #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
37
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 #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
39 #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
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
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
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 typedef struct {
36221
a1b1e451d82e Fix icc warnings: extra semi-colon
Neal Norwitz <nnorwitz@gmail.com>
parents: 26453
diff changeset
45 PyObject_HEAD
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_fd; /* The open file */
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
47 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
48 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
49 int x_ocount; /* Output count */
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
50 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
51 } lad_t;
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
53 /* XXX several format defined in soundcard.h are not supported,
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
54 including _NE (native endian) options and S32 options
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
55 */
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
56
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 static struct {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
58 int a_bps;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
59 uint32_t a_fmt;
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
60 char *a_name;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 } audio_types[] = {
15900
1129e16a11df better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents: 15095
diff changeset
62 { 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
63 { 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
64 { 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
65 { 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
66 { 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
67 { 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
68 { 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
69 { 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
70 { 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
71 };
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
73 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
74
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 23295
diff changeset
75 static PyTypeObject Ladtype;
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 static PyObject *LinuxAudioError;
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 lad_t *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 newladobject(PyObject *arg)
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
82 lad_t *xp;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
83 int fd, afmts, imode;
26453
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
84 char *basedev = NULL;
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
85 char *mode = NULL;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
26453
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
87 /* Two ways to call linuxaudiodev.open():
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
88 open(device, mode) (for consistency with builtin open())
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
89 open(mode) (for backwards compatibility)
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
90 because the *first* argument is optional, parsing args is
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
91 a wee bit tricky. */
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
92 if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode))
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
93 return NULL;
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
94 if (mode == NULL) { /* only one arg supplied */
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
95 mode = basedev;
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
96 basedev = NULL;
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
97 }
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
98
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
99 if (strcmp(mode, "r") == 0)
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
100 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
101 else if (strcmp(mode, "w") == 0)
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
102 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
103 else {
15900
1129e16a11df better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents: 15095
diff changeset
104 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
105 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
106 }
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
108 /* Open the correct device. The base device name comes from the
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
109 * 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
110 * control device tacks "ctl" onto the base device name.
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
111 *
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
112 * Note that the only difference between /dev/audio and /dev/dsp
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
113 * is that the former uses logarithmic mu-law encoding and the
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
114 * 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
115 */
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
116
26453
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
117 if (basedev == NULL) { /* called with one arg */
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
118 basedev = getenv("AUDIODEV");
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
119 if (basedev == NULL) /* $AUDIODEV not set */
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
120 basedev = "/dev/dsp";
60e57797b8e6 Allow the device name to be passed to linuxaudiodev.open(), for
Greg Ward <gward@python.net>
parents: 24280
diff changeset
121 }
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
122
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
123 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
124 PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
125 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
126 }
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
127 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
128 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
129 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
130 }
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
131 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
132 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
133 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
134 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
135 /* 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
136 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
137 close(fd);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
138 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
139 }
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
140 xp->x_fd = fd;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
141 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
142 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
143 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
144 return xp;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 static void
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 lad_dealloc(lad_t *xp)
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 {
14057
ca8dc1bae67d lad_dealloc(): if xp->x_fd == -1, it means the descriptor's already
Barry Warsaw <barry@python.org>
parents: 13651
diff changeset
150 /* 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
151 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
152 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
153 PyObject_Del(xp);
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 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
158 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
159 int size, count;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
160 char *cp;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
161 PyObject *rv;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
162
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
163 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
164 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
165 rv = PyString_FromStringAndSize(NULL, size);
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
166 if (rv == NULL)
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
167 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
168 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
169 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
170 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
171 Py_DECREF(rv);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
172 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
173 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
174 self->x_icount += count;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
175 _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
176 return rv;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
178
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 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
181 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
182 char *cp;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
183 int rv, size;
17302
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
184 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
185 struct timeval tv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
186 int select_retval;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
187
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
188 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
189 return NULL;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
190
17302
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
191 /* 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
192 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
193 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
194 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
195 tv.tv_usec = 0;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
196
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
197 while (size > 0) {
17302
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
198 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
199 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
200 if (select_retval) {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
201 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
202 if (errno != EAGAIN) {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
203 PyErr_SetFromErrno(LinuxAudioError);
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
204 return NULL;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
205 } else {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
206 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
207 }
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
208 } else {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
209 self->x_ocount += rv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
210 size -= rv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
211 cp += rv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
212 }
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
213 } else {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
214 /* 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
215 PyErr_SetFromErrno(LinuxAudioError);
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
216 return NULL;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
217 }
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 }
13427
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 *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
224 lad_close(lad_t *self, PyObject *unused)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
226 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
227 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
228 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
229 }
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
230 Py_RETURN_NONE;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
232
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
234 lad_fileno(lad_t *self, PyObject *unused)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
236 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
237 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
238
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 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
241 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
242 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
243
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
244 if (!PyArg_ParseTuple(args, "iiii|i:setparameters",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
245 &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
246 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
247
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
248 if (rate < 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
249 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
250 rate);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
251 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
252 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
253 if (ssize < 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
254 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
255 ssize);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
256 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
257 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
258 if (nchannels != 1 && nchannels != 2) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
259 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
260 nchannels);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
261 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
262 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
263
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
264 for (n = 0; n < n_audio_types; n++)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
265 if (fmt == audio_types[n].a_fmt)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
266 break;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
267 if (n == n_audio_types) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
268 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
269 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
270 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
271 if (audio_types[n].a_bps != ssize) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
272 PyErr_Format(PyExc_ValueError,
15900
1129e16a11df better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents: 15095
diff changeset
273 "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
274 audio_types[n].a_name, audio_types[n].a_bps, ssize);
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
275 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
276 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
277
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
278 if (emulate == 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
279 if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
280 PyErr_Format(PyExc_ValueError,
15900
1129e16a11df better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents: 15095
diff changeset
281 "%s format not supported by device",
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
282 audio_types[n].a_name);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
283 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
284 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
285 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
286 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
287 &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
288 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
289 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
290 }
21312
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
291 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
292 PyErr_SetFromErrno(LinuxAudioError);
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
293 return NULL;
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
294 }
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
295 if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) {
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
296 PyErr_SetFromErrno(LinuxAudioError);
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
297 return NULL;
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
298 }
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
299
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
300 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
301 return Py_None;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
303
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 static int
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 _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
306 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
307 int fmt;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
308
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
309 fmt = 0;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
310 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
311 return -errno;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
312
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
313 switch (fmt) {
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
314 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
315 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
316 case AFMT_U8:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
317 case AFMT_S8:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
318 *ssize = sizeof(char);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
319 break;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
320 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
321 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
322 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
323 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
324 *ssize = sizeof(short);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
325 break;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
326 case AFMT_MPEG:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
327 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
328 default:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
329 return -EOPNOTSUPP;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
330 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
331 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
332 return -errno;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
333 return 0;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 /* 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
338 of samples */
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
340 lad_bufsize(lad_t *self, PyObject *unused)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
342 audio_buf_info ai;
36785
6e285c69efc0 Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
343 int nchannels=0, ssize=0;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
344
36785
6e285c69efc0 Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
345 if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
346 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
347 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
348 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
349 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
350 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
351 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
352 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
353 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
354 }
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 /* 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
357 hardware for playing */
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
359 lad_obufcount(lad_t *self, PyObject *unused)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
361 audio_buf_info ai;
36785
6e285c69efc0 Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
362 int nchannels=0, ssize=0;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
363
36785
6e285c69efc0 Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
364 if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
365 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
366 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
367 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
368 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
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 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
373 (ssize * nchannels));
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
375
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 /* 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
377 blocking */
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
379 lad_obuffree(lad_t *self, PyObject *unused)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
381 audio_buf_info ai;
36785
6e285c69efc0 Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
382 int nchannels=0, ssize=0;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
383
36785
6e285c69efc0 Rework channelnumber/samplesize detetion code's output variables a bit to
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
384 if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
385 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
386 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
387 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
388 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
389 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
390 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
391 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
392 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
393 }
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 /* Flush the device */
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
397 lad_flush(lad_t *self, PyObject *unused)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
399 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
400 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
401 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
402 }
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
403 Py_RETURN_NONE;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
405
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
406 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
407 lad_getptr(lad_t *self, PyObject *unused)
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
408 {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
409 count_info info;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
410 int req;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
411
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
412 if (self->x_mode == O_RDONLY)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
413 req = SNDCTL_DSP_GETIPTR;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
414 else
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
415 req = SNDCTL_DSP_GETOPTR;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
416 if (ioctl(self->x_fd, req, &info) == -1) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
417 PyErr_SetFromErrno(LinuxAudioError);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
418 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
419 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
420 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
421 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
422
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 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
424 { "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
425 { "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
426 { "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
427 { "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS },
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
428 { "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS },
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
429 { "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS },
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
430 { "flush", (PyCFunction)lad_flush, METH_NOARGS },
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
431 { "close", (PyCFunction)lad_close, METH_NOARGS },
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
432 { "fileno", (PyCFunction)lad_fileno, METH_NOARGS },
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 36785
diff changeset
433 { "getptr", (PyCFunction)lad_getptr, METH_NOARGS },
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
434 { NULL, NULL} /* sentinel */
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 };
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
436
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 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
439 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
440 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
441 }
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 static PyTypeObject Ladtype = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 39992
diff changeset
444 PyVarObject_HEAD_INIT(&PyType_Type, 0)
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 21312
diff changeset
445 "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
446 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
447 0, /*tp_itemsize*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
448 /* methods */
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
449 (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
450 0, /*tp_print*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
451 (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
452 0, /*tp_setattr*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
453 0, /*tp_compare*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
454 0, /*tp_repr*/
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 };
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
456
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
457 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 ladopen(PyObject *self, PyObject *args)
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
460 return (PyObject *)newladobject(args);
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
462
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 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
464 { "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
465 { 0, 0 },
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 };
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
467
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13543
diff changeset
469 initlinuxaudiodev(void)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
470 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
471 PyObject *m;
46851
1e427bc0f818 The linuxaudidev module has been deprecated for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 42334
diff changeset
472
1e427bc0f818 The linuxaudidev module has been deprecated for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 42334
diff changeset
473 if (PyErr_WarnPy3k("the linuxaudiodev module has been removed in "
1e427bc0f818 The linuxaudidev module has been deprecated for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 42334
diff changeset
474 "Python 3.0; use the ossaudiodev module instead", 2) < 0)
1e427bc0f818 The linuxaudidev module has been deprecated for removal in Python 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 42334
diff changeset
475 return;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
476
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
477 m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36221
diff changeset
478 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36221
diff changeset
479 return;
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 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
482 if (LinuxAudioError)
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
483 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
484
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
485 if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
486 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
487 if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
488 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
489 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
490 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
491 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
492 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
493 if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
494 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
495 if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
496 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
497 if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
498 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
499 if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
500 return;
15095
c199460ccde9 Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents: 15062
diff changeset
501 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
502 return;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
503
14346
5397fdf88ec2 Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents: 14306
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 }