blob: 05c4bef97d2659c14de3e20ec8021fe748c27e67 [file] [log] [blame]
Guido van Rossume3db8621991-09-09 23:33:34 +00001
Guido van Rossumd641d671997-04-03 17:06:32 +00002#define OLD_INTERFACE /* define for pre-Irix 6 interface */
Jack Jansene8a3c281993-02-10 14:10:56 +00003
Roger E. Massea2a8b271997-01-03 22:40:34 +00004#include "Python.h"
Guido van Rossumd641d671997-04-03 17:06:32 +00005#include "stringobject.h"
6#include <audio.h>
7#include <stdarg.h>
Guido van Rossume3db8621991-09-09 23:33:34 +00008
Guido van Rossumd641d671997-04-03 17:06:32 +00009#ifndef AL_NO_ELEM
10#ifndef OLD_INTERFACE
11#define OLD_INTERFACE
12#endif /* OLD_INTERFACE */
13#endif /* AL_NO_ELEM */
14
15static PyObject *ErrorObject;
16
17/* ----------------------------------------------------- */
18
19/* Declarations for objects of type port */
Guido van Rossume3db8621991-09-09 23:33:34 +000020
21typedef struct {
Roger E. Massea2a8b271997-01-03 22:40:34 +000022 PyObject_HEAD
Guido van Rossumd641d671997-04-03 17:06:32 +000023 /* XXXX Add your own stuff here */
24 ALport port;
25} alpobject;
Guido van Rossume3db8621991-09-09 23:33:34 +000026
Guido van Rossumd641d671997-04-03 17:06:32 +000027staticforward PyTypeObject Alptype;
Guido van Rossume3db8621991-09-09 23:33:34 +000028
Guido van Rossume3db8621991-09-09 23:33:34 +000029
Guido van Rossumd641d671997-04-03 17:06:32 +000030
31/* ---------------------------------------------------------------- */
32
33/* Declarations for objects of type config */
34
35typedef struct {
36 PyObject_HEAD
37 /* XXXX Add your own stuff here */
38 ALconfig config;
39} alcobject;
40
41staticforward PyTypeObject Alctype;
42
43
44static void
45ErrorHandler(long code, const char *fmt, ...)
46{
47 va_list args;
48 char buf[128];
49
50 va_start(args, fmt);
51 vsprintf(buf, fmt, args);
52 va_end(args);
53 PyErr_SetString(ErrorObject, buf);
54}
55
56#ifdef AL_NO_ELEM /* IRIX 6 */
Guido van Rossumfc58e581992-01-27 16:45:55 +000057
Roger E. Massea2a8b271997-01-03 22:40:34 +000058static PyObject *
Guido van Rossumd641d671997-04-03 17:06:32 +000059param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo)
60{
61 ALparamInfo info;
62 PyObject *v;
63
64 if (pinfo == NULL) {
65 pinfo = &info;
66 if (alGetParamInfo(resource, param, &info) < 0)
67 return NULL;
68 }
69 switch (pinfo->elementType) {
70 case AL_PTR_ELEM:
71 /* XXXX don't know how to handle this */
72 case AL_NO_ELEM:
73 Py_INCREF(Py_None);
74 return Py_None;
75 case AL_INT32_ELEM:
76 case AL_RESOURCE_ELEM:
77 case AL_ENUM_ELEM:
78 return PyInt_FromLong((long) value.i);
79 case AL_INT64_ELEM:
80 return PyLong_FromLongLong(value.ll);
81 case AL_FIXED_ELEM:
82 return PyFloat_FromDouble(alFixedToDouble(value.ll));
83 case AL_CHAR_ELEM:
84 if (value.ptr == NULL) {
85 Py_INCREF(Py_None);
86 return Py_None;
87 }
88 return PyString_FromString((char *) value.ptr);
89 default:
90 PyErr_SetString(ErrorObject, "unknown element type");
91 return NULL;
92 }
93}
94
95static int
96python2elem(PyObject *item, void *ptr, int elementType)
97{
98 switch (elementType) {
99 case AL_INT32_ELEM:
100 case AL_RESOURCE_ELEM:
101 case AL_ENUM_ELEM:
102 if (!PyInt_Check(item)) {
103 PyErr_BadArgument();
104 return -1;
105 }
106 *((int *) ptr) = PyInt_AsLong(item);
107 break;
108 case AL_INT64_ELEM:
109 if (PyInt_Check(item))
110 *((long long *) ptr) = PyInt_AsLong(item);
111 else if (PyLong_Check(item))
112 *((long long *) ptr) = PyLong_AsLongLong(item);
113 else {
114 PyErr_BadArgument();
115 return -1;
116 }
117 break;
118 case AL_FIXED_ELEM:
119 if (PyInt_Check(item))
120 *((long long *) ptr) = alDoubleToFixed((double) PyInt_AsLong(item));
121 else if (PyFloat_Check(item))
122 *((long long *) ptr) = alDoubleToFixed(PyFloat_AsDouble(item));
123 else {
124 PyErr_BadArgument();
125 return -1;
126 }
127 break;
128 default:
129 PyErr_SetString(ErrorObject, "unknown element type");
130 return -1;
131 }
132 return 0;
133}
134
135static int
136python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo)
137{
138 ALparamInfo info;
139 int i, stepsize;
140 PyObject *item;
141
142 if (pinfo == NULL) {
143 pinfo = &info;
144 if (alGetParamInfo(resource, param->param, &info) < 0)
145 return -1;
146 }
147 switch (pinfo->valueType) {
148 case AL_STRING_VAL:
149 if (pinfo->elementType != AL_CHAR_ELEM) {
150 PyErr_SetString(ErrorObject, "unknown element type");
151 return -1;
152 }
153 if (!PyString_Check(value)) {
154 PyErr_BadArgument();
155 return -1;
156 }
157 param->value.ptr = PyString_AS_STRING(value);
158 param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/
159 break;
160 case AL_SET_VAL:
161 case AL_VECTOR_VAL:
162 if (!PyList_Check(value) && !PyTuple_Check(value)) {
163 PyErr_BadArgument();
164 return -1;
165 }
166 switch (pinfo->elementType) {
167 case AL_INT32_ELEM:
168 case AL_RESOURCE_ELEM:
169 case AL_ENUM_ELEM:
Jeremy Hylton03657cf2000-07-12 13:05:33 +0000170 param->sizeIn = PySequence_Size(value);
Guido van Rossumd641d671997-04-03 17:06:32 +0000171 param->value.ptr = PyMem_NEW(int, param->sizeIn);
172 stepsize = sizeof(int);
173 break;
174 case AL_INT64_ELEM:
175 case AL_FIXED_ELEM:
Jeremy Hylton03657cf2000-07-12 13:05:33 +0000176 param->sizeIn = PySequence_Size(value);
Guido van Rossumd641d671997-04-03 17:06:32 +0000177 param->value.ptr = PyMem_NEW(long long, param->sizeIn);
178 stepsize = sizeof(long long);
179 break;
180 }
181 for (i = 0; i < param->sizeIn; i++) {
182 item = PySequence_GetItem(value, i);
183 if (python2elem(item, (void *) ((char *) param->value.ptr + i*stepsize), pinfo->elementType) < 0) {
184 PyMem_DEL(param->value.ptr);
185 return -1;
186 }
187 }
188 break;
189 case AL_SCALAR_VAL:
190 switch (pinfo->elementType) {
191 case AL_INT32_ELEM:
192 case AL_RESOURCE_ELEM:
193 case AL_ENUM_ELEM:
194 return python2elem(value, (void *) &param->value.i,
195 pinfo->elementType);
Guido van Rossumd641d671997-04-03 17:06:32 +0000196 case AL_INT64_ELEM:
197 case AL_FIXED_ELEM:
198 return python2elem(value, (void *) &param->value.ll,
199 pinfo->elementType);
Guido van Rossumd641d671997-04-03 17:06:32 +0000200 default:
201 PyErr_SetString(ErrorObject, "unknown element type");
202 return -1;
203 }
204 }
205 return 0;
206}
207
208static int
209python2params(int resource1, int resource2, PyObject *list, ALpv **pvsp, ALparamInfo **pinfop)
210{
211 PyObject *item;
212 ALpv *pvs;
213 ALparamInfo *pinfo;
214 int npvs, i;
215
216 npvs = PyList_Size(list);
217 pvs = PyMem_NEW(ALpv, npvs);
218 pinfo = PyMem_NEW(ALparamInfo, npvs);
219 for (i = 0; i < npvs; i++) {
220 item = PyList_GetItem(list, i);
221 if (!PyArg_ParseTuple(item, "iO", &pvs[i].param, &item))
222 goto error;
223 if (alGetParamInfo(resource1, pvs[i].param, &pinfo[i]) < 0 &&
224 alGetParamInfo(resource2, pvs[i].param, &pinfo[i]) < 0)
225 goto error;
226 if (python2param(resource1, &pvs[i], item, &pinfo[i]) < 0)
227 goto error;
228 }
229
230 *pvsp = pvs;
231 *pinfop = pinfo;
232 return npvs;
233
234 error:
235 /* XXXX we should clean up everything */
236 if (pvs)
237 PyMem_DEL(pvs);
238 if (pinfo)
239 PyMem_DEL(pinfo);
240 return -1;
241}
242
243/* -------------------------------------------------------- */
244
245
246static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000247SetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig, int))
Guido van Rossumd641d671997-04-03 17:06:32 +0000248{
249 int par;
250
Guido van Rossum43713e52000-02-29 13:59:29 +0000251 if (!PyArg_ParseTuple(args, "i:SetConfig", &par))
Guido van Rossumd641d671997-04-03 17:06:32 +0000252 return NULL;
253
254 if ((*func)(self->config, par) == -1)
255 return NULL;
256
257 Py_INCREF(Py_None);
Roger E. Massea2a8b271997-01-03 22:40:34 +0000258 return Py_None;
Guido van Rossume3db8621991-09-09 23:33:34 +0000259}
260
Roger E. Massea2a8b271997-01-03 22:40:34 +0000261static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000262GetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig))
Guido van Rossumd641d671997-04-03 17:06:32 +0000263{
264 int par;
265
Guido van Rossum43713e52000-02-29 13:59:29 +0000266 if (!PyArg_ParseTuple(args, ":GetConfig"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000267 return NULL;
268
269 if ((par = (*func)(self->config)) == -1)
270 return NULL;
271
272 return PyInt_FromLong((long) par);
273}
274
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000275PyDoc_STRVAR(alc_SetWidth__doc__,
276"alSetWidth: set the wordsize for integer audio data.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000277
278static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000279alc_SetWidth(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000280{
281 return SetConfig(self, args, alSetWidth);
282}
283
284
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000285PyDoc_STRVAR(alc_GetWidth__doc__,
286"alGetWidth: get the wordsize for integer audio data.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000287
288static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000289alc_GetWidth(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000290{
291 return GetConfig(self, args, alGetWidth);
292}
293
294
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000295PyDoc_STRVAR(alc_SetSampFmt__doc__,
296"alSetSampFmt: set the sample format setting in an audio ALconfig "
297"structure.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000298
299static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000300alc_SetSampFmt(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000301{
302 return SetConfig(self, args, alSetSampFmt);
303}
304
305
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000306PyDoc_STRVAR(alc_GetSampFmt__doc__,
307"alGetSampFmt: get the sample format setting in an audio ALconfig "
308"structure.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000309
310static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000311alc_GetSampFmt(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000312{
313 return GetConfig(self, args, alGetSampFmt);
314}
315
316
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000317PyDoc_STRVAR(alc_SetChannels__doc__,
318"alSetChannels: set the channel settings in an audio ALconfig.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000319
320static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000321alc_SetChannels(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000322{
323 return SetConfig(self, args, alSetChannels);
324}
325
326
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000327PyDoc_STRVAR(alc_GetChannels__doc__,
328"alGetChannels: get the channel settings in an audio ALconfig.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000329
330static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000331alc_GetChannels(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000332{
333 return GetConfig(self, args, alGetChannels);
334}
335
336
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000337PyDoc_STRVAR(alc_SetFloatMax__doc__,
338"alSetFloatMax: set the maximum value of floating point sample data.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000339
340static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000341alc_SetFloatMax(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000342{
343 double maximum_value;
344
Guido van Rossum43713e52000-02-29 13:59:29 +0000345 if (!PyArg_ParseTuple(args, "d:SetFloatMax", &maximum_value))
Guido van Rossumd641d671997-04-03 17:06:32 +0000346 return NULL;
347 if (alSetFloatMax(self->config, maximum_value) < 0)
348 return NULL;
349 Py_INCREF(Py_None);
350 return Py_None;
351}
352
353
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000354PyDoc_STRVAR(alc_GetFloatMax__doc__,
355"alGetFloatMax: get the maximum value of floating point sample data.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000356
357static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000358alc_GetFloatMax(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000359{
360 double maximum_value;
361
Guido van Rossum43713e52000-02-29 13:59:29 +0000362 if (!PyArg_ParseTuple(args, ":GetFloatMax"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000363 return NULL;
364 if ((maximum_value = alGetFloatMax(self->config)) == 0)
365 return NULL;
366 return PyFloat_FromDouble(maximum_value);
367}
368
369
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000370PyDoc_STRVAR(alc_SetDevice__doc__,
371"alSetDevice: set the device setting in an audio ALconfig structure.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000372
373static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000374alc_SetDevice(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000375{
376 return SetConfig(self, args, alSetDevice);
377}
378
379
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000380PyDoc_STRVAR(alc_GetDevice__doc__,
381"alGetDevice: get the device setting in an audio ALconfig structure.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000382
383static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000384alc_GetDevice(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000385{
386 return GetConfig(self, args, alGetDevice);
387}
388
389
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000390PyDoc_STRVAR(alc_SetQueueSize__doc__,
391"alSetQueueSize: set audio port buffer size.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000392
393static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000394alc_SetQueueSize(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000395{
396 return SetConfig(self, args, alSetQueueSize);
397}
398
399
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000400PyDoc_STRVAR(alc_GetQueueSize__doc__,
401"alGetQueueSize: get audio port buffer size.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000402
403static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000404alc_GetQueueSize(alcobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000405{
406 return GetConfig(self, args, alGetQueueSize);
407}
408
409#endif /* AL_NO_ELEM */
410
411static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000412setconfig(alcobject *self, PyObject *args, int (*func)(ALconfig, long))
Guido van Rossumd641d671997-04-03 17:06:32 +0000413{
414 long par;
415
Guido van Rossum43713e52000-02-29 13:59:29 +0000416 if (!PyArg_ParseTuple(args, "l:SetConfig", &par))
Guido van Rossumd641d671997-04-03 17:06:32 +0000417 return NULL;
418
419 if ((*func)(self->config, par) == -1)
420 return NULL;
421
422 Py_INCREF(Py_None);
423 return Py_None;
424}
425
426static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000427getconfig(alcobject *self, PyObject *args, long (*func)(ALconfig))
Guido van Rossume3db8621991-09-09 23:33:34 +0000428{
429 long par;
430
Guido van Rossum43713e52000-02-29 13:59:29 +0000431 if (!PyArg_ParseTuple(args, ":GetConfig"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000432 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000433
Guido van Rossumd641d671997-04-03 17:06:32 +0000434 if ((par = (*func)(self->config)) == -1)
435 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000436
Guido van Rossumd641d671997-04-03 17:06:32 +0000437 return PyInt_FromLong((long) par);
Guido van Rossume3db8621991-09-09 23:33:34 +0000438}
439
Roger E. Massea2a8b271997-01-03 22:40:34 +0000440static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000441alc_setqueuesize (alcobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000442{
Guido van Rossumd641d671997-04-03 17:06:32 +0000443 return setconfig(self, args, ALsetqueuesize);
Guido van Rossume3db8621991-09-09 23:33:34 +0000444}
445
Roger E. Massea2a8b271997-01-03 22:40:34 +0000446static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000447alc_getqueuesize (alcobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000448{
Guido van Rossumd641d671997-04-03 17:06:32 +0000449 return getconfig(self, args, ALgetqueuesize);
Guido van Rossume3db8621991-09-09 23:33:34 +0000450}
451
Roger E. Massea2a8b271997-01-03 22:40:34 +0000452static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000453alc_setwidth (alcobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000454{
Guido van Rossumd641d671997-04-03 17:06:32 +0000455 return setconfig(self, args, ALsetwidth);
Guido van Rossume3db8621991-09-09 23:33:34 +0000456}
457
Roger E. Massea2a8b271997-01-03 22:40:34 +0000458static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000459alc_getwidth (alcobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000460{
Guido van Rossumd641d671997-04-03 17:06:32 +0000461 return getconfig(self, args, ALgetwidth);
Guido van Rossume3db8621991-09-09 23:33:34 +0000462}
463
Roger E. Massea2a8b271997-01-03 22:40:34 +0000464static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000465alc_getchannels (alcobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000466{
Guido van Rossumd641d671997-04-03 17:06:32 +0000467 return getconfig(self, args, ALgetchannels);
Guido van Rossume3db8621991-09-09 23:33:34 +0000468}
469
Roger E. Massea2a8b271997-01-03 22:40:34 +0000470static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000471alc_setchannels (alcobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000472{
Guido van Rossumd641d671997-04-03 17:06:32 +0000473 return setconfig(self, args, ALsetchannels);
Guido van Rossume3db8621991-09-09 23:33:34 +0000474}
475
Jack Jansene8a3c281993-02-10 14:10:56 +0000476#ifdef AL_405
477
Roger E. Massea2a8b271997-01-03 22:40:34 +0000478static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000479alc_getsampfmt (alcobject *self, PyObject *args)
Jack Jansene8a3c281993-02-10 14:10:56 +0000480{
Guido van Rossumd641d671997-04-03 17:06:32 +0000481 return getconfig(self, args, ALgetsampfmt);
Jack Jansene8a3c281993-02-10 14:10:56 +0000482}
483
Roger E. Massea2a8b271997-01-03 22:40:34 +0000484static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000485alc_setsampfmt (alcobject *self, PyObject *args)
Jack Jansene8a3c281993-02-10 14:10:56 +0000486{
Guido van Rossumd641d671997-04-03 17:06:32 +0000487 return setconfig(self, args, ALsetsampfmt);
Jack Jansene8a3c281993-02-10 14:10:56 +0000488}
489
Roger E. Massea2a8b271997-01-03 22:40:34 +0000490static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000491alc_getfloatmax(alcobject *self, PyObject *args)
Jack Jansene8a3c281993-02-10 14:10:56 +0000492{
493 double arg;
494
Guido van Rossum43713e52000-02-29 13:59:29 +0000495 if (!PyArg_ParseTuple(args, ":GetFloatMax"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000496 return 0;
497 if ((arg = ALgetfloatmax(self->config)) == 0)
498 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +0000499 return PyFloat_FromDouble(arg);
Jack Jansene8a3c281993-02-10 14:10:56 +0000500}
501
Roger E. Massea2a8b271997-01-03 22:40:34 +0000502static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000503alc_setfloatmax(alcobject *self, PyObject *args)
Jack Jansene8a3c281993-02-10 14:10:56 +0000504{
505 double arg;
506
Guido van Rossum43713e52000-02-29 13:59:29 +0000507 if (!PyArg_ParseTuple(args, "d:SetFloatMax", &arg))
Guido van Rossumd641d671997-04-03 17:06:32 +0000508 return 0;
509 if (ALsetfloatmax(self->config, arg) == -1)
510 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +0000511 Py_INCREF(Py_None);
512 return Py_None;
Jack Jansene8a3c281993-02-10 14:10:56 +0000513}
514#endif /* AL_405 */
515
Guido van Rossumd641d671997-04-03 17:06:32 +0000516static struct PyMethodDef alc_methods[] = {
517#ifdef AL_NO_ELEM /* IRIX 6 */
518 {"SetWidth", (PyCFunction)alc_SetWidth, METH_VARARGS, alc_SetWidth__doc__},
519 {"GetWidth", (PyCFunction)alc_GetWidth, METH_VARARGS, alc_GetWidth__doc__},
520 {"SetSampFmt", (PyCFunction)alc_SetSampFmt, METH_VARARGS, alc_SetSampFmt__doc__},
521 {"GetSampFmt", (PyCFunction)alc_GetSampFmt, METH_VARARGS, alc_GetSampFmt__doc__},
522 {"SetChannels", (PyCFunction)alc_SetChannels, METH_VARARGS, alc_SetChannels__doc__},
523 {"GetChannels", (PyCFunction)alc_GetChannels, METH_VARARGS, alc_GetChannels__doc__},
524 {"SetFloatMax", (PyCFunction)alc_SetFloatMax, METH_VARARGS, alc_SetFloatMax__doc__},
525 {"GetFloatMax", (PyCFunction)alc_GetFloatMax, METH_VARARGS, alc_GetFloatMax__doc__},
526 {"SetDevice", (PyCFunction)alc_SetDevice, METH_VARARGS, alc_SetDevice__doc__},
527 {"GetDevice", (PyCFunction)alc_GetDevice, METH_VARARGS, alc_GetDevice__doc__},
528 {"SetQueueSize", (PyCFunction)alc_SetQueueSize, METH_VARARGS, alc_SetQueueSize__doc__},
529 {"GetQueueSize", (PyCFunction)alc_GetQueueSize, METH_VARARGS, alc_GetQueueSize__doc__},
530#endif /* AL_NO_ELEM */
531 {"getqueuesize", (PyCFunction)alc_getqueuesize, METH_VARARGS},
532 {"setqueuesize", (PyCFunction)alc_setqueuesize, METH_VARARGS},
533 {"getwidth", (PyCFunction)alc_getwidth, METH_VARARGS},
534 {"setwidth", (PyCFunction)alc_setwidth, METH_VARARGS},
535 {"getchannels", (PyCFunction)alc_getchannels, METH_VARARGS},
536 {"setchannels", (PyCFunction)alc_setchannels, METH_VARARGS},
Jack Jansene8a3c281993-02-10 14:10:56 +0000537#ifdef AL_405
Guido van Rossumd641d671997-04-03 17:06:32 +0000538 {"getsampfmt", (PyCFunction)alc_getsampfmt, METH_VARARGS},
539 {"setsampfmt", (PyCFunction)alc_setsampfmt, METH_VARARGS},
540 {"getfloatmax", (PyCFunction)alc_getfloatmax, METH_VARARGS},
541 {"setfloatmax", (PyCFunction)alc_setfloatmax, METH_VARARGS},
Jack Jansene8a3c281993-02-10 14:10:56 +0000542#endif /* AL_405 */
Guido van Rossumd641d671997-04-03 17:06:32 +0000543
544 {NULL, NULL} /* sentinel */
Guido van Rossume3db8621991-09-09 23:33:34 +0000545};
546
Guido van Rossumd641d671997-04-03 17:06:32 +0000547/* ---------- */
548
549
550static PyObject *
551newalcobject(ALconfig config)
Guido van Rossume3db8621991-09-09 23:33:34 +0000552{
Guido van Rossumd641d671997-04-03 17:06:32 +0000553 alcobject *self;
554
Guido van Rossumb18618d2000-05-03 23:44:39 +0000555 self = PyObject_New(alcobject, &Alctype);
Guido van Rossumd641d671997-04-03 17:06:32 +0000556 if (self == NULL)
557 return NULL;
558 /* XXXX Add your own initializers here */
559 self->config = config;
560 return (PyObject *) self;
561}
562
563
564static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000565alc_dealloc(alcobject *self)
Guido van Rossumd641d671997-04-03 17:06:32 +0000566{
567 /* XXXX Add your own cleanup code here */
568#ifdef AL_NO_ELEM /* IRIX 6 */
569 (void) alFreeConfig(self->config); /* ignore errors */
570#else
571 (void) ALfreeconfig(self->config); /* ignore errors */
572#endif
Guido van Rossumb18618d2000-05-03 23:44:39 +0000573 PyObject_Del(self);
Guido van Rossume3db8621991-09-09 23:33:34 +0000574}
575
Roger E. Massea2a8b271997-01-03 22:40:34 +0000576static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000577alc_getattr(alcobject *self, char *name)
Guido van Rossume3db8621991-09-09 23:33:34 +0000578{
Guido van Rossumd641d671997-04-03 17:06:32 +0000579 /* XXXX Add your own getattr code here */
580 return Py_FindMethod(alc_methods, (PyObject *)self, name);
Guido van Rossume3db8621991-09-09 23:33:34 +0000581}
582
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000583PyDoc_STRVAR(Alctype__doc__, "");
Guido van Rossumd641d671997-04-03 17:06:32 +0000584
585static PyTypeObject Alctype = {
Roger E. Massea2a8b271997-01-03 22:40:34 +0000586 PyObject_HEAD_INIT(&PyType_Type)
Guido van Rossumd641d671997-04-03 17:06:32 +0000587 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +0000588 "al.config", /*tp_name*/
Guido van Rossumd641d671997-04-03 17:06:32 +0000589 sizeof(alcobject), /*tp_basicsize*/
590 0, /*tp_itemsize*/
Guido van Rossume3db8621991-09-09 23:33:34 +0000591 /* methods */
Guido van Rossumd641d671997-04-03 17:06:32 +0000592 (destructor)alc_dealloc, /*tp_dealloc*/
593 (printfunc)0, /*tp_print*/
594 (getattrfunc)alc_getattr, /*tp_getattr*/
595 (setattrfunc)0, /*tp_setattr*/
596 (cmpfunc)0, /*tp_compare*/
597 (reprfunc)0, /*tp_repr*/
598 0, /*tp_as_number*/
599 0, /*tp_as_sequence*/
600 0, /*tp_as_mapping*/
601 (hashfunc)0, /*tp_hash*/
602 (ternaryfunc)0, /*tp_call*/
603 (reprfunc)0, /*tp_str*/
604
605 /* Space for future expansion */
606 0L,0L,0L,0L,
607 Alctype__doc__ /* Documentation string */
Guido van Rossume3db8621991-09-09 23:33:34 +0000608};
609
Guido van Rossumd641d671997-04-03 17:06:32 +0000610/* End of code for config objects */
611/* ---------------------------------------------------------------- */
Guido van Rossume3db8621991-09-09 23:33:34 +0000612
Guido van Rossumd641d671997-04-03 17:06:32 +0000613#ifdef AL_NO_ELEM /* IRIX 6 */
Guido van Rossume3db8621991-09-09 23:33:34 +0000614
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000615PyDoc_STRVAR(alp_SetConfig__doc__,
616"alSetConfig: set the ALconfig of an audio ALport.");
Guido van Rossume3db8621991-09-09 23:33:34 +0000617
Roger E. Massea2a8b271997-01-03 22:40:34 +0000618static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000619alp_SetConfig(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000620{
Guido van Rossumd641d671997-04-03 17:06:32 +0000621 alcobject *config;
Guido van Rossum43713e52000-02-29 13:59:29 +0000622 if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
Guido van Rossumd641d671997-04-03 17:06:32 +0000623 return NULL;
624 if (alSetConfig(self->port, config->config) < 0)
625 return NULL;
626 Py_INCREF(Py_None);
Roger E. Massea2a8b271997-01-03 22:40:34 +0000627 return Py_None;
Guido van Rossume3db8621991-09-09 23:33:34 +0000628}
629
Guido van Rossumd641d671997-04-03 17:06:32 +0000630
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000631PyDoc_STRVAR(alp_GetConfig__doc__,
632"alGetConfig: get the ALconfig of an audio ALport.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000633
Roger E. Massea2a8b271997-01-03 22:40:34 +0000634static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000635alp_GetConfig(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000636{
637 ALconfig config;
Guido van Rossum43713e52000-02-29 13:59:29 +0000638 if (!PyArg_ParseTuple(args, ":GetConfig"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000639 return NULL;
640 if ((config = alGetConfig(self->port)) == NULL)
641 return NULL;
642 return newalcobject(config);
643}
644
645
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000646PyDoc_STRVAR(alp_GetResource__doc__,
647"alGetResource: get the resource associated with an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000648
649static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000650alp_GetResource(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000651{
652 int resource;
653
Guido van Rossum43713e52000-02-29 13:59:29 +0000654 if (!PyArg_ParseTuple(args, ":GetResource"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000655 return NULL;
656 if ((resource = alGetResource(self->port)) == 0)
657 return NULL;
658 return PyInt_FromLong((long) resource);
659}
660
661
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000662PyDoc_STRVAR(alp_GetFD__doc__,
663"alGetFD: get the file descriptor for an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000664
665static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000666alp_GetFD(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +0000667{
668 int fd;
669
Guido van Rossum43713e52000-02-29 13:59:29 +0000670 if (!PyArg_ParseTuple(args, ":GetFD"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000671 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000672
Guido van Rossumd641d671997-04-03 17:06:32 +0000673 if ((fd = alGetFD(self->port)) < 0)
674 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +0000675
Guido van Rossumd641d671997-04-03 17:06:32 +0000676 return PyInt_FromLong((long) fd);
677}
678
679
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000680PyDoc_STRVAR(alp_GetFilled__doc__,
681"alGetFilled: return the number of filled sample frames in "
682"an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000683
684static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000685alp_GetFilled(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000686{
687 int filled;
688
Guido van Rossum43713e52000-02-29 13:59:29 +0000689 if (!PyArg_ParseTuple(args, ":GetFilled"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000690 return NULL;
691 if ((filled = alGetFilled(self->port)) < 0)
692 return NULL;
693 return PyInt_FromLong((long) filled);
694}
695
696
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000697PyDoc_STRVAR(alp_GetFillable__doc__,
698"alGetFillable: report the number of unfilled sample frames "
699"in an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000700
701static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000702alp_GetFillable(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000703{
704 int fillable;
705
Guido van Rossum43713e52000-02-29 13:59:29 +0000706 if (!PyArg_ParseTuple(args, ":GetFillable"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000707 return NULL;
708 if ((fillable = alGetFillable(self->port)) < 0)
709 return NULL;
710 return PyInt_FromLong((long) fillable);
711}
712
713
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000714PyDoc_STRVAR(alp_ReadFrames__doc__,
715"alReadFrames: read sample frames from an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000716
717static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000718alp_ReadFrames(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000719{
720 void *samples;
721 int framecount;
722 PyObject *v;
723 int size;
724 int ch;
725 ALconfig c;
726
Guido van Rossum43713e52000-02-29 13:59:29 +0000727 if (!PyArg_ParseTuple(args, "i:ReadFrames", &framecount))
Guido van Rossumd641d671997-04-03 17:06:32 +0000728 return NULL;
729 if (framecount < 0) {
730 PyErr_SetString(ErrorObject, "negative framecount");
731 return NULL;
732 }
733 c = alGetConfig(self->port);
734 switch (alGetSampFmt(c)) {
735 case AL_SAMPFMT_TWOSCOMP:
736 switch (alGetWidth(c)) {
737 case AL_SAMPLE_8:
738 size = 1;
739 break;
740 case AL_SAMPLE_16:
741 size = 2;
742 break;
743 case AL_SAMPLE_24:
744 size = 4;
745 break;
746 default:
747 PyErr_SetString(ErrorObject, "can't determine width");
748 alFreeConfig(c);
749 return NULL;
750 }
751 break;
752 case AL_SAMPFMT_FLOAT:
753 size = 4;
754 break;
755 case AL_SAMPFMT_DOUBLE:
756 size = 8;
757 break;
758 default:
759 PyErr_SetString(ErrorObject, "can't determine format");
760 alFreeConfig(c);
761 return NULL;
762 }
763 ch = alGetChannels(c);
764 alFreeConfig(c);
765 if (ch < 0) {
766 PyErr_SetString(ErrorObject, "can't determine # of channels");
767 return NULL;
768 }
769 size *= ch;
770 v = PyString_FromStringAndSize((char *) NULL, size * framecount);
771 if (v == NULL)
772 return NULL;
773
774 Py_BEGIN_ALLOW_THREADS
775 alReadFrames(self->port, (void *) PyString_AS_STRING(v), framecount);
776 Py_END_ALLOW_THREADS
777
778 return v;
779}
780
781
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000782PyDoc_STRVAR(alp_DiscardFrames__doc__,
783"alDiscardFrames: discard audio from an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000784
785static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000786alp_DiscardFrames(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000787{
788 int framecount;
789
Guido van Rossum43713e52000-02-29 13:59:29 +0000790 if (!PyArg_ParseTuple(args, "i:DiscardFrames", &framecount))
Guido van Rossumd641d671997-04-03 17:06:32 +0000791 return NULL;
792
793 Py_BEGIN_ALLOW_THREADS
794 framecount = alDiscardFrames(self->port, framecount);
795 Py_END_ALLOW_THREADS
796
797 if (framecount < 0)
798 return NULL;
799
800 return PyInt_FromLong((long) framecount);
801}
802
803
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000804PyDoc_STRVAR(alp_ZeroFrames__doc__,
805"alZeroFrames: write zero-valued sample frames to an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000806
807static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000808alp_ZeroFrames(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000809{
810 int framecount;
811
Guido van Rossum43713e52000-02-29 13:59:29 +0000812 if (!PyArg_ParseTuple(args, "i:ZeroFrames", &framecount))
Guido van Rossumd641d671997-04-03 17:06:32 +0000813 return NULL;
814
815 if (framecount < 0) {
816 PyErr_SetString(ErrorObject, "negative framecount");
817 return NULL;
818 }
819
820 Py_BEGIN_ALLOW_THREADS
821 alZeroFrames(self->port, framecount);
822 Py_END_ALLOW_THREADS
823
824 Py_INCREF(Py_None);
825 return Py_None;
826}
827
828
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000829PyDoc_STRVAR(alp_SetFillPoint__doc__,
830"alSetFillPoint: set low- or high-water mark for an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000831
832static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000833alp_SetFillPoint(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000834{
835 int fillpoint;
836
Guido van Rossum43713e52000-02-29 13:59:29 +0000837 if (!PyArg_ParseTuple(args, "i:SetFillPoint", &fillpoint))
Guido van Rossumd641d671997-04-03 17:06:32 +0000838 return NULL;
839
840 if (alSetFillPoint(self->port, fillpoint) < 0)
841 return NULL;
842
843 Py_INCREF(Py_None);
844 return Py_None;
845}
846
847
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000848PyDoc_STRVAR(alp_GetFillPoint__doc__,
849"alGetFillPoint: get low- or high-water mark for an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000850
851static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000852alp_GetFillPoint(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000853{
854 int fillpoint;
855
Guido van Rossum43713e52000-02-29 13:59:29 +0000856 if (!PyArg_ParseTuple(args, ":GetFillPoint"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000857 return NULL;
858
859 if ((fillpoint = alGetFillPoint(self->port)) < 0)
860 return NULL;
861
862 return PyInt_FromLong((long) fillpoint);
863}
864
865
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000866PyDoc_STRVAR(alp_GetFrameNumber__doc__,
867"alGetFrameNumber: get the absolute sample frame number "
868"associated with a port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000869
870static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000871alp_GetFrameNumber(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000872{
873 stamp_t fnum;
874
Guido van Rossum43713e52000-02-29 13:59:29 +0000875 if (!PyArg_ParseTuple(args, ":GetFrameNumber"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000876 return NULL;
877
878 if (alGetFrameNumber(self->port, &fnum) < 0)
879 return NULL;
880
881 return PyLong_FromLongLong((long long) fnum);
882}
883
884
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000885PyDoc_STRVAR(alp_GetFrameTime__doc__,
886"alGetFrameTime: get the time at which a sample frame came "
887"in or will go out.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000888
889static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000890alp_GetFrameTime(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000891{
892 stamp_t fnum, time;
893 PyObject *ret, *v0, *v1;
894
Guido van Rossum43713e52000-02-29 13:59:29 +0000895 if (!PyArg_ParseTuple(args, ":GetFrameTime"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000896 return NULL;
897 if (alGetFrameTime(self->port, &fnum, &time) < 0)
898 return NULL;
899 v0 = PyLong_FromLongLong((long long) fnum);
900 v1 = PyLong_FromLongLong((long long) time);
901 if (PyErr_Occurred()) {
902 Py_XDECREF(v0);
903 Py_XDECREF(v1);
904 return NULL;
905 }
906 ret = Py_BuildValue("(OO)", v0, v1);
907 Py_DECREF(v0);
908 Py_DECREF(v1);
909 return ret;
910}
911
912
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000913PyDoc_STRVAR(alp_WriteFrames__doc__,
914"alWriteFrames: write sample frames to an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000915
916static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000917alp_WriteFrames(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000918{
919 char *samples;
920 int length;
921 int size, ch;
922 ALconfig c;
923
Guido van Rossum43713e52000-02-29 13:59:29 +0000924 if (!PyArg_ParseTuple(args, "s#:WriteFrames", &samples, &length))
Guido van Rossumd641d671997-04-03 17:06:32 +0000925 return NULL;
926 c = alGetConfig(self->port);
927 switch (alGetSampFmt(c)) {
928 case AL_SAMPFMT_TWOSCOMP:
929 switch (alGetWidth(c)) {
930 case AL_SAMPLE_8:
931 size = 1;
932 break;
933 case AL_SAMPLE_16:
934 size = 2;
935 break;
936 case AL_SAMPLE_24:
937 size = 4;
938 break;
939 default:
940 PyErr_SetString(ErrorObject, "can't determine width");
941 alFreeConfig(c);
942 return NULL;
943 }
944 break;
945 case AL_SAMPFMT_FLOAT:
946 size = 4;
947 break;
948 case AL_SAMPFMT_DOUBLE:
949 size = 8;
950 break;
951 default:
952 PyErr_SetString(ErrorObject, "can't determine format");
953 alFreeConfig(c);
954 return NULL;
955 }
956 ch = alGetChannels(c);
957 alFreeConfig(c);
958 if (ch < 0) {
959 PyErr_SetString(ErrorObject, "can't determine # of channels");
960 return NULL;
961 }
962 size *= ch;
963 if (length % size != 0) {
964 PyErr_SetString(ErrorObject,
965 "buffer length not whole number of frames");
966 return NULL;
967 }
968
969 Py_BEGIN_ALLOW_THREADS
970 alWriteFrames(self->port, (void *) samples, length / size);
971 Py_END_ALLOW_THREADS
972
973 Py_INCREF(Py_None);
974 return Py_None;
975}
976
977
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +0000978PyDoc_STRVAR(alp_ClosePort__doc__, "alClosePort: close an audio port.");
Guido van Rossumd641d671997-04-03 17:06:32 +0000979
980static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000981alp_ClosePort(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000982{
Guido van Rossum43713e52000-02-29 13:59:29 +0000983 if (!PyArg_ParseTuple(args, ":ClosePort"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000984 return NULL;
985 if (alClosePort(self->port) < 0)
986 return NULL;
987 self->port = NULL;
988 Py_INCREF(Py_None);
989 return Py_None;
990}
991
992#endif /* AL_NO_ELEM */
993
994#ifdef OLD_INTERFACE
995static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +0000996alp_closeport(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +0000997{
Guido van Rossum43713e52000-02-29 13:59:29 +0000998 if (!PyArg_ParseTuple(args, ":ClosePort"))
Guido van Rossumd641d671997-04-03 17:06:32 +0000999 return NULL;
1000 if (ALcloseport(self->port) < 0)
1001 return NULL;
1002 self->port = NULL;
1003 Py_INCREF(Py_None);
1004 return Py_None;
Guido van Rossume3db8621991-09-09 23:33:34 +00001005}
1006
Roger E. Massea2a8b271997-01-03 22:40:34 +00001007static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001008alp_getfd(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001009{
1010 int fd;
1011
Guido van Rossum43713e52000-02-29 13:59:29 +00001012 if (!PyArg_ParseTuple(args, ":GetFD"))
Guido van Rossumd641d671997-04-03 17:06:32 +00001013 return NULL;
1014 if ((fd = ALgetfd(self-> port)) == -1)
1015 return NULL;
1016 return PyInt_FromLong(fd);
1017}
1018
1019static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001020alp_getfilled(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001021{
1022 long count;
1023
Guido van Rossum43713e52000-02-29 13:59:29 +00001024 if (!PyArg_ParseTuple(args, ":GetFilled"))
Guido van Rossumd641d671997-04-03 17:06:32 +00001025 return NULL;
1026 if ((count = ALgetfilled(self-> port)) == -1)
1027 return NULL;
1028 return PyInt_FromLong(count);
Guido van Rossume3db8621991-09-09 23:33:34 +00001029}
1030
Roger E. Massea2a8b271997-01-03 22:40:34 +00001031static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001032alp_getfillable(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001033{
1034 long count;
1035
Guido van Rossum43713e52000-02-29 13:59:29 +00001036 if (!PyArg_ParseTuple(args, ":GetFillable"))
Guido van Rossumd641d671997-04-03 17:06:32 +00001037 return NULL;
1038 if ((count = ALgetfillable(self-> port)) == -1)
1039 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001040 return PyInt_FromLong (count);
Guido van Rossume3db8621991-09-09 23:33:34 +00001041}
1042
Roger E. Massea2a8b271997-01-03 22:40:34 +00001043static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001044alp_readsamps(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001045{
1046 long count;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001047 PyObject *v;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001048 ALconfig c;
Guido van Rossume3db8621991-09-09 23:33:34 +00001049 int width;
Guido van Rossumd641d671997-04-03 17:06:32 +00001050 int ret;
Guido van Rossume3db8621991-09-09 23:33:34 +00001051
Guido van Rossum43713e52000-02-29 13:59:29 +00001052 if (!PyArg_ParseTuple(args, "l:readsamps", &count))
Guido van Rossumd641d671997-04-03 17:06:32 +00001053 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +00001054
Guido van Rossumd641d671997-04-03 17:06:32 +00001055 if (count <= 0) {
1056 PyErr_SetString(ErrorObject, "al.readsamps : arg <= 0");
Guido van Rossume3db8621991-09-09 23:33:34 +00001057 return NULL;
1058 }
1059
Guido van Rossumd641d671997-04-03 17:06:32 +00001060 c = ALgetconfig(self->port);
Jack Jansene8a3c281993-02-10 14:10:56 +00001061#ifdef AL_405
1062 width = ALgetsampfmt(c);
Guido van Rossumd641d671997-04-03 17:06:32 +00001063 if (width == AL_SAMPFMT_FLOAT)
1064 width = sizeof(float);
1065 else if (width == AL_SAMPFMT_DOUBLE)
1066 width = sizeof(double);
Jack Jansene8a3c281993-02-10 14:10:56 +00001067 else
Guido van Rossumd641d671997-04-03 17:06:32 +00001068 width = ALgetwidth(c);
Jack Jansene8a3c281993-02-10 14:10:56 +00001069#else
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001070 width = ALgetwidth(c);
Jack Jansene8a3c281993-02-10 14:10:56 +00001071#endif /* AL_405 */
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001072 ALfreeconfig(c);
Guido van Rossumd641d671997-04-03 17:06:32 +00001073 v = PyString_FromStringAndSize((char *)NULL, width * count);
1074 if (v == NULL)
1075 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +00001076
Roger E. Massea2a8b271997-01-03 22:40:34 +00001077 Py_BEGIN_ALLOW_THREADS
Guido van Rossumd641d671997-04-03 17:06:32 +00001078 ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
Roger E. Massea2a8b271997-01-03 22:40:34 +00001079 Py_END_ALLOW_THREADS
Guido van Rossumd641d671997-04-03 17:06:32 +00001080 if (ret == -1) {
1081 Py_DECREF(v);
1082 return NULL;
1083 }
Guido van Rossume3db8621991-09-09 23:33:34 +00001084
1085 return (v);
1086}
1087
Roger E. Massea2a8b271997-01-03 22:40:34 +00001088static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001089alp_writesamps(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001090{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001091 char *buf;
1092 int size, width;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001093 ALconfig c;
Guido van Rossumd641d671997-04-03 17:06:32 +00001094 int ret;
Guido van Rossume3db8621991-09-09 23:33:34 +00001095
Guido van Rossum43713e52000-02-29 13:59:29 +00001096 if (!PyArg_ParseTuple(args, "s#:writesamps", &buf, &size))
Guido van Rossumd641d671997-04-03 17:06:32 +00001097 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +00001098
Guido van Rossumd641d671997-04-03 17:06:32 +00001099 c = ALgetconfig(self->port);
Jack Jansene8a3c281993-02-10 14:10:56 +00001100#ifdef AL_405
1101 width = ALgetsampfmt(c);
Guido van Rossumd641d671997-04-03 17:06:32 +00001102 if (width == AL_SAMPFMT_FLOAT)
1103 width = sizeof(float);
1104 else if (width == AL_SAMPFMT_DOUBLE)
1105 width = sizeof(double);
Jack Jansene8a3c281993-02-10 14:10:56 +00001106 else
Guido van Rossumd641d671997-04-03 17:06:32 +00001107 width = ALgetwidth(c);
Jack Jansene8a3c281993-02-10 14:10:56 +00001108#else
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001109 width = ALgetwidth(c);
Jack Jansene8a3c281993-02-10 14:10:56 +00001110#endif /* AL_405 */
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001111 ALfreeconfig(c);
Roger E. Massea2a8b271997-01-03 22:40:34 +00001112 Py_BEGIN_ALLOW_THREADS
Guido van Rossumd641d671997-04-03 17:06:32 +00001113 ret = ALwritesamps (self->port, (void *) buf, (long) size / width);
Roger E. Massea2a8b271997-01-03 22:40:34 +00001114 Py_END_ALLOW_THREADS
Guido van Rossumd641d671997-04-03 17:06:32 +00001115 if (ret == -1)
1116 return NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +00001117
Guido van Rossumd641d671997-04-03 17:06:32 +00001118 Py_INCREF(Py_None);
Roger E. Massea2a8b271997-01-03 22:40:34 +00001119 return Py_None;
Guido van Rossume3db8621991-09-09 23:33:34 +00001120}
1121
Roger E. Massea2a8b271997-01-03 22:40:34 +00001122static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001123alp_getfillpoint(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001124{
1125 long count;
1126
Guido van Rossum43713e52000-02-29 13:59:29 +00001127 if (!PyArg_ParseTuple(args, ":GetFillPoint"))
Guido van Rossumd641d671997-04-03 17:06:32 +00001128 return NULL;
1129 if ((count = ALgetfillpoint(self->port)) == -1)
1130 return NULL;
1131 return PyInt_FromLong(count);
Guido van Rossume3db8621991-09-09 23:33:34 +00001132}
1133
Roger E. Massea2a8b271997-01-03 22:40:34 +00001134static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001135alp_setfillpoint(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001136{
1137 long count;
1138
Guido van Rossum43713e52000-02-29 13:59:29 +00001139 if (!PyArg_ParseTuple(args, "l:SetFillPoint", &count))
Guido van Rossumd641d671997-04-03 17:06:32 +00001140 return NULL;
1141 if (ALsetfillpoint(self->port, count) == -1)
1142 return NULL;
1143 Py_INCREF(Py_None);
1144 return Py_None;
Guido van Rossume3db8621991-09-09 23:33:34 +00001145}
1146
Roger E. Massea2a8b271997-01-03 22:40:34 +00001147static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001148alp_setconfig(alpobject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001149{
1150 alcobject *config;
1151
Guido van Rossum43713e52000-02-29 13:59:29 +00001152 if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
Guido van Rossumd641d671997-04-03 17:06:32 +00001153 return NULL;
1154 if (ALsetconfig(self->port, config->config) == -1)
1155 return NULL;
1156 Py_INCREF(Py_None);
1157 return Py_None;
1158}
1159
1160static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001161alp_getconfig(alpobject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001162{
1163 ALconfig config;
1164
Guido van Rossum43713e52000-02-29 13:59:29 +00001165 if (!PyArg_ParseTuple(args, ":GetConfig"))
Guido van Rossumd641d671997-04-03 17:06:32 +00001166 return NULL;
1167 config = ALgetconfig(self->port);
1168 if (config == NULL)
1169 return NULL;
1170 return newalcobject(config);
Guido van Rossume3db8621991-09-09 23:33:34 +00001171}
1172
Jack Jansene8a3c281993-02-10 14:10:56 +00001173#ifdef AL_405
Roger E. Massea2a8b271997-01-03 22:40:34 +00001174static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001175alp_getstatus(alpobject *self, PyObject *args)
Jack Jansene8a3c281993-02-10 14:10:56 +00001176{
Roger E. Massea2a8b271997-01-03 22:40:34 +00001177 PyObject *list, *v;
Jack Jansene8a3c281993-02-10 14:10:56 +00001178 long *PVbuffer;
1179 long length;
1180 int i;
1181
Martin v. Löwis0bd292f2001-11-03 10:48:43 +00001182 if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
Jack Jansene8a3c281993-02-10 14:10:56 +00001183 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001184 length = PyList_Size(list);
1185 PVbuffer = PyMem_NEW(long, length);
Jack Jansene8a3c281993-02-10 14:10:56 +00001186 if (PVbuffer == NULL)
Roger E. Massea2a8b271997-01-03 22:40:34 +00001187 return PyErr_NoMemory();
Jack Jansene8a3c281993-02-10 14:10:56 +00001188 for (i = 0; i < length; i++) {
Roger E. Massea2a8b271997-01-03 22:40:34 +00001189 v = PyList_GetItem(list, i);
1190 if (!PyInt_Check(v)) {
1191 PyMem_DEL(PVbuffer);
1192 PyErr_BadArgument();
Jack Jansene8a3c281993-02-10 14:10:56 +00001193 return NULL;
1194 }
Roger E. Massea2a8b271997-01-03 22:40:34 +00001195 PVbuffer[i] = PyInt_AsLong(v);
Jack Jansene8a3c281993-02-10 14:10:56 +00001196 }
1197
Guido van Rossumd641d671997-04-03 17:06:32 +00001198 if (ALgetstatus(self->port, PVbuffer, length) == -1)
1199 return NULL;
Jack Jansene8a3c281993-02-10 14:10:56 +00001200
1201 for (i = 0; i < length; i++)
Guido van Rossumd641d671997-04-03 17:06:32 +00001202 PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
Jack Jansene8a3c281993-02-10 14:10:56 +00001203
Roger E. Massea2a8b271997-01-03 22:40:34 +00001204 PyMem_DEL(PVbuffer);
Jack Jansene8a3c281993-02-10 14:10:56 +00001205
Roger E. Massea2a8b271997-01-03 22:40:34 +00001206 Py_INCREF(Py_None);
1207 return Py_None;
Jack Jansene8a3c281993-02-10 14:10:56 +00001208}
1209#endif /* AL_405 */
1210
Guido van Rossumd641d671997-04-03 17:06:32 +00001211#endif /* OLD_INTERFACE */
1212
1213static struct PyMethodDef alp_methods[] = {
1214#ifdef AL_NO_ELEM /* IRIX 6 */
1215 {"SetConfig", (PyCFunction)alp_SetConfig, METH_VARARGS, alp_SetConfig__doc__},
1216 {"GetConfig", (PyCFunction)alp_GetConfig, METH_VARARGS, alp_GetConfig__doc__},
1217 {"GetResource", (PyCFunction)alp_GetResource, METH_VARARGS, alp_GetResource__doc__},
1218 {"GetFD", (PyCFunction)alp_GetFD, METH_VARARGS, alp_GetFD__doc__},
1219 {"GetFilled", (PyCFunction)alp_GetFilled, METH_VARARGS, alp_GetFilled__doc__},
1220 {"GetFillable", (PyCFunction)alp_GetFillable, METH_VARARGS, alp_GetFillable__doc__},
1221 {"ReadFrames", (PyCFunction)alp_ReadFrames, METH_VARARGS, alp_ReadFrames__doc__},
1222 {"DiscardFrames", (PyCFunction)alp_DiscardFrames, METH_VARARGS, alp_DiscardFrames__doc__},
1223 {"ZeroFrames", (PyCFunction)alp_ZeroFrames, METH_VARARGS, alp_ZeroFrames__doc__},
1224 {"SetFillPoint", (PyCFunction)alp_SetFillPoint, METH_VARARGS, alp_SetFillPoint__doc__},
1225 {"GetFillPoint", (PyCFunction)alp_GetFillPoint, METH_VARARGS, alp_GetFillPoint__doc__},
1226 {"GetFrameNumber", (PyCFunction)alp_GetFrameNumber, METH_VARARGS, alp_GetFrameNumber__doc__},
1227 {"GetFrameTime", (PyCFunction)alp_GetFrameTime, METH_VARARGS, alp_GetFrameTime__doc__},
1228 {"WriteFrames", (PyCFunction)alp_WriteFrames, METH_VARARGS, alp_WriteFrames__doc__},
1229 {"ClosePort", (PyCFunction)alp_ClosePort, METH_VARARGS, alp_ClosePort__doc__},
1230#endif /* AL_NO_ELEM */
1231#ifdef OLD_INTERFACE
1232 {"closeport", (PyCFunction)alp_closeport, METH_VARARGS},
1233 {"getfd", (PyCFunction)alp_getfd, METH_VARARGS},
1234 {"fileno", (PyCFunction)alp_getfd, METH_VARARGS},
1235 {"getfilled", (PyCFunction)alp_getfilled, METH_VARARGS},
1236 {"getfillable", (PyCFunction)alp_getfillable, METH_VARARGS},
1237 {"readsamps", (PyCFunction)alp_readsamps, METH_VARARGS},
1238 {"writesamps", (PyCFunction)alp_writesamps, METH_VARARGS},
1239 {"setfillpoint", (PyCFunction)alp_setfillpoint, METH_VARARGS},
1240 {"getfillpoint", (PyCFunction)alp_getfillpoint, METH_VARARGS},
1241 {"setconfig", (PyCFunction)alp_setconfig, METH_VARARGS},
1242 {"getconfig", (PyCFunction)alp_getconfig, METH_VARARGS},
Jack Jansene8a3c281993-02-10 14:10:56 +00001243#ifdef AL_405
Guido van Rossumd641d671997-04-03 17:06:32 +00001244 {"getstatus", (PyCFunction)alp_getstatus, METH_VARARGS},
Jack Jansene8a3c281993-02-10 14:10:56 +00001245#endif /* AL_405 */
Guido van Rossumd641d671997-04-03 17:06:32 +00001246#endif /* OLD_INTERFACE */
1247
1248 {NULL, NULL} /* sentinel */
Guido van Rossume3db8621991-09-09 23:33:34 +00001249};
1250
Guido van Rossumd641d671997-04-03 17:06:32 +00001251/* ---------- */
1252
1253
1254static PyObject *
1255newalpobject(ALport port)
1256{
1257 alpobject *self;
1258
Guido van Rossumb18618d2000-05-03 23:44:39 +00001259 self = PyObject_New(alpobject, &Alptype);
Guido van Rossumd641d671997-04-03 17:06:32 +00001260 if (self == NULL)
1261 return NULL;
1262 /* XXXX Add your own initializers here */
1263 self->port = port;
1264 return (PyObject *) self;
1265}
1266
1267
Guido van Rossume3db8621991-09-09 23:33:34 +00001268static void
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001269alp_dealloc(alpobject *self)
Guido van Rossume3db8621991-09-09 23:33:34 +00001270{
Guido van Rossumd641d671997-04-03 17:06:32 +00001271 /* XXXX Add your own cleanup code here */
1272 if (self->port) {
1273#ifdef AL_NO_ELEM /* IRIX 6 */
1274 alClosePort(self->port);
1275#else
1276 ALcloseport(self->port);
1277#endif
1278 }
Guido van Rossumb18618d2000-05-03 23:44:39 +00001279 PyObject_Del(self);
Guido van Rossume3db8621991-09-09 23:33:34 +00001280}
1281
Roger E. Massea2a8b271997-01-03 22:40:34 +00001282static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001283alp_getattr(alpobject *self, char *name)
Guido van Rossume3db8621991-09-09 23:33:34 +00001284{
Guido van Rossumd641d671997-04-03 17:06:32 +00001285 /* XXXX Add your own getattr code here */
1286 if (self->port == NULL) {
1287 PyErr_SetString(ErrorObject, "port already closed");
1288 return NULL;
1289 }
1290 return Py_FindMethod(alp_methods, (PyObject *)self, name);
Guido van Rossume3db8621991-09-09 23:33:34 +00001291}
1292
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001293PyDoc_STRVAR(Alptype__doc__, "");
Guido van Rossumd641d671997-04-03 17:06:32 +00001294
1295static PyTypeObject Alptype = {
Roger E. Massea2a8b271997-01-03 22:40:34 +00001296 PyObject_HEAD_INIT(&PyType_Type)
Guido van Rossumd641d671997-04-03 17:06:32 +00001297 0, /*ob_size*/
Guido van Rossum14648392001-12-08 18:02:58 +00001298 "al.port", /*tp_name*/
Guido van Rossumd641d671997-04-03 17:06:32 +00001299 sizeof(alpobject), /*tp_basicsize*/
1300 0, /*tp_itemsize*/
Guido van Rossume3db8621991-09-09 23:33:34 +00001301 /* methods */
Guido van Rossumd641d671997-04-03 17:06:32 +00001302 (destructor)alp_dealloc, /*tp_dealloc*/
1303 (printfunc)0, /*tp_print*/
1304 (getattrfunc)alp_getattr, /*tp_getattr*/
1305 (setattrfunc)0, /*tp_setattr*/
1306 (cmpfunc)0, /*tp_compare*/
1307 (reprfunc)0, /*tp_repr*/
1308 0, /*tp_as_number*/
1309 0, /*tp_as_sequence*/
1310 0, /*tp_as_mapping*/
1311 (hashfunc)0, /*tp_hash*/
1312 (ternaryfunc)0, /*tp_call*/
1313 (reprfunc)0, /*tp_str*/
1314
1315 /* Space for future expansion */
1316 0L,0L,0L,0L,
1317 Alptype__doc__ /* Documentation string */
Guido van Rossume3db8621991-09-09 23:33:34 +00001318};
1319
Guido van Rossumd641d671997-04-03 17:06:32 +00001320/* End of code for port objects */
1321/* -------------------------------------------------------- */
1322
1323
1324#ifdef AL_NO_ELEM /* IRIX 6 */
1325
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001326PyDoc_STRVAR(al_NewConfig__doc__,
1327"alNewConfig: create and initialize an audio ALconfig structure.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001328
Roger E. Massea2a8b271997-01-03 22:40:34 +00001329static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001330al_NewConfig(PyObject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001331{
Guido van Rossumd641d671997-04-03 17:06:32 +00001332 ALconfig config;
1333
Guido van Rossum43713e52000-02-29 13:59:29 +00001334 if (!PyArg_ParseTuple(args, ":NewConfig"))
Guido van Rossume3db8621991-09-09 23:33:34 +00001335 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001336 if ((config = alNewConfig()) == NULL)
1337 return NULL;
1338 return newalcobject(config);
Guido van Rossume3db8621991-09-09 23:33:34 +00001339}
1340
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001341PyDoc_STRVAR(al_OpenPort__doc__,
1342"alOpenPort: open an audio port.");
Guido van Rossume3db8621991-09-09 23:33:34 +00001343
Roger E. Massea2a8b271997-01-03 22:40:34 +00001344static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001345al_OpenPort(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001346{
1347 ALport port;
1348 char *name, *dir;
1349 alcobject *config = NULL;
1350
Guido van Rossum43713e52000-02-29 13:59:29 +00001351 if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
Guido van Rossumd641d671997-04-03 17:06:32 +00001352 return NULL;
1353 if ((port = alOpenPort(name, dir, config ? config->config : NULL)) == NULL)
1354 return NULL;
1355 return newalpobject(port);
1356}
1357
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001358PyDoc_STRVAR(al_Connect__doc__,
1359"alConnect: connect two audio I/O resources.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001360
1361static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001362al_Connect(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001363{
1364 int source, dest, nprops = 0, id, i;
1365 ALpv *props = NULL;
1366 ALparamInfo *propinfo = NULL;
1367 PyObject *propobj = NULL;
1368
Guido van Rossum43713e52000-02-29 13:59:29 +00001369 if (!PyArg_ParseTuple(args, "ii|O!:Connect", &source, &dest, &PyList_Type, &propobj))
Guido van Rossumd641d671997-04-03 17:06:32 +00001370 return NULL;
1371 if (propobj != NULL) {
1372 nprops = python2params(source, dest, propobj, &props, &propinfo);
1373 if (nprops < 0)
1374 return NULL;
1375 }
1376
1377 id = alConnect(source, dest, props, nprops);
1378
1379 if (props) {
1380 for (i = 0; i < nprops; i++) {
1381 switch (propinfo[i].valueType) {
1382 case AL_SET_VAL:
1383 case AL_VECTOR_VAL:
1384 PyMem_DEL(props[i].value.ptr);
1385 break;
1386 }
1387 }
1388 PyMem_DEL(props);
1389 PyMem_DEL(propinfo);
1390 }
1391
1392 if (id < 0)
1393 return NULL;
1394 return PyInt_FromLong((long) id);
1395}
1396
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001397PyDoc_STRVAR(al_Disconnect__doc__,
1398"alDisconnect: delete a connection between two audio I/O resources.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001399
1400static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001401al_Disconnect(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001402{
1403 int res;
1404
Guido van Rossum43713e52000-02-29 13:59:29 +00001405 if (!PyArg_ParseTuple(args, "i:Disconnect", &res))
Guido van Rossumd641d671997-04-03 17:06:32 +00001406 return NULL;
1407 if (alDisconnect(res) < 0)
1408 return NULL;
1409 Py_INCREF(Py_None);
1410 return Py_None;
1411}
1412
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001413PyDoc_STRVAR(al_GetParams__doc__,
1414"alGetParams: get the values of audio resource parameters.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001415
1416static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001417al_GetParams(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001418{
1419 int resource;
1420 PyObject *pvslist, *item = NULL, *v = NULL;
1421 ALpv *pvs;
1422 int i, j, npvs;
1423 ALparamInfo *pinfo;
1424
Guido van Rossum43713e52000-02-29 13:59:29 +00001425 if (!PyArg_ParseTuple(args, "iO!:GetParams", &resource, &PyList_Type, &pvslist))
Guido van Rossumd641d671997-04-03 17:06:32 +00001426 return NULL;
1427 npvs = PyList_Size(pvslist);
1428 pvs = PyMem_NEW(ALpv, npvs);
1429 pinfo = PyMem_NEW(ALparamInfo, npvs);
1430 for (i = 0; i < npvs; i++) {
1431 item = PyList_GetItem(pvslist, i);
1432 if (!PyInt_Check(item)) {
1433 item = NULL;
1434 PyErr_SetString(ErrorObject, "list of integers expected");
1435 goto error;
1436 }
1437 pvs[i].param = (int) PyInt_AsLong(item);
1438 item = NULL; /* not needed anymore */
1439 if (alGetParamInfo(resource, pvs[i].param, &pinfo[i]) < 0)
1440 goto error;
1441 switch (pinfo[i].valueType) {
1442 case AL_NO_VAL:
1443 break;
1444 case AL_MATRIX_VAL:
1445 pinfo[i].maxElems *= pinfo[i].maxElems2;
1446 /* fall through */
1447 case AL_STRING_VAL:
1448 case AL_SET_VAL:
1449 case AL_VECTOR_VAL:
1450 switch (pinfo[i].elementType) {
1451 case AL_INT32_ELEM:
1452 case AL_RESOURCE_ELEM:
1453 case AL_ENUM_ELEM:
1454 pvs[i].value.ptr = PyMem_NEW(int, pinfo[i].maxElems);
1455 pvs[i].sizeIn = pinfo[i].maxElems;
1456 break;
1457 case AL_INT64_ELEM:
1458 case AL_FIXED_ELEM:
1459 pvs[i].value.ptr = PyMem_NEW(long long, pinfo[i].maxElems);
1460 pvs[i].sizeIn = pinfo[i].maxElems;
1461 break;
1462 case AL_CHAR_ELEM:
1463 pvs[i].value.ptr = PyMem_NEW(char, 32);
1464 pvs[i].sizeIn = 32;
1465 break;
1466 case AL_NO_ELEM:
1467 case AL_PTR_ELEM:
1468 default:
1469 PyErr_SetString(ErrorObject, "internal error");
1470 goto error;
1471 }
1472 break;
1473 case AL_SCALAR_VAL:
1474 break;
1475 default:
1476 PyErr_SetString(ErrorObject, "internal error");
1477 goto error;
1478 }
1479 if (pinfo[i].valueType == AL_MATRIX_VAL) {
1480 pinfo[i].maxElems /= pinfo[i].maxElems2;
1481 pvs[i].sizeIn /= pinfo[i].maxElems2;
1482 pvs[i].size2In = pinfo[i].maxElems2;
1483 }
1484 }
1485 if (alGetParams(resource, pvs, npvs) < 0)
1486 goto error;
1487 v = PyList_New(npvs);
1488 for (i = 0; i < npvs; i++) {
1489 if (pvs[i].sizeOut < 0) {
1490 char buf[32];
Tim Peters75cdad52001-11-28 22:07:30 +00001491 PyOS_snprintf(buf, sizeof(buf),
1492 "problem with param %d", i);
Guido van Rossumd641d671997-04-03 17:06:32 +00001493 PyErr_SetString(ErrorObject, buf);
1494 goto error;
1495 }
1496 switch (pinfo[i].valueType) {
1497 case AL_NO_VAL:
1498 item = Py_None;
1499 Py_INCREF(item);
1500 break;
1501 case AL_STRING_VAL:
1502 item = PyString_FromString(pvs[i].value.ptr);
1503 PyMem_DEL(pvs[i].value.ptr);
1504 break;
1505 case AL_MATRIX_VAL:
1506 /* XXXX this is not right */
1507 pvs[i].sizeOut *= pvs[i].size2Out;
1508 /* fall through */
1509 case AL_SET_VAL:
1510 case AL_VECTOR_VAL:
1511 item = PyList_New(pvs[i].sizeOut);
1512 for (j = 0; j < pvs[i].sizeOut; j++) {
1513 switch (pinfo[i].elementType) {
1514 case AL_INT32_ELEM:
1515 case AL_RESOURCE_ELEM:
1516 case AL_ENUM_ELEM:
1517 PyList_SetItem(item, j, PyInt_FromLong((long) ((int *) pvs[i].value.ptr)[j]));
1518 break;
1519 case AL_INT64_ELEM:
1520 PyList_SetItem(item, j, PyLong_FromLongLong(((long long *) pvs[i].value.ptr)[j]));
1521 break;
1522 case AL_FIXED_ELEM:
1523 PyList_SetItem(item, j, PyFloat_FromDouble(alFixedToDouble(((long long *) pvs[i].value.ptr)[j])));
1524 break;
1525 default:
1526 PyErr_SetString(ErrorObject, "internal error");
1527 goto error;
1528 }
1529 }
1530 PyMem_DEL(pvs[i].value.ptr);
1531 break;
1532 case AL_SCALAR_VAL:
1533 item = param2python(resource, pvs[i].param, pvs[i].value, &pinfo[i]);
1534 break;
1535 }
1536 if (PyErr_Occurred() ||
1537 PyList_SetItem(v, i, Py_BuildValue("(iO)", pvs[i].param,
1538 item)) < 0 ||
1539 PyErr_Occurred())
1540 goto error;
1541 Py_DECREF(item);
1542 }
1543 PyMem_DEL(pvs);
1544 PyMem_DEL(pinfo);
1545 return v;
1546
1547 error:
1548 Py_XDECREF(v);
1549 Py_XDECREF(item);
1550 if (pvs)
1551 PyMem_DEL(pvs);
1552 if (pinfo)
1553 PyMem_DEL(pinfo);
1554 return NULL;
1555}
1556
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001557PyDoc_STRVAR(al_SetParams__doc__,
1558"alSetParams: set the values of audio resource parameters.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001559
1560static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001561al_SetParams(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001562{
1563 int resource;
1564 PyObject *pvslist, *item;
1565 ALpv *pvs;
1566 ALparamInfo *pinfo;
1567 int npvs, i;
1568
Guido van Rossum43713e52000-02-29 13:59:29 +00001569 if (!PyArg_ParseTuple(args, "iO!:SetParams", &resource, &PyList_Type, &pvslist))
Guido van Rossumd641d671997-04-03 17:06:32 +00001570 return NULL;
1571 npvs = python2params(resource, -1, pvslist, &pvs, &pinfo);
1572 if (npvs < 0)
1573 return NULL;
1574
1575 if (alSetParams(resource, pvs, npvs) < 0)
1576 goto error;
1577
1578 /* cleanup */
1579 for (i = 0; i < npvs; i++) {
1580 switch (pinfo[i].valueType) {
1581 case AL_SET_VAL:
1582 case AL_VECTOR_VAL:
1583 PyMem_DEL(pvs[i].value.ptr);
1584 break;
1585 }
1586 }
1587 PyMem_DEL(pvs);
1588 PyMem_DEL(pinfo);
1589
1590 Py_INCREF(Py_None);
1591 return Py_None;
1592
1593 error:
1594 /* XXXX we should clean up everything */
1595 if (pvs)
1596 PyMem_DEL(pvs);
1597 if (pinfo)
1598 PyMem_DEL(pinfo);
1599 return NULL;
1600}
1601
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001602PyDoc_STRVAR(al_QueryValues__doc__,
1603"alQueryValues: get the set of possible values for a parameter.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001604
1605static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001606al_QueryValues(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001607{
1608 int resource, param;
1609 ALvalue *return_set = NULL;
1610 int setsize = 32, qualsize = 0, nvals, i;
1611 ALpv *quals = NULL;
1612 ALparamInfo pinfo;
1613 ALparamInfo *qualinfo = NULL;
1614 PyObject *qualobj = NULL;
1615 PyObject *res = NULL, *item;
1616
Guido van Rossum43713e52000-02-29 13:59:29 +00001617 if (!PyArg_ParseTuple(args, "ii|O!:QueryValues", &resource, &param,
Guido van Rossumd641d671997-04-03 17:06:32 +00001618 &PyList_Type, &qualobj))
1619 return NULL;
1620 if (qualobj != NULL) {
1621 qualsize = python2params(resource, param, qualobj, &quals, &qualinfo);
1622 if (qualsize < 0)
1623 return NULL;
1624 }
1625 setsize = 32;
1626 return_set = PyMem_NEW(ALvalue, setsize);
1627 if (return_set == NULL) {
1628 PyErr_NoMemory();
1629 goto cleanup;
1630 }
1631
1632 retry:
1633 nvals = alQueryValues(resource, param, return_set, setsize, quals, qualsize);
1634 if (nvals < 0)
1635 goto cleanup;
1636 if (nvals > setsize) {
1637 setsize = nvals;
1638 PyMem_RESIZE(return_set, ALvalue, setsize);
1639 if (return_set == NULL) {
1640 PyErr_NoMemory();
1641 goto cleanup;
1642 }
1643 goto retry;
1644 }
1645
1646 if (alGetParamInfo(resource, param, &pinfo) < 0)
1647 goto cleanup;
1648
1649 res = PyList_New(nvals);
1650 if (res == NULL)
1651 goto cleanup;
1652 for (i = 0; i < nvals; i++) {
1653 item = param2python(resource, param, return_set[i], &pinfo);
1654 if (item == NULL ||
1655 PyList_SetItem(res, i, item) < 0) {
1656 Py_DECREF(res);
1657 res = NULL;
1658 goto cleanup;
1659 }
1660 }
1661
1662 cleanup:
1663 if (return_set)
1664 PyMem_DEL(return_set);
1665 if (quals) {
1666 for (i = 0; i < qualsize; i++) {
1667 switch (qualinfo[i].valueType) {
1668 case AL_SET_VAL:
1669 case AL_VECTOR_VAL:
1670 PyMem_DEL(quals[i].value.ptr);
1671 break;
1672 }
1673 }
1674 PyMem_DEL(quals);
1675 PyMem_DEL(qualinfo);
1676 }
1677
1678 return res;
1679}
1680
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001681PyDoc_STRVAR(al_GetParamInfo__doc__,
1682"alGetParamInfo: get information about a parameter on "
1683"a particular audio resource.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001684
1685static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001686al_GetParamInfo(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001687{
1688 int res, param;
1689 ALparamInfo pinfo;
1690 PyObject *v, *item;;
1691
Guido van Rossum43713e52000-02-29 13:59:29 +00001692 if (!PyArg_ParseTuple(args, "ii:GetParamInfo", &res, &param))
Guido van Rossumd641d671997-04-03 17:06:32 +00001693 return NULL;
1694 if (alGetParamInfo(res, param, &pinfo) < 0)
1695 return NULL;
1696 v = PyDict_New();
1697
1698 item = PyInt_FromLong((long) pinfo.resource);
1699 PyDict_SetItemString(v, "resource", item);
1700 Py_DECREF(item);
1701
1702 item = PyInt_FromLong((long) pinfo.param);
1703 PyDict_SetItemString(v, "param", item);
1704 Py_DECREF(item);
1705
1706 item = PyInt_FromLong((long) pinfo.valueType);
1707 PyDict_SetItemString(v, "valueType", item);
1708 Py_DECREF(item);
1709
1710 if (pinfo.valueType != AL_NO_VAL && pinfo.valueType != AL_SCALAR_VAL) {
1711 /* multiple values */
1712 item = PyInt_FromLong((long) pinfo.maxElems);
1713 PyDict_SetItemString(v, "maxElems", item);
1714 Py_DECREF(item);
1715
1716 if (pinfo.valueType == AL_MATRIX_VAL) {
1717 /* 2 dimensional */
1718 item = PyInt_FromLong((long) pinfo.maxElems2);
1719 PyDict_SetItemString(v, "maxElems2", item);
1720 Py_DECREF(item);
1721 }
1722 }
1723
1724 item = PyInt_FromLong((long) pinfo.elementType);
1725 PyDict_SetItemString(v, "elementType", item);
1726 Py_DECREF(item);
1727
1728 item = PyString_FromString(pinfo.name);
1729 PyDict_SetItemString(v, "name", item);
1730 Py_DECREF(item);
1731
1732 item = param2python(res, param, pinfo.initial, &pinfo);
1733 PyDict_SetItemString(v, "initial", item);
1734 Py_DECREF(item);
1735
1736 if (pinfo.elementType != AL_ENUM_ELEM &&
1737 pinfo.elementType != AL_RESOURCE_ELEM &&
1738 pinfo.elementType != AL_CHAR_ELEM) {
1739 /* range param */
1740 item = param2python(res, param, pinfo.min, &pinfo);
1741 PyDict_SetItemString(v, "min", item);
1742 Py_DECREF(item);
1743
1744 item = param2python(res, param, pinfo.max, &pinfo);
1745 PyDict_SetItemString(v, "max", item);
1746 Py_DECREF(item);
1747
1748 item = param2python(res, param, pinfo.minDelta, &pinfo);
1749 PyDict_SetItemString(v, "minDelta", item);
1750 Py_DECREF(item);
1751
1752 item = param2python(res, param, pinfo.maxDelta, &pinfo);
1753 PyDict_SetItemString(v, "maxDelta", item);
1754 Py_DECREF(item);
1755
1756 item = PyInt_FromLong((long) pinfo.specialVals);
1757 PyDict_SetItemString(v, "specialVals", item);
1758 Py_DECREF(item);
1759 }
1760
1761 return v;
1762}
1763
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001764PyDoc_STRVAR(al_GetResourceByName__doc__,
1765"alGetResourceByName: find an audio resource by name.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001766
1767static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001768al_GetResourceByName(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001769{
1770 int res, start_res, type;
1771 char *name;
1772
Guido van Rossum43713e52000-02-29 13:59:29 +00001773 if (!PyArg_ParseTuple(args, "isi:GetResourceByName", &start_res, &name, &type))
Guido van Rossumd641d671997-04-03 17:06:32 +00001774 return NULL;
1775 if ((res = alGetResourceByName(start_res, name, type)) == 0)
1776 return NULL;
1777 return PyInt_FromLong((long) res);
1778}
1779
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001780PyDoc_STRVAR(al_IsSubtype__doc__,
1781"alIsSubtype: indicate if one resource type is a subtype of another.");
Guido van Rossumd641d671997-04-03 17:06:32 +00001782
1783static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001784al_IsSubtype(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001785{
1786 int type, subtype;
1787
Guido van Rossum43713e52000-02-29 13:59:29 +00001788 if (!PyArg_ParseTuple(args, "ii:IsSubtype", &type, &subtype))
Guido van Rossumd641d671997-04-03 17:06:32 +00001789 return NULL;
1790 return PyInt_FromLong((long) alIsSubtype(type, subtype));
1791}
1792
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001793PyDoc_STRVAR(al_SetErrorHandler__doc__, "");
Guido van Rossumd641d671997-04-03 17:06:32 +00001794
1795static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001796al_SetErrorHandler(PyObject *self, PyObject *args)
Guido van Rossumd641d671997-04-03 17:06:32 +00001797{
1798
Guido van Rossum43713e52000-02-29 13:59:29 +00001799 if (!PyArg_ParseTuple(args, ":SetErrorHandler"))
Guido van Rossumd641d671997-04-03 17:06:32 +00001800 return NULL;
1801 Py_INCREF(Py_None);
1802 return Py_None;
1803}
1804
1805#endif /* AL_NO_ELEM */
1806
1807#ifdef OLD_INTERFACE
1808
1809static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001810al_openport(PyObject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001811{
Guido van Rossumfc58e581992-01-27 16:45:55 +00001812 char *name, *dir;
Guido van Rossume3db8621991-09-09 23:33:34 +00001813 ALport port;
Guido van Rossumd641d671997-04-03 17:06:32 +00001814 alcobject *config = NULL;
Guido van Rossume3db8621991-09-09 23:33:34 +00001815
Guido van Rossum43713e52000-02-29 13:59:29 +00001816 if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
Guido van Rossumc0aab891991-10-20 20:10:46 +00001817 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001818 if ((port = ALopenport(name, dir, config ? config->config : NULL)) == NULL)
Guido van Rossume3db8621991-09-09 23:33:34 +00001819 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001820 return newalpobject(port);
Guido van Rossume3db8621991-09-09 23:33:34 +00001821}
1822
Roger E. Massea2a8b271997-01-03 22:40:34 +00001823static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001824al_newconfig(PyObject *self, PyObject *args)
Guido van Rossume3db8621991-09-09 23:33:34 +00001825{
1826 ALconfig config;
1827
Guido van Rossum43713e52000-02-29 13:59:29 +00001828 if (!PyArg_ParseTuple(args, ":NewConfig"))
Guido van Rossumc0aab891991-10-20 20:10:46 +00001829 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001830 if ((config = ALnewconfig ()) == NULL)
1831 return NULL;
1832 return newalcobject(config);
Guido van Rossume3db8621991-09-09 23:33:34 +00001833}
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001834
Roger E. Massea2a8b271997-01-03 22:40:34 +00001835static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001836al_queryparams(PyObject *self, PyObject *args)
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001837{
1838 long device;
1839 long length;
1840 long *PVbuffer;
1841 long PVdummy[2];
Guido van Rossumd641d671997-04-03 17:06:32 +00001842 PyObject *v = NULL;
1843 int i;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001844
Guido van Rossum43713e52000-02-29 13:59:29 +00001845 if (!PyArg_ParseTuple(args, "l:queryparams", &device))
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001846 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001847 if ((length = ALqueryparams(device, PVdummy, 2L)) == -1)
1848 return NULL;
1849 if ((PVbuffer = PyMem_NEW(long, length)) == NULL)
Roger E. Massea2a8b271997-01-03 22:40:34 +00001850 return PyErr_NoMemory();
Guido van Rossumd641d671997-04-03 17:06:32 +00001851 if (ALqueryparams(device, PVbuffer, length) >= 0 &&
1852 (v = PyList_New((int)length)) != NULL) {
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001853 for (i = 0; i < length; i++)
Roger E. Massea2a8b271997-01-03 22:40:34 +00001854 PyList_SetItem(v, i, PyInt_FromLong(PVbuffer[i]));
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001855 }
Roger E. Massea2a8b271997-01-03 22:40:34 +00001856 PyMem_DEL(PVbuffer);
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001857 return v;
1858}
1859
Roger E. Massea2a8b271997-01-03 22:40:34 +00001860static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001861doParams(PyObject *args, int (*func)(long, long *, long), int modified)
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001862{
1863 long device;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001864 PyObject *list, *v;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001865 long *PVbuffer;
1866 long length;
1867 int i;
Guido van Rossume3db8621991-09-09 23:33:34 +00001868
Guido van Rossumd641d671997-04-03 17:06:32 +00001869 if (!PyArg_ParseTuple(args, "lO!", &device, &PyList_Type, &list))
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001870 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001871 length = PyList_Size(list);
1872 PVbuffer = PyMem_NEW(long, length);
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001873 if (PVbuffer == NULL)
Roger E. Massea2a8b271997-01-03 22:40:34 +00001874 return PyErr_NoMemory();
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001875 for (i = 0; i < length; i++) {
Roger E. Massea2a8b271997-01-03 22:40:34 +00001876 v = PyList_GetItem(list, i);
1877 if (!PyInt_Check(v)) {
1878 PyMem_DEL(PVbuffer);
1879 PyErr_BadArgument();
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001880 return NULL;
1881 }
Roger E. Massea2a8b271997-01-03 22:40:34 +00001882 PVbuffer[i] = PyInt_AsLong(v);
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001883 }
1884
Guido van Rossumd641d671997-04-03 17:06:32 +00001885 if ((*func)(device, PVbuffer, length) == -1) {
1886 PyMem_DEL(PVbuffer);
1887 return NULL;
1888 }
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001889
1890 if (modified) {
1891 for (i = 0; i < length; i++)
Roger E. Massea2a8b271997-01-03 22:40:34 +00001892 PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001893 }
1894
Roger E. Massea2a8b271997-01-03 22:40:34 +00001895 PyMem_DEL(PVbuffer);
Guido van Rossumc0aab891991-10-20 20:10:46 +00001896
Roger E. Massea2a8b271997-01-03 22:40:34 +00001897 Py_INCREF(Py_None);
1898 return Py_None;
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001899}
1900
Roger E. Massea2a8b271997-01-03 22:40:34 +00001901static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001902al_getparams(PyObject *self, PyObject *args)
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001903{
1904 return doParams(args, ALgetparams, 1);
1905}
1906
Roger E. Massea2a8b271997-01-03 22:40:34 +00001907static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001908al_setparams(PyObject *self, PyObject *args)
Guido van Rossumb3a5b9b1991-09-10 14:54:05 +00001909{
1910 return doParams(args, ALsetparams, 0);
1911}
1912
Roger E. Massea2a8b271997-01-03 22:40:34 +00001913static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001914al_getname(PyObject *self, PyObject *args)
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001915{
1916 long device, descriptor;
1917 char *name;
Guido van Rossumd641d671997-04-03 17:06:32 +00001918
Guido van Rossum43713e52000-02-29 13:59:29 +00001919 if (!PyArg_ParseTuple(args, "ll:getname", &device, &descriptor))
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001920 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001921 if ((name = ALgetname(device, descriptor)) == NULL)
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001922 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001923 return PyString_FromString(name);
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001924}
1925
Roger E. Massea2a8b271997-01-03 22:40:34 +00001926static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001927al_getdefault(PyObject *self, PyObject *args)
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001928{
1929 long device, descriptor, value;
Guido van Rossumd641d671997-04-03 17:06:32 +00001930
Guido van Rossum43713e52000-02-29 13:59:29 +00001931 if (!PyArg_ParseTuple(args, "ll:getdefault", &device, &descriptor))
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001932 return NULL;
Guido van Rossumd641d671997-04-03 17:06:32 +00001933 if ((value = ALgetdefault(device, descriptor)) == -1)
1934 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001935 return PyLong_FromLong(value);
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001936}
1937
Roger E. Massea2a8b271997-01-03 22:40:34 +00001938static PyObject *
Peter Schneider-Kamp6a850272000-07-10 17:04:33 +00001939al_getminmax(PyObject *self, PyObject *args)
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001940{
1941 long device, descriptor, min, max;
Guido van Rossumd641d671997-04-03 17:06:32 +00001942
Guido van Rossum43713e52000-02-29 13:59:29 +00001943 if (!PyArg_ParseTuple(args, "ll:getminmax", &device, &descriptor))
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001944 return NULL;
1945 min = -1;
1946 max = -1;
Guido van Rossumd641d671997-04-03 17:06:32 +00001947 if (ALgetminmax(device, descriptor, &min, &max) == -1)
1948 return NULL;
Roger E. Massea2a8b271997-01-03 22:40:34 +00001949 return Py_BuildValue("ll", min, max);
Guido van Rossum448f4bf1992-08-19 16:41:15 +00001950}
1951
Guido van Rossumd641d671997-04-03 17:06:32 +00001952#endif /* OLD_INTERFACE */
1953
1954/* List of methods defined in the module */
1955
1956static struct PyMethodDef al_methods[] = {
1957#ifdef AL_NO_ELEM /* IRIX 6 */
1958 {"NewConfig", (PyCFunction)al_NewConfig, METH_VARARGS, al_NewConfig__doc__},
1959 {"OpenPort", (PyCFunction)al_OpenPort, METH_VARARGS, al_OpenPort__doc__},
1960 {"Connect", (PyCFunction)al_Connect, METH_VARARGS, al_Connect__doc__},
1961 {"Disconnect", (PyCFunction)al_Disconnect, METH_VARARGS, al_Disconnect__doc__},
1962 {"GetParams", (PyCFunction)al_GetParams, METH_VARARGS, al_GetParams__doc__},
1963 {"SetParams", (PyCFunction)al_SetParams, METH_VARARGS, al_SetParams__doc__},
1964 {"QueryValues", (PyCFunction)al_QueryValues, METH_VARARGS, al_QueryValues__doc__},
1965 {"GetParamInfo", (PyCFunction)al_GetParamInfo, METH_VARARGS, al_GetParamInfo__doc__},
1966 {"GetResourceByName", (PyCFunction)al_GetResourceByName, METH_VARARGS, al_GetResourceByName__doc__},
1967 {"IsSubtype", (PyCFunction)al_IsSubtype, METH_VARARGS, al_IsSubtype__doc__},
1968#if 0
1969 /* this one not supported */
1970 {"SetErrorHandler", (PyCFunction)al_SetErrorHandler, METH_VARARGS, al_SetErrorHandler__doc__},
1971#endif
1972#endif /* AL_NO_ELEM */
1973#ifdef OLD_INTERFACE
1974 {"openport", (PyCFunction)al_openport, METH_VARARGS},
1975 {"newconfig", (PyCFunction)al_newconfig, METH_VARARGS},
1976 {"queryparams", (PyCFunction)al_queryparams, METH_VARARGS},
1977 {"getparams", (PyCFunction)al_getparams, METH_VARARGS},
1978 {"setparams", (PyCFunction)al_setparams, METH_VARARGS},
1979 {"getname", (PyCFunction)al_getname, METH_VARARGS},
1980 {"getdefault", (PyCFunction)al_getdefault, METH_VARARGS},
1981 {"getminmax", (PyCFunction)al_getminmax, METH_VARARGS},
1982#endif /* OLD_INTERFACE */
1983
1984 {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
Guido van Rossume3db8621991-09-09 23:33:34 +00001985};
1986
Guido van Rossumd641d671997-04-03 17:06:32 +00001987
1988/* Initialization function for the module (*must* be called inital) */
1989
Martin v. Löwis14f8b4c2002-06-13 20:33:02 +00001990PyDoc_STRVAR(al_module_documentation, "");
Guido van Rossumd641d671997-04-03 17:06:32 +00001991
Guido van Rossume3db8621991-09-09 23:33:34 +00001992void
Thomas Woutersf3f33dc2000-07-21 06:00:07 +00001993inital(void)
Guido van Rossume3db8621991-09-09 23:33:34 +00001994{
Guido van Rossumd641d671997-04-03 17:06:32 +00001995 PyObject *m, *d, *x;
Guido van Rossume3db8621991-09-09 23:33:34 +00001996
Guido van Rossumd641d671997-04-03 17:06:32 +00001997 /* Create the module and add the functions */
1998 m = Py_InitModule4("al", al_methods,
1999 al_module_documentation,
2000 (PyObject*)NULL,PYTHON_API_VERSION);
2001
2002 /* Add some symbolic constants to the module */
2003 d = PyModule_GetDict(m);
Fred Drake589c35b2000-07-06 19:38:49 +00002004 ErrorObject = PyErr_NewException("al.error", NULL, NULL);
Guido van Rossumd641d671997-04-03 17:06:32 +00002005 PyDict_SetItemString(d, "error", ErrorObject);
2006
2007 /* XXXX Add constants here */
2008#ifdef AL_4CHANNEL
2009 x = PyInt_FromLong((long) AL_4CHANNEL);
2010 if (x == NULL || PyDict_SetItemString(d, "FOURCHANNEL", x) < 0)
2011 goto error;
2012 Py_DECREF(x);
2013#endif
2014#ifdef AL_ADAT_IF_TYPE
2015 x = PyInt_FromLong((long) AL_ADAT_IF_TYPE);
2016 if (x == NULL || PyDict_SetItemString(d, "ADAT_IF_TYPE", x) < 0)
2017 goto error;
2018 Py_DECREF(x);
2019#endif
2020#ifdef AL_ADAT_MCLK_TYPE
2021 x = PyInt_FromLong((long) AL_ADAT_MCLK_TYPE);
2022 if (x == NULL || PyDict_SetItemString(d, "ADAT_MCLK_TYPE", x) < 0)
2023 goto error;
2024 Py_DECREF(x);
2025#endif
2026#ifdef AL_AES_IF_TYPE
2027 x = PyInt_FromLong((long) AL_AES_IF_TYPE);
2028 if (x == NULL || PyDict_SetItemString(d, "AES_IF_TYPE", x) < 0)
2029 goto error;
2030 Py_DECREF(x);
2031#endif
2032#ifdef AL_AES_MCLK_TYPE
2033 x = PyInt_FromLong((long) AL_AES_MCLK_TYPE);
2034 if (x == NULL || PyDict_SetItemString(d, "AES_MCLK_TYPE", x) < 0)
2035 goto error;
2036 Py_DECREF(x);
2037#endif
2038#ifdef AL_ANALOG_IF_TYPE
2039 x = PyInt_FromLong((long) AL_ANALOG_IF_TYPE);
2040 if (x == NULL || PyDict_SetItemString(d, "ANALOG_IF_TYPE", x) < 0)
2041 goto error;
2042 Py_DECREF(x);
2043#endif
2044#ifdef AL_ASSOCIATE
2045 x = PyInt_FromLong((long) AL_ASSOCIATE);
2046 if (x == NULL || PyDict_SetItemString(d, "ASSOCIATE", x) < 0)
2047 goto error;
2048 Py_DECREF(x);
2049#endif
2050#ifdef AL_BAD_BUFFER_NULL
2051 x = PyInt_FromLong((long) AL_BAD_BUFFER_NULL);
2052 if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFER_NULL", x) < 0)
2053 goto error;
2054 Py_DECREF(x);
2055#endif
2056#ifdef AL_BAD_BUFFERLENGTH
2057 x = PyInt_FromLong((long) AL_BAD_BUFFERLENGTH);
2058 if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH", x) < 0)
2059 goto error;
2060 Py_DECREF(x);
2061#endif
2062#ifdef AL_BAD_BUFFERLENGTH_NEG
2063 x = PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_NEG);
2064 if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_NEG", x) < 0)
2065 goto error;
2066 Py_DECREF(x);
2067#endif
2068#ifdef AL_BAD_BUFFERLENGTH_ODD
2069 x = PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_ODD);
2070 if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_ODD", x) < 0)
2071 goto error;
2072 Py_DECREF(x);
2073#endif
2074#ifdef AL_BAD_CHANNELS
2075 x = PyInt_FromLong((long) AL_BAD_CHANNELS);
2076 if (x == NULL || PyDict_SetItemString(d, "BAD_CHANNELS", x) < 0)
2077 goto error;
2078 Py_DECREF(x);
2079#endif
2080#ifdef AL_BAD_CONFIG
2081 x = PyInt_FromLong((long) AL_BAD_CONFIG);
2082 if (x == NULL || PyDict_SetItemString(d, "BAD_CONFIG", x) < 0)
2083 goto error;
2084 Py_DECREF(x);
2085#endif
2086#ifdef AL_BAD_COUNT_NEG
2087 x = PyInt_FromLong((long) AL_BAD_COUNT_NEG);
2088 if (x == NULL || PyDict_SetItemString(d, "BAD_COUNT_NEG", x) < 0)
2089 goto error;
2090 Py_DECREF(x);
2091#endif
2092#ifdef AL_BAD_DEVICE
2093 x = PyInt_FromLong((long) AL_BAD_DEVICE);
2094 if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE", x) < 0)
2095 goto error;
2096 Py_DECREF(x);
2097#endif
2098#ifdef AL_BAD_DEVICE_ACCESS
2099 x = PyInt_FromLong((long) AL_BAD_DEVICE_ACCESS);
2100 if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE_ACCESS", x) < 0)
2101 goto error;
2102 Py_DECREF(x);
2103#endif
2104#ifdef AL_BAD_DIRECTION
2105 x = PyInt_FromLong((long) AL_BAD_DIRECTION);
2106 if (x == NULL || PyDict_SetItemString(d, "BAD_DIRECTION", x) < 0)
2107 goto error;
2108 Py_DECREF(x);
2109#endif
2110#ifdef AL_BAD_FILLPOINT
2111 x = PyInt_FromLong((long) AL_BAD_FILLPOINT);
2112 if (x == NULL || PyDict_SetItemString(d, "BAD_FILLPOINT", x) < 0)
2113 goto error;
2114 Py_DECREF(x);
2115#endif
2116#ifdef AL_BAD_FLOATMAX
2117 x = PyInt_FromLong((long) AL_BAD_FLOATMAX);
2118 if (x == NULL || PyDict_SetItemString(d, "BAD_FLOATMAX", x) < 0)
2119 goto error;
2120 Py_DECREF(x);
2121#endif
2122#ifdef AL_BAD_ILLEGAL_STATE
2123 x = PyInt_FromLong((long) AL_BAD_ILLEGAL_STATE);
2124 if (x == NULL || PyDict_SetItemString(d, "BAD_ILLEGAL_STATE", x) < 0)
2125 goto error;
2126 Py_DECREF(x);
2127#endif
2128#ifdef AL_BAD_NO_PORTS
2129 x = PyInt_FromLong((long) AL_BAD_NO_PORTS);
2130 if (x == NULL || PyDict_SetItemString(d, "BAD_NO_PORTS", x) < 0)
2131 goto error;
2132 Py_DECREF(x);
2133#endif
2134#ifdef AL_BAD_NOT_FOUND
2135 x = PyInt_FromLong((long) AL_BAD_NOT_FOUND);
2136 if (x == NULL || PyDict_SetItemString(d, "BAD_NOT_FOUND", x) < 0)
2137 goto error;
2138 Py_DECREF(x);
2139#endif
2140#ifdef AL_BAD_NOT_IMPLEMENTED
2141 x = PyInt_FromLong((long) AL_BAD_NOT_IMPLEMENTED);
2142 if (x == NULL || PyDict_SetItemString(d, "BAD_NOT_IMPLEMENTED", x) < 0)
2143 goto error;
2144 Py_DECREF(x);
2145#endif
2146#ifdef AL_BAD_OUT_OF_MEM
2147 x = PyInt_FromLong((long) AL_BAD_OUT_OF_MEM);
2148 if (x == NULL || PyDict_SetItemString(d, "BAD_OUT_OF_MEM", x) < 0)
2149 goto error;
2150 Py_DECREF(x);
2151#endif
2152#ifdef AL_BAD_PARAM
2153 x = PyInt_FromLong((long) AL_BAD_PARAM);
2154 if (x == NULL || PyDict_SetItemString(d, "BAD_PARAM", x) < 0)
2155 goto error;
2156 Py_DECREF(x);
2157#endif
2158#ifdef AL_BAD_PERMISSIONS
2159 x = PyInt_FromLong((long) AL_BAD_PERMISSIONS);
2160 if (x == NULL || PyDict_SetItemString(d, "BAD_PERMISSIONS", x) < 0)
2161 goto error;
2162 Py_DECREF(x);
2163#endif
2164#ifdef AL_BAD_PORT
2165 x = PyInt_FromLong((long) AL_BAD_PORT);
2166 if (x == NULL || PyDict_SetItemString(d, "BAD_PORT", x) < 0)
2167 goto error;
2168 Py_DECREF(x);
2169#endif
2170#ifdef AL_BAD_PORTSTYLE
2171 x = PyInt_FromLong((long) AL_BAD_PORTSTYLE);
2172 if (x == NULL || PyDict_SetItemString(d, "BAD_PORTSTYLE", x) < 0)
2173 goto error;
2174 Py_DECREF(x);
2175#endif
2176#ifdef AL_BAD_PVBUFFER
2177 x = PyInt_FromLong((long) AL_BAD_PVBUFFER);
2178 if (x == NULL || PyDict_SetItemString(d, "BAD_PVBUFFER", x) < 0)
2179 goto error;
2180 Py_DECREF(x);
2181#endif
2182#ifdef AL_BAD_QSIZE
2183 x = PyInt_FromLong((long) AL_BAD_QSIZE);
2184 if (x == NULL || PyDict_SetItemString(d, "BAD_QSIZE", x) < 0)
2185 goto error;
2186 Py_DECREF(x);
2187#endif
2188#ifdef AL_BAD_RATE
2189 x = PyInt_FromLong((long) AL_BAD_RATE);
2190 if (x == NULL || PyDict_SetItemString(d, "BAD_RATE", x) < 0)
2191 goto error;
2192 Py_DECREF(x);
2193#endif
2194#ifdef AL_BAD_RESOURCE
2195 x = PyInt_FromLong((long) AL_BAD_RESOURCE);
2196 if (x == NULL || PyDict_SetItemString(d, "BAD_RESOURCE", x) < 0)
2197 goto error;
2198 Py_DECREF(x);
2199#endif
2200#ifdef AL_BAD_SAMPFMT
2201 x = PyInt_FromLong((long) AL_BAD_SAMPFMT);
2202 if (x == NULL || PyDict_SetItemString(d, "BAD_SAMPFMT", x) < 0)
2203 goto error;
2204 Py_DECREF(x);
2205#endif
2206#ifdef AL_BAD_TRANSFER_SIZE
2207 x = PyInt_FromLong((long) AL_BAD_TRANSFER_SIZE);
2208 if (x == NULL || PyDict_SetItemString(d, "BAD_TRANSFER_SIZE", x) < 0)
2209 goto error;
2210 Py_DECREF(x);
2211#endif
2212#ifdef AL_BAD_WIDTH
2213 x = PyInt_FromLong((long) AL_BAD_WIDTH);
2214 if (x == NULL || PyDict_SetItemString(d, "BAD_WIDTH", x) < 0)
2215 goto error;
2216 Py_DECREF(x);
2217#endif
2218#ifdef AL_CHANNEL_MODE
2219 x = PyInt_FromLong((long) AL_CHANNEL_MODE);
2220 if (x == NULL || PyDict_SetItemString(d, "CHANNEL_MODE", x) < 0)
2221 goto error;
2222 Py_DECREF(x);
2223#endif
2224#ifdef AL_CHANNELS
2225 x = PyInt_FromLong((long) AL_CHANNELS);
2226 if (x == NULL || PyDict_SetItemString(d, "CHANNELS", x) < 0)
2227 goto error;
2228 Py_DECREF(x);
2229#endif
2230#ifdef AL_CHAR_ELEM
2231 x = PyInt_FromLong((long) AL_CHAR_ELEM);
2232 if (x == NULL || PyDict_SetItemString(d, "CHAR_ELEM", x) < 0)
2233 goto error;
2234 Py_DECREF(x);
2235#endif
2236#ifdef AL_CLOCK_GEN
2237 x = PyInt_FromLong((long) AL_CLOCK_GEN);
2238 if (x == NULL || PyDict_SetItemString(d, "CLOCK_GEN", x) < 0)
2239 goto error;
2240 Py_DECREF(x);
2241#endif
2242#ifdef AL_CLOCKGEN_TYPE
2243 x = PyInt_FromLong((long) AL_CLOCKGEN_TYPE);
2244 if (x == NULL || PyDict_SetItemString(d, "CLOCKGEN_TYPE", x) < 0)
2245 goto error;
2246 Py_DECREF(x);
2247#endif
2248#ifdef AL_CONNECT
2249 x = PyInt_FromLong((long) AL_CONNECT);
2250 if (x == NULL || PyDict_SetItemString(d, "CONNECT", x) < 0)
2251 goto error;
2252 Py_DECREF(x);
2253#endif
2254#ifdef AL_CONNECTION_TYPE
2255 x = PyInt_FromLong((long) AL_CONNECTION_TYPE);
2256 if (x == NULL || PyDict_SetItemString(d, "CONNECTION_TYPE", x) < 0)
2257 goto error;
2258 Py_DECREF(x);
2259#endif
2260#ifdef AL_CONNECTIONS
2261 x = PyInt_FromLong((long) AL_CONNECTIONS);
2262 if (x == NULL || PyDict_SetItemString(d, "CONNECTIONS", x) < 0)
2263 goto error;
2264 Py_DECREF(x);
2265#endif
2266#ifdef AL_CRYSTAL_MCLK_TYPE
2267 x = PyInt_FromLong((long) AL_CRYSTAL_MCLK_TYPE);
2268 if (x == NULL || PyDict_SetItemString(d, "CRYSTAL_MCLK_TYPE", x) < 0)
2269 goto error;
2270 Py_DECREF(x);
2271#endif
2272#ifdef AL_DEFAULT_DEVICE
2273 x = PyInt_FromLong((long) AL_DEFAULT_DEVICE);
2274 if (x == NULL || PyDict_SetItemString(d, "DEFAULT_DEVICE", x) < 0)
2275 goto error;
2276 Py_DECREF(x);
2277#endif
2278#ifdef AL_DEFAULT_INPUT
2279 x = PyInt_FromLong((long) AL_DEFAULT_INPUT);
2280 if (x == NULL || PyDict_SetItemString(d, "DEFAULT_INPUT", x) < 0)
2281 goto error;
2282 Py_DECREF(x);
2283#endif
2284#ifdef AL_DEFAULT_OUTPUT
2285 x = PyInt_FromLong((long) AL_DEFAULT_OUTPUT);
2286 if (x == NULL || PyDict_SetItemString(d, "DEFAULT_OUTPUT", x) < 0)
2287 goto error;
2288 Py_DECREF(x);
2289#endif
2290#ifdef AL_DEST
2291 x = PyInt_FromLong((long) AL_DEST);
2292 if (x == NULL || PyDict_SetItemString(d, "DEST", x) < 0)
2293 goto error;
2294 Py_DECREF(x);
2295#endif
2296#ifdef AL_DEVICE_TYPE
2297 x = PyInt_FromLong((long) AL_DEVICE_TYPE);
2298 if (x == NULL || PyDict_SetItemString(d, "DEVICE_TYPE", x) < 0)
2299 goto error;
2300 Py_DECREF(x);
2301#endif
2302#ifdef AL_DEVICES
2303 x = PyInt_FromLong((long) AL_DEVICES);
2304 if (x == NULL || PyDict_SetItemString(d, "DEVICES", x) < 0)
2305 goto error;
2306 Py_DECREF(x);
2307#endif
2308#ifdef AL_DIGITAL_IF_TYPE
2309 x = PyInt_FromLong((long) AL_DIGITAL_IF_TYPE);
2310 if (x == NULL || PyDict_SetItemString(d, "DIGITAL_IF_TYPE", x) < 0)
2311 goto error;
2312 Py_DECREF(x);
2313#endif
2314#ifdef AL_DIGITAL_INPUT_RATE
2315 x = PyInt_FromLong((long) AL_DIGITAL_INPUT_RATE);
2316 if (x == NULL || PyDict_SetItemString(d, "DIGITAL_INPUT_RATE", x) < 0)
2317 goto error;
2318 Py_DECREF(x);
2319#endif
2320#ifdef AL_DISCONNECT
2321 x = PyInt_FromLong((long) AL_DISCONNECT);
2322 if (x == NULL || PyDict_SetItemString(d, "DISCONNECT", x) < 0)
2323 goto error;
2324 Py_DECREF(x);
2325#endif
2326#ifdef AL_ENUM_ELEM
2327 x = PyInt_FromLong((long) AL_ENUM_ELEM);
2328 if (x == NULL || PyDict_SetItemString(d, "ENUM_ELEM", x) < 0)
2329 goto error;
2330 Py_DECREF(x);
2331#endif
2332#ifdef AL_ENUM_VALUE
2333 x = PyInt_FromLong((long) AL_ENUM_VALUE);
2334 if (x == NULL || PyDict_SetItemString(d, "ENUM_VALUE", x) < 0)
2335 goto error;
2336 Py_DECREF(x);
2337#endif
2338#ifdef AL_ERROR_INPUT_OVERFLOW
2339 x = PyInt_FromLong((long) AL_ERROR_INPUT_OVERFLOW);
2340 if (x == NULL || PyDict_SetItemString(d, "ERROR_INPUT_OVERFLOW", x) < 0)
2341 goto error;
2342 Py_DECREF(x);
2343#endif
2344#ifdef AL_ERROR_LENGTH
2345 x = PyInt_FromLong((long) AL_ERROR_LENGTH);
2346 if (x == NULL || PyDict_SetItemString(d, "ERROR_LENGTH", x) < 0)
2347 goto error;
2348 Py_DECREF(x);
2349#endif
2350#ifdef AL_ERROR_LOCATION_LSP
2351 x = PyInt_FromLong((long) AL_ERROR_LOCATION_LSP);
2352 if (x == NULL || PyDict_SetItemString(d, "ERROR_LOCATION_LSP", x) < 0)
2353 goto error;
2354 Py_DECREF(x);
2355#endif
2356#ifdef AL_ERROR_LOCATION_MSP
2357 x = PyInt_FromLong((long) AL_ERROR_LOCATION_MSP);
2358 if (x == NULL || PyDict_SetItemString(d, "ERROR_LOCATION_MSP", x) < 0)
2359 goto error;
2360 Py_DECREF(x);
2361#endif
2362#ifdef AL_ERROR_NUMBER
2363 x = PyInt_FromLong((long) AL_ERROR_NUMBER);
2364 if (x == NULL || PyDict_SetItemString(d, "ERROR_NUMBER", x) < 0)
2365 goto error;
2366 Py_DECREF(x);
2367#endif
2368#ifdef AL_ERROR_OUTPUT_UNDERFLOW
2369 x = PyInt_FromLong((long) AL_ERROR_OUTPUT_UNDERFLOW);
2370 if (x == NULL || PyDict_SetItemString(d, "ERROR_OUTPUT_UNDERFLOW", x) < 0)
2371 goto error;
2372 Py_DECREF(x);
2373#endif
2374#ifdef AL_ERROR_TYPE
2375 x = PyInt_FromLong((long) AL_ERROR_TYPE);
2376 if (x == NULL || PyDict_SetItemString(d, "ERROR_TYPE", x) < 0)
2377 goto error;
2378 Py_DECREF(x);
2379#endif
2380#ifdef AL_FIXED_ELEM
2381 x = PyInt_FromLong((long) AL_FIXED_ELEM);
2382 if (x == NULL || PyDict_SetItemString(d, "FIXED_ELEM", x) < 0)
2383 goto error;
2384 Py_DECREF(x);
2385#endif
2386#ifdef AL_FIXED_MCLK_TYPE
2387 x = PyInt_FromLong((long) AL_FIXED_MCLK_TYPE);
2388 if (x == NULL || PyDict_SetItemString(d, "FIXED_MCLK_TYPE", x) < 0)
2389 goto error;
2390 Py_DECREF(x);
2391#endif
2392#ifdef AL_GAIN
2393 x = PyInt_FromLong((long) AL_GAIN);
2394 if (x == NULL || PyDict_SetItemString(d, "GAIN", x) < 0)
2395 goto error;
2396 Py_DECREF(x);
2397#endif
2398#ifdef AL_GAIN_REF
2399 x = PyInt_FromLong((long) AL_GAIN_REF);
2400 if (x == NULL || PyDict_SetItemString(d, "GAIN_REF", x) < 0)
2401 goto error;
2402 Py_DECREF(x);
2403#endif
2404#ifdef AL_HRB_TYPE
2405 x = PyInt_FromLong((long) AL_HRB_TYPE);
2406 if (x == NULL || PyDict_SetItemString(d, "HRB_TYPE", x) < 0)
2407 goto error;
2408 Py_DECREF(x);
2409#endif
2410#ifdef AL_INPUT_COUNT
2411 x = PyInt_FromLong((long) AL_INPUT_COUNT);
2412 if (x == NULL || PyDict_SetItemString(d, "INPUT_COUNT", x) < 0)
2413 goto error;
2414 Py_DECREF(x);
2415#endif
2416#ifdef AL_INPUT_DEVICE_TYPE
2417 x = PyInt_FromLong((long) AL_INPUT_DEVICE_TYPE);
2418 if (x == NULL || PyDict_SetItemString(d, "INPUT_DEVICE_TYPE", x) < 0)
2419 goto error;
2420 Py_DECREF(x);
2421#endif
2422#ifdef AL_INPUT_DIGITAL
2423 x = PyInt_FromLong((long) AL_INPUT_DIGITAL);
2424 if (x == NULL || PyDict_SetItemString(d, "INPUT_DIGITAL", x) < 0)
2425 goto error;
2426 Py_DECREF(x);
2427#endif
2428#ifdef AL_INPUT_HRB_TYPE
2429 x = PyInt_FromLong((long) AL_INPUT_HRB_TYPE);
2430 if (x == NULL || PyDict_SetItemString(d, "INPUT_HRB_TYPE", x) < 0)
2431 goto error;
2432 Py_DECREF(x);
2433#endif
2434#ifdef AL_INPUT_LINE
2435 x = PyInt_FromLong((long) AL_INPUT_LINE);
2436 if (x == NULL || PyDict_SetItemString(d, "INPUT_LINE", x) < 0)
2437 goto error;
2438 Py_DECREF(x);
2439#endif
2440#ifdef AL_INPUT_MIC
2441 x = PyInt_FromLong((long) AL_INPUT_MIC);
2442 if (x == NULL || PyDict_SetItemString(d, "INPUT_MIC", x) < 0)
2443 goto error;
2444 Py_DECREF(x);
2445#endif
2446#ifdef AL_INPUT_PORT_TYPE
2447 x = PyInt_FromLong((long) AL_INPUT_PORT_TYPE);
2448 if (x == NULL || PyDict_SetItemString(d, "INPUT_PORT_TYPE", x) < 0)
2449 goto error;
2450 Py_DECREF(x);
2451#endif
2452#ifdef AL_INPUT_RATE
2453 x = PyInt_FromLong((long) AL_INPUT_RATE);
2454 if (x == NULL || PyDict_SetItemString(d, "INPUT_RATE", x) < 0)
2455 goto error;
2456 Py_DECREF(x);
2457#endif
2458#ifdef AL_INPUT_SOURCE
2459 x = PyInt_FromLong((long) AL_INPUT_SOURCE);
2460 if (x == NULL || PyDict_SetItemString(d, "INPUT_SOURCE", x) < 0)
2461 goto error;
2462 Py_DECREF(x);
2463#endif
2464#ifdef AL_INT32_ELEM
2465 x = PyInt_FromLong((long) AL_INT32_ELEM);
2466 if (x == NULL || PyDict_SetItemString(d, "INT32_ELEM", x) < 0)
2467 goto error;
2468 Py_DECREF(x);
2469#endif
2470#ifdef AL_INT64_ELEM
2471 x = PyInt_FromLong((long) AL_INT64_ELEM);
2472 if (x == NULL || PyDict_SetItemString(d, "INT64_ELEM", x) < 0)
2473 goto error;
2474 Py_DECREF(x);
2475#endif
2476#ifdef AL_INTERFACE
2477 x = PyInt_FromLong((long) AL_INTERFACE);
2478 if (x == NULL || PyDict_SetItemString(d, "INTERFACE", x) < 0)
2479 goto error;
2480 Py_DECREF(x);
2481#endif
2482#ifdef AL_INTERFACE_TYPE
2483 x = PyInt_FromLong((long) AL_INTERFACE_TYPE);
2484 if (x == NULL || PyDict_SetItemString(d, "INTERFACE_TYPE", x) < 0)
2485 goto error;
2486 Py_DECREF(x);
2487#endif
2488#ifdef AL_INVALID_PARAM
2489 x = PyInt_FromLong((long) AL_INVALID_PARAM);
2490 if (x == NULL || PyDict_SetItemString(d, "INVALID_PARAM", x) < 0)
2491 goto error;
2492 Py_DECREF(x);
2493#endif
2494#ifdef AL_INVALID_VALUE
2495 x = PyInt_FromLong((long) AL_INVALID_VALUE);
2496 if (x == NULL || PyDict_SetItemString(d, "INVALID_VALUE", x) < 0)
2497 goto error;
2498 Py_DECREF(x);
2499#endif
2500#ifdef AL_JITTER
2501 x = PyInt_FromLong((long) AL_JITTER);
2502 if (x == NULL || PyDict_SetItemString(d, "JITTER", x) < 0)
2503 goto error;
2504 Py_DECREF(x);
2505#endif
2506#ifdef AL_LABEL
2507 x = PyInt_FromLong((long) AL_LABEL);
2508 if (x == NULL || PyDict_SetItemString(d, "LABEL", x) < 0)
2509 goto error;
2510 Py_DECREF(x);
2511#endif
2512#ifdef AL_LEFT_INPUT_ATTEN
2513 x = PyInt_FromLong((long) AL_LEFT_INPUT_ATTEN);
2514 if (x == NULL || PyDict_SetItemString(d, "LEFT_INPUT_ATTEN", x) < 0)
2515 goto error;
2516 Py_DECREF(x);
2517#endif
2518#ifdef AL_LEFT_MONITOR_ATTEN
2519 x = PyInt_FromLong((long) AL_LEFT_MONITOR_ATTEN);
2520 if (x == NULL || PyDict_SetItemString(d, "LEFT_MONITOR_ATTEN", x) < 0)
2521 goto error;
2522 Py_DECREF(x);
2523#endif
2524#ifdef AL_LEFT_SPEAKER_GAIN
2525 x = PyInt_FromLong((long) AL_LEFT_SPEAKER_GAIN);
2526 if (x == NULL || PyDict_SetItemString(d, "LEFT_SPEAKER_GAIN", x) < 0)
2527 goto error;
2528 Py_DECREF(x);
2529#endif
2530#ifdef AL_LEFT1_INPUT_ATTEN
2531 x = PyInt_FromLong((long) AL_LEFT1_INPUT_ATTEN);
2532 if (x == NULL || PyDict_SetItemString(d, "LEFT1_INPUT_ATTEN", x) < 0)
2533 goto error;
2534 Py_DECREF(x);
2535#endif
2536#ifdef AL_LEFT2_INPUT_ATTEN
2537 x = PyInt_FromLong((long) AL_LEFT2_INPUT_ATTEN);
2538 if (x == NULL || PyDict_SetItemString(d, "LEFT2_INPUT_ATTEN", x) < 0)
2539 goto error;
2540 Py_DECREF(x);
2541#endif
2542#ifdef AL_LINE_IF_TYPE
2543 x = PyInt_FromLong((long) AL_LINE_IF_TYPE);
2544 if (x == NULL || PyDict_SetItemString(d, "LINE_IF_TYPE", x) < 0)
2545 goto error;
2546 Py_DECREF(x);
2547#endif
2548#ifdef AL_MASTER_CLOCK
2549 x = PyInt_FromLong((long) AL_MASTER_CLOCK);
2550 if (x == NULL || PyDict_SetItemString(d, "MASTER_CLOCK", x) < 0)
2551 goto error;
2552 Py_DECREF(x);
2553#endif
2554#ifdef AL_MATRIX_VAL
2555 x = PyInt_FromLong((long) AL_MATRIX_VAL);
2556 if (x == NULL || PyDict_SetItemString(d, "MATRIX_VAL", x) < 0)
2557 goto error;
2558 Py_DECREF(x);
2559#endif
2560#ifdef AL_MAX_ERROR
2561 x = PyInt_FromLong((long) AL_MAX_ERROR);
2562 if (x == NULL || PyDict_SetItemString(d, "MAX_ERROR", x) < 0)
2563 goto error;
2564 Py_DECREF(x);
2565#endif
2566#ifdef AL_MAX_EVENT_PARAM
2567 x = PyInt_FromLong((long) AL_MAX_EVENT_PARAM);
2568 if (x == NULL || PyDict_SetItemString(d, "MAX_EVENT_PARAM", x) < 0)
2569 goto error;
2570 Py_DECREF(x);
2571#endif
2572#ifdef AL_MAX_PBUFSIZE
2573 x = PyInt_FromLong((long) AL_MAX_PBUFSIZE);
2574 if (x == NULL || PyDict_SetItemString(d, "MAX_PBUFSIZE", x) < 0)
2575 goto error;
2576 Py_DECREF(x);
2577#endif
2578#ifdef AL_MAX_PORTS
2579 x = PyInt_FromLong((long) AL_MAX_PORTS);
2580 if (x == NULL || PyDict_SetItemString(d, "MAX_PORTS", x) < 0)
2581 goto error;
2582 Py_DECREF(x);
2583#endif
2584#ifdef AL_MAX_RESOURCE_ID
2585 x = PyInt_FromLong((long) AL_MAX_RESOURCE_ID);
2586 if (x == NULL || PyDict_SetItemString(d, "MAX_RESOURCE_ID", x) < 0)
2587 goto error;
2588 Py_DECREF(x);
2589#endif
2590#ifdef AL_MAX_SETSIZE
2591 x = PyInt_FromLong((long) AL_MAX_SETSIZE);
2592 if (x == NULL || PyDict_SetItemString(d, "MAX_SETSIZE", x) < 0)
2593 goto error;
2594 Py_DECREF(x);
2595#endif
2596#ifdef AL_MAX_STRLEN
2597 x = PyInt_FromLong((long) AL_MAX_STRLEN);
2598 if (x == NULL || PyDict_SetItemString(d, "MAX_STRLEN", x) < 0)
2599 goto error;
2600 Py_DECREF(x);
2601#endif
2602#ifdef AL_MCLK_TYPE
2603 x = PyInt_FromLong((long) AL_MCLK_TYPE);
2604 if (x == NULL || PyDict_SetItemString(d, "MCLK_TYPE", x) < 0)
2605 goto error;
2606 Py_DECREF(x);
2607#endif
2608#ifdef AL_MIC_IF_TYPE
2609 x = PyInt_FromLong((long) AL_MIC_IF_TYPE);
2610 if (x == NULL || PyDict_SetItemString(d, "MIC_IF_TYPE", x) < 0)
2611 goto error;
2612 Py_DECREF(x);
2613#endif
2614#ifdef AL_MONITOR_CTL
2615 x = PyInt_FromLong((long) AL_MONITOR_CTL);
2616 if (x == NULL || PyDict_SetItemString(d, "MONITOR_CTL", x) < 0)
2617 goto error;
2618 Py_DECREF(x);
2619#endif
2620#ifdef AL_MONITOR_OFF
2621 x = PyInt_FromLong((long) AL_MONITOR_OFF);
2622 if (x == NULL || PyDict_SetItemString(d, "MONITOR_OFF", x) < 0)
2623 goto error;
2624 Py_DECREF(x);
2625#endif
2626#ifdef AL_MONITOR_ON
2627 x = PyInt_FromLong((long) AL_MONITOR_ON);
2628 if (x == NULL || PyDict_SetItemString(d, "MONITOR_ON", x) < 0)
2629 goto error;
2630 Py_DECREF(x);
2631#endif
2632#ifdef AL_MONO
2633 x = PyInt_FromLong((long) AL_MONO);
2634 if (x == NULL || PyDict_SetItemString(d, "MONO", x) < 0)
2635 goto error;
2636 Py_DECREF(x);
2637#endif
2638#ifdef AL_MUTE
2639 x = PyInt_FromLong((long) AL_MUTE);
2640 if (x == NULL || PyDict_SetItemString(d, "MUTE", x) < 0)
2641 goto error;
2642 Py_DECREF(x);
2643#endif
2644#ifdef AL_NAME
2645 x = PyInt_FromLong((long) AL_NAME);
2646 if (x == NULL || PyDict_SetItemString(d, "NAME", x) < 0)
2647 goto error;
2648 Py_DECREF(x);
2649#endif
2650#ifdef AL_NEG_INFINITY
2651 x = PyInt_FromLong((long) AL_NEG_INFINITY);
2652 if (x == NULL || PyDict_SetItemString(d, "NEG_INFINITY", x) < 0)
2653 goto error;
2654 Py_DECREF(x);
2655#endif
2656#ifdef AL_NEG_INFINITY_BIT
2657 x = PyInt_FromLong((long) AL_NEG_INFINITY_BIT);
2658 if (x == NULL || PyDict_SetItemString(d, "NEG_INFINITY_BIT", x) < 0)
2659 goto error;
2660 Py_DECREF(x);
2661#endif
2662#ifdef AL_NO_CHANGE
2663 x = PyInt_FromLong((long) AL_NO_CHANGE);
2664 if (x == NULL || PyDict_SetItemString(d, "NO_CHANGE", x) < 0)
2665 goto error;
2666 Py_DECREF(x);
2667#endif
2668#ifdef AL_NO_CHANGE_BIT
2669 x = PyInt_FromLong((long) AL_NO_CHANGE_BIT);
2670 if (x == NULL || PyDict_SetItemString(d, "NO_CHANGE_BIT", x) < 0)
2671 goto error;
2672 Py_DECREF(x);
2673#endif
2674#ifdef AL_NO_ELEM
2675 x = PyInt_FromLong((long) AL_NO_ELEM);
2676 if (x == NULL || PyDict_SetItemString(d, "NO_ELEM", x) < 0)
2677 goto error;
2678 Py_DECREF(x);
2679#endif
2680#ifdef AL_NO_ERRORS
2681 x = PyInt_FromLong((long) AL_NO_ERRORS);
2682 if (x == NULL || PyDict_SetItemString(d, "NO_ERRORS", x) < 0)
2683 goto error;
2684 Py_DECREF(x);
2685#endif
2686#ifdef AL_NO_OP
2687 x = PyInt_FromLong((long) AL_NO_OP);
2688 if (x == NULL || PyDict_SetItemString(d, "NO_OP", x) < 0)
2689 goto error;
2690 Py_DECREF(x);
2691#endif
2692#ifdef AL_NO_VAL
2693 x = PyInt_FromLong((long) AL_NO_VAL);
2694 if (x == NULL || PyDict_SetItemString(d, "NO_VAL", x) < 0)
2695 goto error;
2696 Py_DECREF(x);
2697#endif
2698#ifdef AL_NULL_RESOURCE
2699 x = PyInt_FromLong((long) AL_NULL_RESOURCE);
2700 if (x == NULL || PyDict_SetItemString(d, "NULL_RESOURCE", x) < 0)
2701 goto error;
2702 Py_DECREF(x);
2703#endif
2704#ifdef AL_OUTPUT_COUNT
2705 x = PyInt_FromLong((long) AL_OUTPUT_COUNT);
2706 if (x == NULL || PyDict_SetItemString(d, "OUTPUT_COUNT", x) < 0)
2707 goto error;
2708 Py_DECREF(x);
2709#endif
2710#ifdef AL_OUTPUT_DEVICE_TYPE
2711 x = PyInt_FromLong((long) AL_OUTPUT_DEVICE_TYPE);
2712 if (x == NULL || PyDict_SetItemString(d, "OUTPUT_DEVICE_TYPE", x) < 0)
2713 goto error;
2714 Py_DECREF(x);
2715#endif
2716#ifdef AL_OUTPUT_HRB_TYPE
2717 x = PyInt_FromLong((long) AL_OUTPUT_HRB_TYPE);
2718 if (x == NULL || PyDict_SetItemString(d, "OUTPUT_HRB_TYPE", x) < 0)
2719 goto error;
2720 Py_DECREF(x);
2721#endif
2722#ifdef AL_OUTPUT_PORT_TYPE
2723 x = PyInt_FromLong((long) AL_OUTPUT_PORT_TYPE);
2724 if (x == NULL || PyDict_SetItemString(d, "OUTPUT_PORT_TYPE", x) < 0)
2725 goto error;
2726 Py_DECREF(x);
2727#endif
2728#ifdef AL_OUTPUT_RATE
2729 x = PyInt_FromLong((long) AL_OUTPUT_RATE);
2730 if (x == NULL || PyDict_SetItemString(d, "OUTPUT_RATE", x) < 0)
2731 goto error;
2732 Py_DECREF(x);
2733#endif
2734#ifdef AL_PARAM_BIT
2735 x = PyInt_FromLong((long) AL_PARAM_BIT);
2736 if (x == NULL || PyDict_SetItemString(d, "PARAM_BIT", x) < 0)
2737 goto error;
2738 Py_DECREF(x);
2739#endif
2740#ifdef AL_PARAMS
2741 x = PyInt_FromLong((long) AL_PARAMS);
2742 if (x == NULL || PyDict_SetItemString(d, "PARAMS", x) < 0)
2743 goto error;
2744 Py_DECREF(x);
2745#endif
2746#ifdef AL_PORT_COUNT
2747 x = PyInt_FromLong((long) AL_PORT_COUNT);
2748 if (x == NULL || PyDict_SetItemString(d, "PORT_COUNT", x) < 0)
2749 goto error;
2750 Py_DECREF(x);
2751#endif
2752#ifdef AL_PORT_TYPE
2753 x = PyInt_FromLong((long) AL_PORT_TYPE);
2754 if (x == NULL || PyDict_SetItemString(d, "PORT_TYPE", x) < 0)
2755 goto error;
2756 Py_DECREF(x);
2757#endif
2758#ifdef AL_PORTS
2759 x = PyInt_FromLong((long) AL_PORTS);
2760 if (x == NULL || PyDict_SetItemString(d, "PORTS", x) < 0)
2761 goto error;
2762 Py_DECREF(x);
2763#endif
2764#ifdef AL_PORTSTYLE_DIRECT
2765 x = PyInt_FromLong((long) AL_PORTSTYLE_DIRECT);
2766 if (x == NULL || PyDict_SetItemString(d, "PORTSTYLE_DIRECT", x) < 0)
2767 goto error;
2768 Py_DECREF(x);
2769#endif
2770#ifdef AL_PORTSTYLE_SERIAL
2771 x = PyInt_FromLong((long) AL_PORTSTYLE_SERIAL);
2772 if (x == NULL || PyDict_SetItemString(d, "PORTSTYLE_SERIAL", x) < 0)
2773 goto error;
2774 Py_DECREF(x);
2775#endif
2776#ifdef AL_PRINT_ERRORS
2777 x = PyInt_FromLong((long) AL_PRINT_ERRORS);
2778 if (x == NULL || PyDict_SetItemString(d, "PRINT_ERRORS", x) < 0)
2779 goto error;
2780 Py_DECREF(x);
2781#endif
2782#ifdef AL_PTR_ELEM
2783 x = PyInt_FromLong((long) AL_PTR_ELEM);
2784 if (x == NULL || PyDict_SetItemString(d, "PTR_ELEM", x) < 0)
2785 goto error;
2786 Py_DECREF(x);
2787#endif
2788#ifdef AL_RANGE_VALUE
2789 x = PyInt_FromLong((long) AL_RANGE_VALUE);
2790 if (x == NULL || PyDict_SetItemString(d, "RANGE_VALUE", x) < 0)
2791 goto error;
2792 Py_DECREF(x);
2793#endif
2794#ifdef AL_RATE
2795 x = PyInt_FromLong((long) AL_RATE);
2796 if (x == NULL || PyDict_SetItemString(d, "RATE", x) < 0)
2797 goto error;
2798 Py_DECREF(x);
2799#endif
2800#ifdef AL_RATE_11025
2801 x = PyInt_FromLong((long) AL_RATE_11025);
2802 if (x == NULL || PyDict_SetItemString(d, "RATE_11025", x) < 0)
2803 goto error;
2804 Py_DECREF(x);
2805#endif
2806#ifdef AL_RATE_16000
2807 x = PyInt_FromLong((long) AL_RATE_16000);
2808 if (x == NULL || PyDict_SetItemString(d, "RATE_16000", x) < 0)
2809 goto error;
2810 Py_DECREF(x);
2811#endif
2812#ifdef AL_RATE_22050
2813 x = PyInt_FromLong((long) AL_RATE_22050);
2814 if (x == NULL || PyDict_SetItemString(d, "RATE_22050", x) < 0)
2815 goto error;
2816 Py_DECREF(x);
2817#endif
2818#ifdef AL_RATE_32000
2819 x = PyInt_FromLong((long) AL_RATE_32000);
2820 if (x == NULL || PyDict_SetItemString(d, "RATE_32000", x) < 0)
2821 goto error;
2822 Py_DECREF(x);
2823#endif
2824#ifdef AL_RATE_44100
2825 x = PyInt_FromLong((long) AL_RATE_44100);
2826 if (x == NULL || PyDict_SetItemString(d, "RATE_44100", x) < 0)
2827 goto error;
2828 Py_DECREF(x);
2829#endif
2830#ifdef AL_RATE_48000
2831 x = PyInt_FromLong((long) AL_RATE_48000);
2832 if (x == NULL || PyDict_SetItemString(d, "RATE_48000", x) < 0)
2833 goto error;
2834 Py_DECREF(x);
2835#endif
2836#ifdef AL_RATE_8000
2837 x = PyInt_FromLong((long) AL_RATE_8000);
2838 if (x == NULL || PyDict_SetItemString(d, "RATE_8000", x) < 0)
2839 goto error;
2840 Py_DECREF(x);
2841#endif
2842#ifdef AL_RATE_AES_1
2843 x = PyInt_FromLong((long) AL_RATE_AES_1);
2844 if (x == NULL || PyDict_SetItemString(d, "RATE_AES_1", x) < 0)
2845 goto error;
2846 Py_DECREF(x);
2847#endif
2848#ifdef AL_RATE_AES_1s
2849 x = PyInt_FromLong((long) AL_RATE_AES_1s);
2850 if (x == NULL || PyDict_SetItemString(d, "RATE_AES_1s", x) < 0)
2851 goto error;
2852 Py_DECREF(x);
2853#endif
2854#ifdef AL_RATE_AES_2
2855 x = PyInt_FromLong((long) AL_RATE_AES_2);
2856 if (x == NULL || PyDict_SetItemString(d, "RATE_AES_2", x) < 0)
2857 goto error;
2858 Py_DECREF(x);
2859#endif
2860#ifdef AL_RATE_AES_3
2861 x = PyInt_FromLong((long) AL_RATE_AES_3);
2862 if (x == NULL || PyDict_SetItemString(d, "RATE_AES_3", x) < 0)
2863 goto error;
2864 Py_DECREF(x);
2865#endif
2866#ifdef AL_RATE_AES_4
2867 x = PyInt_FromLong((long) AL_RATE_AES_4);
2868 if (x == NULL || PyDict_SetItemString(d, "RATE_AES_4", x) < 0)
2869 goto error;
2870 Py_DECREF(x);
2871#endif
2872#ifdef AL_RATE_AES_6
2873 x = PyInt_FromLong((long) AL_RATE_AES_6);
2874 if (x == NULL || PyDict_SetItemString(d, "RATE_AES_6", x) < 0)
2875 goto error;
2876 Py_DECREF(x);
2877#endif
2878#ifdef AL_RATE_FRACTION_D
2879 x = PyInt_FromLong((long) AL_RATE_FRACTION_D);
2880 if (x == NULL || PyDict_SetItemString(d, "RATE_FRACTION_D", x) < 0)
2881 goto error;
2882 Py_DECREF(x);
2883#endif
2884#ifdef AL_RATE_FRACTION_N
2885 x = PyInt_FromLong((long) AL_RATE_FRACTION_N);
2886 if (x == NULL || PyDict_SetItemString(d, "RATE_FRACTION_N", x) < 0)
2887 goto error;
2888 Py_DECREF(x);
2889#endif
2890#ifdef AL_RATE_INPUTRATE
2891 x = PyInt_FromLong((long) AL_RATE_INPUTRATE);
2892 if (x == NULL || PyDict_SetItemString(d, "RATE_INPUTRATE", x) < 0)
2893 goto error;
2894 Py_DECREF(x);
2895#endif
2896#ifdef AL_RATE_NO_DIGITAL_INPUT
2897 x = PyInt_FromLong((long) AL_RATE_NO_DIGITAL_INPUT);
2898 if (x == NULL || PyDict_SetItemString(d, "RATE_NO_DIGITAL_INPUT", x) < 0)
2899 goto error;
2900 Py_DECREF(x);
2901#endif
2902#ifdef AL_RATE_UNACQUIRED
2903 x = PyInt_FromLong((long) AL_RATE_UNACQUIRED);
2904 if (x == NULL || PyDict_SetItemString(d, "RATE_UNACQUIRED", x) < 0)
2905 goto error;
2906 Py_DECREF(x);
2907#endif
2908#ifdef AL_RATE_UNDEFINED
2909 x = PyInt_FromLong((long) AL_RATE_UNDEFINED);
2910 if (x == NULL || PyDict_SetItemString(d, "RATE_UNDEFINED", x) < 0)
2911 goto error;
2912 Py_DECREF(x);
2913#endif
2914#ifdef AL_REF_0DBV
2915 x = PyInt_FromLong((long) AL_REF_0DBV);
2916 if (x == NULL || PyDict_SetItemString(d, "REF_0DBV", x) < 0)
2917 goto error;
2918 Py_DECREF(x);
2919#endif
2920#ifdef AL_REF_NONE
2921 x = PyInt_FromLong((long) AL_REF_NONE);
2922 if (x == NULL || PyDict_SetItemString(d, "REF_NONE", x) < 0)
2923 goto error;
2924 Py_DECREF(x);
2925#endif
2926#ifdef AL_RESERVED1_TYPE
2927 x = PyInt_FromLong((long) AL_RESERVED1_TYPE);
2928 if (x == NULL || PyDict_SetItemString(d, "RESERVED1_TYPE", x) < 0)
2929 goto error;
2930 Py_DECREF(x);
2931#endif
2932#ifdef AL_RESERVED2_TYPE
2933 x = PyInt_FromLong((long) AL_RESERVED2_TYPE);
2934 if (x == NULL || PyDict_SetItemString(d, "RESERVED2_TYPE", x) < 0)
2935 goto error;
2936 Py_DECREF(x);
2937#endif
2938#ifdef AL_RESERVED3_TYPE
2939 x = PyInt_FromLong((long) AL_RESERVED3_TYPE);
2940 if (x == NULL || PyDict_SetItemString(d, "RESERVED3_TYPE", x) < 0)
2941 goto error;
2942 Py_DECREF(x);
2943#endif
2944#ifdef AL_RESERVED4_TYPE
2945 x = PyInt_FromLong((long) AL_RESERVED4_TYPE);
2946 if (x == NULL || PyDict_SetItemString(d, "RESERVED4_TYPE", x) < 0)
2947 goto error;
2948 Py_DECREF(x);
2949#endif
2950#ifdef AL_RESOURCE
2951 x = PyInt_FromLong((long) AL_RESOURCE);
2952 if (x == NULL || PyDict_SetItemString(d, "RESOURCE", x) < 0)
2953 goto error;
2954 Py_DECREF(x);
2955#endif
2956#ifdef AL_RESOURCE_ELEM
2957 x = PyInt_FromLong((long) AL_RESOURCE_ELEM);
2958 if (x == NULL || PyDict_SetItemString(d, "RESOURCE_ELEM", x) < 0)
2959 goto error;
2960 Py_DECREF(x);
2961#endif
2962#ifdef AL_RESOURCE_TYPE
2963 x = PyInt_FromLong((long) AL_RESOURCE_TYPE);
2964 if (x == NULL || PyDict_SetItemString(d, "RESOURCE_TYPE", x) < 0)
2965 goto error;
2966 Py_DECREF(x);
2967#endif
2968#ifdef AL_RIGHT_INPUT_ATTEN
2969 x = PyInt_FromLong((long) AL_RIGHT_INPUT_ATTEN);
2970 if (x == NULL || PyDict_SetItemString(d, "RIGHT_INPUT_ATTEN", x) < 0)
2971 goto error;
2972 Py_DECREF(x);
2973#endif
2974#ifdef AL_RIGHT_MONITOR_ATTEN
2975 x = PyInt_FromLong((long) AL_RIGHT_MONITOR_ATTEN);
2976 if (x == NULL || PyDict_SetItemString(d, "RIGHT_MONITOR_ATTEN", x) < 0)
2977 goto error;
2978 Py_DECREF(x);
2979#endif
2980#ifdef AL_RIGHT_SPEAKER_GAIN
2981 x = PyInt_FromLong((long) AL_RIGHT_SPEAKER_GAIN);
2982 if (x == NULL || PyDict_SetItemString(d, "RIGHT_SPEAKER_GAIN", x) < 0)
2983 goto error;
2984 Py_DECREF(x);
2985#endif
2986#ifdef AL_RIGHT1_INPUT_ATTEN
2987 x = PyInt_FromLong((long) AL_RIGHT1_INPUT_ATTEN);
2988 if (x == NULL || PyDict_SetItemString(d, "RIGHT1_INPUT_ATTEN", x) < 0)
2989 goto error;
2990 Py_DECREF(x);
2991#endif
2992#ifdef AL_RIGHT2_INPUT_ATTEN
2993 x = PyInt_FromLong((long) AL_RIGHT2_INPUT_ATTEN);
2994 if (x == NULL || PyDict_SetItemString(d, "RIGHT2_INPUT_ATTEN", x) < 0)
2995 goto error;
2996 Py_DECREF(x);
2997#endif
2998#ifdef AL_SAMPFMT_DOUBLE
2999 x = PyInt_FromLong((long) AL_SAMPFMT_DOUBLE);
3000 if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_DOUBLE", x) < 0)
3001 goto error;
3002 Py_DECREF(x);
3003#endif
3004#ifdef AL_SAMPFMT_FLOAT
3005 x = PyInt_FromLong((long) AL_SAMPFMT_FLOAT);
3006 if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_FLOAT", x) < 0)
3007 goto error;
3008 Py_DECREF(x);
3009#endif
3010#ifdef AL_SAMPFMT_TWOSCOMP
3011 x = PyInt_FromLong((long) AL_SAMPFMT_TWOSCOMP);
3012 if (x == NULL || PyDict_SetItemString(d, "SAMPFMT_TWOSCOMP", x) < 0)
3013 goto error;
3014 Py_DECREF(x);
3015#endif
3016#ifdef AL_SAMPLE_16
3017 x = PyInt_FromLong((long) AL_SAMPLE_16);
3018 if (x == NULL || PyDict_SetItemString(d, "SAMPLE_16", x) < 0)
3019 goto error;
3020 Py_DECREF(x);
3021#endif
3022#ifdef AL_SAMPLE_24
3023 x = PyInt_FromLong((long) AL_SAMPLE_24);
3024 if (x == NULL || PyDict_SetItemString(d, "SAMPLE_24", x) < 0)
3025 goto error;
3026 Py_DECREF(x);
3027#endif
3028#ifdef AL_SAMPLE_8
3029 x = PyInt_FromLong((long) AL_SAMPLE_8);
3030 if (x == NULL || PyDict_SetItemString(d, "SAMPLE_8", x) < 0)
3031 goto error;
3032 Py_DECREF(x);
3033#endif
3034#ifdef AL_SCALAR_VAL
3035 x = PyInt_FromLong((long) AL_SCALAR_VAL);
3036 if (x == NULL || PyDict_SetItemString(d, "SCALAR_VAL", x) < 0)
3037 goto error;
3038 Py_DECREF(x);
3039#endif
3040#ifdef AL_SET_VAL
3041 x = PyInt_FromLong((long) AL_SET_VAL);
3042 if (x == NULL || PyDict_SetItemString(d, "SET_VAL", x) < 0)
3043 goto error;
3044 Py_DECREF(x);
3045#endif
3046#ifdef AL_SHORT_NAME
3047 x = PyInt_FromLong((long) AL_SHORT_NAME);
3048 if (x == NULL || PyDict_SetItemString(d, "SHORT_NAME", x) < 0)
3049 goto error;
3050 Py_DECREF(x);
3051#endif
3052#ifdef AL_SOURCE
3053 x = PyInt_FromLong((long) AL_SOURCE);
3054 if (x == NULL || PyDict_SetItemString(d, "SOURCE", x) < 0)
3055 goto error;
3056 Py_DECREF(x);
3057#endif
3058#ifdef AL_SPEAKER_IF_TYPE
3059 x = PyInt_FromLong((long) AL_SPEAKER_IF_TYPE);
3060 if (x == NULL || PyDict_SetItemString(d, "SPEAKER_IF_TYPE", x) < 0)
3061 goto error;
3062 Py_DECREF(x);
3063#endif
3064#ifdef AL_SPEAKER_MUTE_CTL
3065 x = PyInt_FromLong((long) AL_SPEAKER_MUTE_CTL);
3066 if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_CTL", x) < 0)
3067 goto error;
3068 Py_DECREF(x);
3069#endif
3070#ifdef AL_SPEAKER_MUTE_OFF
3071 x = PyInt_FromLong((long) AL_SPEAKER_MUTE_OFF);
3072 if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_OFF", x) < 0)
3073 goto error;
3074 Py_DECREF(x);
3075#endif
3076#ifdef AL_SPEAKER_MUTE_ON
3077 x = PyInt_FromLong((long) AL_SPEAKER_MUTE_ON);
3078 if (x == NULL || PyDict_SetItemString(d, "SPEAKER_MUTE_ON", x) < 0)
3079 goto error;
3080 Py_DECREF(x);
3081#endif
3082#ifdef AL_SPEAKER_PLUS_LINE_IF_TYPE
3083 x = PyInt_FromLong((long) AL_SPEAKER_PLUS_LINE_IF_TYPE);
3084 if (x == NULL || PyDict_SetItemString(d, "SPEAKER_PLUS_LINE_IF_TYPE", x) < 0)
3085 goto error;
3086 Py_DECREF(x);
3087#endif
3088#ifdef AL_STEREO
3089 x = PyInt_FromLong((long) AL_STEREO);
3090 if (x == NULL || PyDict_SetItemString(d, "STEREO", x) < 0)
3091 goto error;
3092 Py_DECREF(x);
3093#endif
3094#ifdef AL_STRING_VAL
3095 x = PyInt_FromLong((long) AL_STRING_VAL);
3096 if (x == NULL || PyDict_SetItemString(d, "STRING_VAL", x) < 0)
3097 goto error;
3098 Py_DECREF(x);
3099#endif
3100#ifdef AL_SUBSYSTEM
3101 x = PyInt_FromLong((long) AL_SUBSYSTEM);
3102 if (x == NULL || PyDict_SetItemString(d, "SUBSYSTEM", x) < 0)
3103 goto error;
3104 Py_DECREF(x);
3105#endif
3106#ifdef AL_SUBSYSTEM_TYPE
3107 x = PyInt_FromLong((long) AL_SUBSYSTEM_TYPE);
3108 if (x == NULL || PyDict_SetItemString(d, "SUBSYSTEM_TYPE", x) < 0)
3109 goto error;
3110 Py_DECREF(x);
3111#endif
3112#ifdef AL_SYNC_INPUT_TO_AES
3113 x = PyInt_FromLong((long) AL_SYNC_INPUT_TO_AES);
3114 if (x == NULL || PyDict_SetItemString(d, "SYNC_INPUT_TO_AES", x) < 0)
3115 goto error;
3116 Py_DECREF(x);
3117#endif
3118#ifdef AL_SYNC_OUTPUT_TO_AES
3119 x = PyInt_FromLong((long) AL_SYNC_OUTPUT_TO_AES);
3120 if (x == NULL || PyDict_SetItemString(d, "SYNC_OUTPUT_TO_AES", x) < 0)
3121 goto error;
3122 Py_DECREF(x);
3123#endif
3124#ifdef AL_SYSTEM
3125 x = PyInt_FromLong((long) AL_SYSTEM);
3126 if (x == NULL || PyDict_SetItemString(d, "SYSTEM", x) < 0)
3127 goto error;
3128 Py_DECREF(x);
3129#endif
3130#ifdef AL_SYSTEM_TYPE
3131 x = PyInt_FromLong((long) AL_SYSTEM_TYPE);
3132 if (x == NULL || PyDict_SetItemString(d, "SYSTEM_TYPE", x) < 0)
3133 goto error;
3134 Py_DECREF(x);
3135#endif
3136#ifdef AL_TEST_IF_TYPE
3137 x = PyInt_FromLong((long) AL_TEST_IF_TYPE);
3138 if (x == NULL || PyDict_SetItemString(d, "TEST_IF_TYPE", x) < 0)
3139 goto error;
3140 Py_DECREF(x);
3141#endif
3142#ifdef AL_TYPE
3143 x = PyInt_FromLong((long) AL_TYPE);
3144 if (x == NULL || PyDict_SetItemString(d, "TYPE", x) < 0)
3145 goto error;
3146 Py_DECREF(x);
3147#endif
3148#ifdef AL_TYPE_BIT
3149 x = PyInt_FromLong((long) AL_TYPE_BIT);
3150 if (x == NULL || PyDict_SetItemString(d, "TYPE_BIT", x) < 0)
3151 goto error;
3152 Py_DECREF(x);
3153#endif
3154#ifdef AL_UNUSED_COUNT
3155 x = PyInt_FromLong((long) AL_UNUSED_COUNT);
3156 if (x == NULL || PyDict_SetItemString(d, "UNUSED_COUNT", x) < 0)
3157 goto error;
3158 Py_DECREF(x);
3159#endif
3160#ifdef AL_UNUSED_PORTS
3161 x = PyInt_FromLong((long) AL_UNUSED_PORTS);
3162 if (x == NULL || PyDict_SetItemString(d, "UNUSED_PORTS", x) < 0)
3163 goto error;
3164 Py_DECREF(x);
3165#endif
3166#ifdef AL_VARIABLE_MCLK_TYPE
3167 x = PyInt_FromLong((long) AL_VARIABLE_MCLK_TYPE);
3168 if (x == NULL || PyDict_SetItemString(d, "VARIABLE_MCLK_TYPE", x) < 0)
3169 goto error;
3170 Py_DECREF(x);
3171#endif
3172#ifdef AL_VECTOR_VAL
3173 x = PyInt_FromLong((long) AL_VECTOR_VAL);
3174 if (x == NULL || PyDict_SetItemString(d, "VECTOR_VAL", x) < 0)
3175 goto error;
3176 Py_DECREF(x);
3177#endif
3178#ifdef AL_VIDEO_MCLK_TYPE
3179 x = PyInt_FromLong((long) AL_VIDEO_MCLK_TYPE);
3180 if (x == NULL || PyDict_SetItemString(d, "VIDEO_MCLK_TYPE", x) < 0)
3181 goto error;
3182 Py_DECREF(x);
3183#endif
3184#ifdef AL_WORDSIZE
3185 x = PyInt_FromLong((long) AL_WORDSIZE);
3186 if (x == NULL || PyDict_SetItemString(d, "WORDSIZE", x) < 0)
3187 goto error;
3188 Py_DECREF(x);
3189#endif
3190
3191#ifdef AL_NO_ELEM /* IRIX 6 */
3192 (void) alSetErrorHandler(ErrorHandler);
3193#endif /* AL_NO_ELEM */
3194#ifdef OLD_INTERFACE
3195 (void) ALseterrorhandler(ErrorHandler);
3196#endif /* OLD_INTERFACE */
Guido van Rossume3db8621991-09-09 23:33:34 +00003197
Barry Warsaw9bfd2bf2000-09-01 09:01:32 +00003198 error:
3199 return;
Guido van Rossume3db8621991-09-09 23:33:34 +00003200}