annotate Modules/linuxaudiodev.c @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents e223397b26fa
children 6fa76b4e59fe
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
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
51 /* XXX several format defined in soundcard.h are not supported,
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
52 including _NE (native endian) options and S32 options
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
53 */
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 staticforward PyTypeObject Ladtype;
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
99 *
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
100 * Note that the only difference between /dev/audio and /dev/dsp
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
101 * is that the former uses logarithmic mu-law encoding and the
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
126 xp->x_fd = fd;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
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;
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
161 if (_PyString_Resize(&rv, count) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
162 return NULL;
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
163 return rv;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 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
168 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
169 char *cp;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
170 int rv, size;
17302
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
171 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
172 struct timeval tv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
173 int select_retval;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
174
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
175 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
176 return NULL;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
17302
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
178 /* 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
179 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
180 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
181 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
182 tv.tv_usec = 0;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
183
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
184 while (size > 0) {
17302
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
185 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
186 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
187 if (select_retval) {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
188 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
189 if (errno != EAGAIN) {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
190 PyErr_SetFromErrno(LinuxAudioError);
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
191 return NULL;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
192 } else {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
193 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
194 }
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
195 } else {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
196 self->x_ocount += rv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
197 size -= rv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
198 cp += rv;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
199 }
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
200 } else {
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
201 /* 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
202 PyErr_SetFromErrno(LinuxAudioError);
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
203 return NULL;
03ba06247486 Applying SF patch #412553 by Christopher Lee: fix linuxaudiodev
Guido van Rossum <guido@python.org>
parents: 15958
diff changeset
204 }
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 }
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
206 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
207 return Py_None;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 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
212 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
213 if (!PyArg_ParseTuple(args, ":close"))
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
214 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
215
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
216 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
217 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
218 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
219 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
220 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
221 return Py_None;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 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
226 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
227 if (!PyArg_ParseTuple(args, ":fileno"))
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
228 return NULL;
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
229 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
230 }
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 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 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
234 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
235 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
236
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
237 if (!PyArg_ParseTuple(args, "iiii|i:setparameters",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
238 &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
239 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
240
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
241 if (rate < 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
242 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
243 rate);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
244 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
245 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
246 if (ssize < 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
247 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
248 ssize);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
249 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
250 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
251 if (nchannels != 1 && nchannels != 2) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
252 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
253 nchannels);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
254 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
255 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
256
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
257 for (n = 0; n < n_audio_types; n++)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
258 if (fmt == audio_types[n].a_fmt)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
259 break;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
260 if (n == n_audio_types) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
261 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
262 return NULL;
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 if (audio_types[n].a_bps != ssize) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
265 PyErr_Format(PyExc_ValueError,
15900
1129e16a11df better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents: 15095
diff changeset
266 "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
267 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
268 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
269 }
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 (emulate == 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
272 if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
273 PyErr_Format(PyExc_ValueError,
15900
1129e16a11df better format names and error messages
Ka-Ping Yee <ping@zesty.ca>
parents: 15095
diff changeset
274 "%s format not supported by device",
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
275 audio_types[n].a_name);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
276 return NULL;
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 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
279 if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
280 &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
281 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
282 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
283 }
21312
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
284 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
285 PyErr_SetFromErrno(LinuxAudioError);
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
286 return NULL;
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
287 }
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
288 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
289 PyErr_SetFromErrno(LinuxAudioError);
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
290 return NULL;
0102692417af SF patch #489989 (Charles G Waldman) linuxaudiodev.c - fix initialization
Guido van Rossum <guido@python.org>
parents: 17302
diff changeset
291 }
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
292
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
293 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
294 return Py_None;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 static int
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 _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
299 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
300 int fmt;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
301
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
302 fmt = 0;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
303 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
304 return -errno;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
305
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
306 switch (fmt) {
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
307 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
308 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
309 case AFMT_U8:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
310 case AFMT_S8:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
311 *ssize = sizeof(char);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
312 break;
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_LE:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
314 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
315 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
316 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
317 *ssize = sizeof(short);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
318 break;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
319 case AFMT_MPEG:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
320 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
321 default:
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
322 return -EOPNOTSUPP;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
323 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
324 *nchannels = 0;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
325 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
326 return -errno;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
327 return 0;
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 /* 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
332 of samples */
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 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
335 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
336 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
337 int nchannels, ssize;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
338
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
339 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
340
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
341 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
342 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
343 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
344 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
345 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
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 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
350 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
351
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 /* 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
353 hardware for playing */
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 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
356 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
357 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
358 int nchannels, ssize;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
360 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
361 return NULL;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
362
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
363 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
364 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
365 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
366 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
367 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
368 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
369 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
370 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
371 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
372 (ssize * nchannels));
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 /* 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
376 blocking */
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 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
379 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
380 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
381 int nchannels, ssize;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
382
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
383 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
384 return NULL;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
385
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
386 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
387 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
388 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
389 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
390 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
391 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
392 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
393 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
394 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
395 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
396
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 /* Flush the device */
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 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
400 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
401 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
402
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
403 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
404 PyErr_SetFromErrno(LinuxAudioError);
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
405 return NULL;
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
406 }
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
407 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
408 return Py_None;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
410
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
411 static PyObject *
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
412 lad_getptr(lad_t *self, PyObject *args)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
413 {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
414 count_info info;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
415 int req;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
416
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
417 if (!PyArg_ParseTuple(args, ":getptr"))
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 if (self->x_mode == O_RDONLY)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
421 req = SNDCTL_DSP_GETIPTR;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
422 else
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
423 req = SNDCTL_DSP_GETOPTR;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
424 if (ioctl(self->x_fd, req, &info) == -1) {
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
425 PyErr_SetFromErrno(LinuxAudioError);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
426 return NULL;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
427 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
428 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
429 }
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
430
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 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
432 { "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
433 { "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
434 { "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
435 { "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
436 { "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
437 { "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
438 { "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
439 { "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
440 { "fileno", (PyCFunction)lad_fileno, METH_VARARGS },
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
441 { "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
442 { NULL, NULL} /* sentinel */
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 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
447 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
448 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
449 }
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
450
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 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
452 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
453 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
454 "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
455 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
456 0, /*tp_itemsize*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
457 /* methods */
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
458 (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
459 0, /*tp_print*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
460 (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
461 0, /*tp_setattr*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
462 0, /*tp_compare*/
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
463 0, /*tp_repr*/
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
466 static PyObject *
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
467 ladopen(PyObject *self, PyObject *args)
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 {
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
469 return (PyObject *)newladobject(args);
12191
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
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 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
473 { "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
474 { 0, 0 },
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 };
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
476
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 void
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13543
diff changeset
478 initlinuxaudiodev(void)
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 {
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
480 PyObject *m;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
481
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
482 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
483
13427
618a7280f6be Add method names to PyArg_ParseTuple() calls for better error messages.
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
484 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
485 if (LinuxAudioError)
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
486 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
487
15062
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
488 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
489 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
490 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
491 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
492 if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
493 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
494 if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1)
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
495 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
496 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
497 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
498 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
499 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
500 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
501 return;
675748378c81 test_linuxaudio:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 14351
diff changeset
502 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
503 return;
15095
c199460ccde9 Be consistent in the description of audio formats: <format> <width>
Guido van Rossum <guido@python.org>
parents: 15062
diff changeset
504 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
505 return;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
506
14346
5397fdf88ec2 Do the absolute minimal amount of modifications to eradicate
Barry Warsaw <barry@python.org>
parents: 14306
diff changeset
507 return;
12191
e75ac292ef4c This module's name should be linuxaudio*dev*.c
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 }