PageRenderTime 828ms CodeModel.GetById 90ms app.highlight 520ms RepoModel.GetById 134ms app.codeStats 2ms

/Modules/almodule.c

http://unladen-swallow.googlecode.com/
C | 3232 lines | 2865 code | 328 blank | 39 comment | 874 complexity | 5a888f855852821b3ee48ea76475954b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1
   2#define OLD_INTERFACE		/* define for pre-Irix 6 interface */
   3
   4#include "Python.h"
   5#include "stringobject.h"
   6#include <audio.h>
   7#include <stdarg.h>
   8
   9#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 */
  20
  21typedef struct {
  22	PyObject_HEAD
  23	/* XXXX Add your own stuff here */
  24	ALport port;
  25} alpobject;
  26
  27static PyTypeObject Alptype;
  28
  29
  30
  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
  41static 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 */
  57
  58static PyObject *
  59param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo)
  60{
  61	ALparamInfo info;
  62
  63	if (pinfo == NULL) {
  64		pinfo = &info;
  65		if (alGetParamInfo(resource, param, &info) < 0)
  66			return NULL;
  67	}
  68	switch (pinfo->elementType) {
  69	case AL_PTR_ELEM:
  70		/* XXXX don't know how to handle this */
  71	case AL_NO_ELEM:
  72		Py_INCREF(Py_None);
  73		return Py_None;
  74	case AL_INT32_ELEM:
  75	case AL_RESOURCE_ELEM:
  76	case AL_ENUM_ELEM:
  77		return PyInt_FromLong((long) value.i);
  78	case AL_INT64_ELEM:
  79		return PyLong_FromLongLong(value.ll);
  80	case AL_FIXED_ELEM:
  81		return PyFloat_FromDouble(alFixedToDouble(value.ll));
  82	case AL_CHAR_ELEM:
  83		if (value.ptr == NULL) {
  84			Py_INCREF(Py_None);
  85			return Py_None;
  86		}
  87		return PyString_FromString((char *) value.ptr);
  88	default:
  89		PyErr_SetString(ErrorObject, "unknown element type");
  90		return NULL;
  91	}
  92}
  93
  94static int
  95python2elem(PyObject *item, void *ptr, int elementType)
  96{
  97	switch (elementType) {
  98	case AL_INT32_ELEM:
  99	case AL_RESOURCE_ELEM:
 100	case AL_ENUM_ELEM:
 101		if (!PyInt_Check(item)) {
 102			PyErr_BadArgument();
 103			return -1;
 104		}
 105		*((int *) ptr) = PyInt_AsLong(item);
 106		break;
 107	case AL_INT64_ELEM:
 108		if (PyInt_Check(item))
 109			*((long long *) ptr) = PyInt_AsLong(item);
 110		else if (PyLong_Check(item))
 111			*((long long *) ptr) = PyLong_AsLongLong(item);
 112		else {
 113			PyErr_BadArgument();
 114			return -1;
 115		}
 116		break;
 117	case AL_FIXED_ELEM:
 118		if (PyInt_Check(item))
 119			*((long long *) ptr) = alDoubleToFixed((double) PyInt_AsLong(item));
 120		else if (PyFloat_Check(item))
 121			*((long long *) ptr) = alDoubleToFixed(PyFloat_AsDouble(item));
 122		else {
 123			PyErr_BadArgument();
 124			return -1;
 125		}
 126		break;
 127	default:
 128		PyErr_SetString(ErrorObject, "unknown element type");
 129		return -1;
 130	}
 131	return 0;
 132}
 133
 134static int
 135python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo)
 136{
 137	ALparamInfo info;
 138	int i, stepsize;
 139	PyObject *item;
 140
 141	if (pinfo == NULL) {
 142		pinfo = &info;
 143		if (alGetParamInfo(resource, param->param, &info) < 0)
 144			return -1;
 145	}
 146	switch (pinfo->valueType) {
 147	case AL_STRING_VAL:
 148		if (pinfo->elementType != AL_CHAR_ELEM) {
 149			PyErr_SetString(ErrorObject, "unknown element type");
 150			return -1;
 151		}
 152		if (!PyString_Check(value)) {
 153			PyErr_BadArgument();
 154			return -1;
 155		}
 156		param->value.ptr = PyString_AS_STRING(value);
 157		param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/
 158		break;
 159	case AL_SET_VAL:
 160	case AL_VECTOR_VAL:
 161		if (!PyList_Check(value) && !PyTuple_Check(value)) {
 162			PyErr_BadArgument();
 163			return -1;
 164		}
 165		switch (pinfo->elementType) {
 166		case AL_INT32_ELEM:
 167		case AL_RESOURCE_ELEM:
 168		case AL_ENUM_ELEM:
 169			param->sizeIn = PySequence_Size(value);
 170			param->value.ptr = PyMem_NEW(int, param->sizeIn);
 171			stepsize = sizeof(int);
 172			break;
 173		case AL_INT64_ELEM:
 174		case AL_FIXED_ELEM:
 175			param->sizeIn = PySequence_Size(value);
 176			param->value.ptr = PyMem_NEW(long long, param->sizeIn);
 177			stepsize = sizeof(long long);
 178			break;
 179		}
 180		for (i = 0; i < param->sizeIn; i++) {
 181			item = PySequence_GetItem(value, i);
 182			if (python2elem(item, (void *) ((char *) param->value.ptr + i*stepsize), pinfo->elementType) < 0) {
 183				PyMem_DEL(param->value.ptr);
 184				return -1;
 185			}
 186		}
 187		break;
 188	case AL_SCALAR_VAL:
 189		switch (pinfo->elementType) {
 190		case AL_INT32_ELEM:
 191		case AL_RESOURCE_ELEM:
 192		case AL_ENUM_ELEM:
 193			return python2elem(value, (void *) &param->value.i,
 194					   pinfo->elementType);
 195		case AL_INT64_ELEM:
 196		case AL_FIXED_ELEM:
 197			return python2elem(value, (void *) &param->value.ll,
 198					   pinfo->elementType);
 199		default:
 200			PyErr_SetString(ErrorObject, "unknown element type");
 201			return -1;
 202		}
 203	}
 204	return 0;
 205}
 206
 207static int
 208python2params(int resource1, int resource2, PyObject *list, ALpv **pvsp, ALparamInfo **pinfop)
 209{
 210	PyObject *item;
 211	ALpv *pvs;
 212	ALparamInfo *pinfo;
 213	int npvs, i;
 214
 215	npvs = PyList_Size(list);
 216	pvs = PyMem_NEW(ALpv, npvs);
 217	pinfo = PyMem_NEW(ALparamInfo, npvs);
 218	for (i = 0; i < npvs; i++) {
 219		item = PyList_GetItem(list, i);
 220		if (!PyArg_ParseTuple(item, "iO", &pvs[i].param, &item))
 221			goto error;
 222		if (alGetParamInfo(resource1, pvs[i].param, &pinfo[i]) < 0 &&
 223		    alGetParamInfo(resource2, pvs[i].param, &pinfo[i]) < 0)
 224			goto error;
 225		if (python2param(resource1, &pvs[i], item, &pinfo[i]) < 0)
 226			goto error;
 227	}
 228
 229	*pvsp = pvs;
 230	*pinfop = pinfo;
 231	return npvs;
 232
 233  error:
 234	/* XXXX we should clean up everything */
 235	if (pvs)
 236		PyMem_DEL(pvs);
 237	if (pinfo)
 238		PyMem_DEL(pinfo);
 239	return -1;
 240}
 241
 242/* -------------------------------------------------------- */
 243
 244
 245static PyObject *
 246SetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig, int))
 247{
 248	int par;
 249
 250	if (!PyArg_ParseTuple(args, "i:SetConfig", &par))
 251		return NULL;
 252
 253	if ((*func)(self->config, par) == -1)
 254		return NULL;
 255
 256	Py_INCREF(Py_None);
 257	return Py_None;
 258}
 259
 260static PyObject *
 261GetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig))
 262{	
 263	int par;
 264
 265	if (!PyArg_ParseTuple(args, ":GetConfig"))
 266		return NULL;
 267	
 268	if ((par = (*func)(self->config)) == -1)
 269		return NULL;
 270
 271	return PyInt_FromLong((long) par);
 272}
 273
 274PyDoc_STRVAR(alc_SetWidth__doc__,
 275"alSetWidth: set the wordsize for integer audio data.");
 276
 277static PyObject *
 278alc_SetWidth(alcobject *self, PyObject *args)
 279{
 280	return SetConfig(self, args, alSetWidth);
 281}
 282
 283
 284PyDoc_STRVAR(alc_GetWidth__doc__,
 285"alGetWidth: get the wordsize for integer audio data.");
 286
 287static PyObject *
 288alc_GetWidth(alcobject *self, PyObject *args)
 289{
 290	return GetConfig(self, args, alGetWidth);
 291}
 292
 293
 294PyDoc_STRVAR(alc_SetSampFmt__doc__,
 295"alSetSampFmt: set the sample format setting in an audio ALconfig "
 296"structure.");
 297
 298static PyObject *
 299alc_SetSampFmt(alcobject *self, PyObject *args)
 300{
 301	return SetConfig(self, args, alSetSampFmt);
 302}
 303
 304
 305PyDoc_STRVAR(alc_GetSampFmt__doc__,
 306"alGetSampFmt: get the sample format setting in an audio ALconfig "
 307"structure.");
 308
 309static PyObject *
 310alc_GetSampFmt(alcobject *self, PyObject *args)
 311{
 312	return GetConfig(self, args, alGetSampFmt);
 313}
 314
 315
 316PyDoc_STRVAR(alc_SetChannels__doc__,
 317"alSetChannels: set the channel settings in an audio ALconfig.");
 318
 319static PyObject *
 320alc_SetChannels(alcobject *self, PyObject *args)
 321{
 322	return SetConfig(self, args, alSetChannels);
 323}
 324
 325
 326PyDoc_STRVAR(alc_GetChannels__doc__,
 327"alGetChannels: get the channel settings in an audio ALconfig.");
 328
 329static PyObject *
 330alc_GetChannels(alcobject *self, PyObject *args)
 331{
 332	return GetConfig(self, args, alGetChannels);
 333}
 334
 335
 336PyDoc_STRVAR(alc_SetFloatMax__doc__,
 337"alSetFloatMax: set the maximum value of floating point sample data.");
 338
 339static PyObject *
 340alc_SetFloatMax(alcobject *self, PyObject *args)
 341{
 342	double maximum_value;
 343
 344	if (!PyArg_ParseTuple(args, "d:SetFloatMax", &maximum_value))
 345		return NULL;
 346	if (alSetFloatMax(self->config, maximum_value) < 0)
 347		return NULL;
 348	Py_INCREF(Py_None);
 349	return Py_None;
 350}
 351
 352
 353PyDoc_STRVAR(alc_GetFloatMax__doc__,
 354"alGetFloatMax: get the maximum value of floating point sample data.");
 355
 356static PyObject *
 357alc_GetFloatMax(alcobject *self, PyObject *args)
 358{
 359	double maximum_value;
 360
 361	if (!PyArg_ParseTuple(args, ":GetFloatMax"))
 362		return NULL;
 363	if ((maximum_value = alGetFloatMax(self->config)) == 0)
 364		return NULL;
 365	return PyFloat_FromDouble(maximum_value);
 366}
 367
 368
 369PyDoc_STRVAR(alc_SetDevice__doc__,
 370"alSetDevice: set the device setting in an audio ALconfig structure.");
 371
 372static PyObject *
 373alc_SetDevice(alcobject *self, PyObject *args)
 374{
 375	return SetConfig(self, args, alSetDevice);
 376}
 377
 378
 379PyDoc_STRVAR(alc_GetDevice__doc__,
 380"alGetDevice: get the device setting in an audio ALconfig structure.");
 381
 382static PyObject *
 383alc_GetDevice(alcobject *self, PyObject *args)
 384{
 385	return GetConfig(self, args, alGetDevice);
 386}
 387
 388
 389PyDoc_STRVAR(alc_SetQueueSize__doc__,
 390"alSetQueueSize: set audio port buffer size.");
 391
 392static PyObject *
 393alc_SetQueueSize(alcobject *self, PyObject *args)
 394{
 395	return SetConfig(self, args, alSetQueueSize);
 396}
 397
 398
 399PyDoc_STRVAR(alc_GetQueueSize__doc__,
 400"alGetQueueSize: get audio port buffer size.");
 401
 402static PyObject *
 403alc_GetQueueSize(alcobject *self, PyObject *args)
 404{
 405	return GetConfig(self, args, alGetQueueSize);
 406}
 407
 408#endif /* AL_NO_ELEM */
 409
 410static PyObject *
 411setconfig(alcobject *self, PyObject *args, int (*func)(ALconfig, long))
 412{
 413	long par;
 414
 415	if (!PyArg_ParseTuple(args, "l:SetConfig", &par))
 416		return NULL;
 417
 418	if ((*func)(self->config, par) == -1)
 419		return NULL;
 420
 421	Py_INCREF(Py_None);
 422	return Py_None;
 423}
 424
 425static PyObject *
 426getconfig(alcobject *self, PyObject *args, long (*func)(ALconfig))
 427{	
 428	long par;
 429
 430	if (!PyArg_ParseTuple(args, ":GetConfig"))
 431		return NULL;
 432	
 433	if ((par = (*func)(self->config)) == -1)
 434		return NULL;
 435
 436	return PyInt_FromLong((long) par);
 437}
 438
 439static PyObject *
 440alc_setqueuesize (alcobject *self, PyObject *args)
 441{
 442	return setconfig(self, args, ALsetqueuesize);
 443}
 444
 445static PyObject *
 446alc_getqueuesize (alcobject *self, PyObject *args)
 447{
 448	return getconfig(self, args, ALgetqueuesize);
 449}
 450
 451static PyObject *
 452alc_setwidth (alcobject *self, PyObject *args)
 453{
 454	return setconfig(self, args, ALsetwidth);
 455}
 456
 457static PyObject *
 458alc_getwidth (alcobject *self, PyObject *args)
 459{
 460	return getconfig(self, args, ALgetwidth);	
 461}
 462
 463static PyObject *
 464alc_getchannels (alcobject *self, PyObject *args)
 465{
 466	return getconfig(self, args, ALgetchannels);	
 467}
 468
 469static PyObject *
 470alc_setchannels (alcobject *self, PyObject *args)
 471{
 472	return setconfig(self, args, ALsetchannels);
 473}
 474
 475#ifdef AL_405
 476
 477static PyObject *
 478alc_getsampfmt (alcobject *self, PyObject *args)
 479{
 480	return getconfig(self, args, ALgetsampfmt);	
 481}
 482
 483static PyObject *
 484alc_setsampfmt (alcobject *self, PyObject *args)
 485{
 486	return setconfig(self, args, ALsetsampfmt);
 487}
 488
 489static PyObject *
 490alc_getfloatmax(alcobject *self, PyObject *args)
 491{
 492	double arg;
 493
 494	if (!PyArg_ParseTuple(args, ":GetFloatMax"))
 495		return 0;
 496	if ((arg = ALgetfloatmax(self->config)) == 0)
 497		return NULL;
 498	return PyFloat_FromDouble(arg);
 499}
 500
 501static PyObject *
 502alc_setfloatmax(alcobject *self, PyObject *args)
 503{
 504	double arg;
 505
 506	if (!PyArg_ParseTuple(args, "d:SetFloatMax", &arg))
 507		return 0;
 508	if (ALsetfloatmax(self->config, arg) == -1)
 509		return NULL;
 510	Py_INCREF(Py_None);
 511	return Py_None;
 512}
 513#endif /* AL_405 */
 514	
 515static struct PyMethodDef alc_methods[] = {
 516#ifdef AL_NO_ELEM		/* IRIX 6 */
 517	{"SetWidth",	(PyCFunction)alc_SetWidth,	METH_VARARGS,	alc_SetWidth__doc__},
 518	{"GetWidth",	(PyCFunction)alc_GetWidth,	METH_VARARGS,	alc_GetWidth__doc__},
 519	{"SetSampFmt",	(PyCFunction)alc_SetSampFmt,	METH_VARARGS,	alc_SetSampFmt__doc__},
 520	{"GetSampFmt",	(PyCFunction)alc_GetSampFmt,	METH_VARARGS,	alc_GetSampFmt__doc__},
 521	{"SetChannels",	(PyCFunction)alc_SetChannels,	METH_VARARGS,	alc_SetChannels__doc__},
 522	{"GetChannels",	(PyCFunction)alc_GetChannels,	METH_VARARGS,	alc_GetChannels__doc__},
 523	{"SetFloatMax",	(PyCFunction)alc_SetFloatMax,	METH_VARARGS,	alc_SetFloatMax__doc__},
 524	{"GetFloatMax",	(PyCFunction)alc_GetFloatMax,	METH_VARARGS,	alc_GetFloatMax__doc__},
 525	{"SetDevice",	(PyCFunction)alc_SetDevice,	METH_VARARGS,	alc_SetDevice__doc__},
 526	{"GetDevice",	(PyCFunction)alc_GetDevice,	METH_VARARGS,	alc_GetDevice__doc__},
 527	{"SetQueueSize",	(PyCFunction)alc_SetQueueSize,	METH_VARARGS,	alc_SetQueueSize__doc__},
 528	{"GetQueueSize",	(PyCFunction)alc_GetQueueSize,	METH_VARARGS,	alc_GetQueueSize__doc__},
 529#endif /* AL_NO_ELEM */
 530	{"getqueuesize",	(PyCFunction)alc_getqueuesize,	METH_VARARGS},
 531	{"setqueuesize",	(PyCFunction)alc_setqueuesize,	METH_VARARGS},
 532	{"getwidth",		(PyCFunction)alc_getwidth,	METH_VARARGS},
 533	{"setwidth",		(PyCFunction)alc_setwidth,	METH_VARARGS},
 534	{"getchannels",		(PyCFunction)alc_getchannels,	METH_VARARGS},
 535	{"setchannels",		(PyCFunction)alc_setchannels,	METH_VARARGS},
 536#ifdef AL_405
 537	{"getsampfmt",		(PyCFunction)alc_getsampfmt,	METH_VARARGS},
 538	{"setsampfmt",		(PyCFunction)alc_setsampfmt,	METH_VARARGS},
 539	{"getfloatmax",		(PyCFunction)alc_getfloatmax,	METH_VARARGS},
 540	{"setfloatmax",		(PyCFunction)alc_setfloatmax,	METH_VARARGS},
 541#endif /* AL_405 */
 542
 543	{NULL,		NULL}		/* sentinel */
 544};
 545
 546/* ---------- */
 547
 548
 549static PyObject *
 550newalcobject(ALconfig config)
 551{
 552	alcobject *self;
 553	
 554	self = PyObject_New(alcobject, &Alctype);
 555	if (self == NULL)
 556		return NULL;
 557	/* XXXX Add your own initializers here */
 558	self->config = config;
 559	return (PyObject *) self;
 560}
 561
 562
 563static void
 564alc_dealloc(alcobject *self)
 565{
 566	/* XXXX Add your own cleanup code here */
 567#ifdef AL_NO_ELEM		/* IRIX 6 */
 568	(void) alFreeConfig(self->config);	/* ignore errors */
 569#else
 570	(void) ALfreeconfig(self->config);	/* ignore errors */
 571#endif
 572	PyObject_Del(self);
 573}
 574
 575static PyObject *
 576alc_getattr(alcobject *self, char *name)
 577{
 578	/* XXXX Add your own getattr code here */
 579	return Py_FindMethod(alc_methods, (PyObject *)self, name);
 580}
 581
 582PyDoc_STRVAR(Alctype__doc__, "");
 583
 584static PyTypeObject Alctype = {
 585	PyObject_HEAD_INIT(&PyType_Type)
 586	0,				/*ob_size*/
 587	"al.config",			/*tp_name*/
 588	sizeof(alcobject),		/*tp_basicsize*/
 589	0,				/*tp_itemsize*/
 590	/* methods */
 591	(destructor)alc_dealloc,	/*tp_dealloc*/
 592	(printfunc)0,		/*tp_print*/
 593	(getattrfunc)alc_getattr,	/*tp_getattr*/
 594	(setattrfunc)0,	/*tp_setattr*/
 595	(cmpfunc)0,		/*tp_compare*/
 596	(reprfunc)0,		/*tp_repr*/
 597	0,			/*tp_as_number*/
 598	0,		/*tp_as_sequence*/
 599	0,		/*tp_as_mapping*/
 600	(hashfunc)0,		/*tp_hash*/
 601	(ternaryfunc)0,		/*tp_call*/
 602	(reprfunc)0,		/*tp_str*/
 603
 604	/* Space for future expansion */
 605	0L,0L,0L,0L,
 606	Alctype__doc__ /* Documentation string */
 607};
 608
 609/* End of code for config objects */
 610/* ---------------------------------------------------------------- */
 611
 612#ifdef AL_NO_ELEM		/* IRIX 6 */
 613
 614PyDoc_STRVAR(alp_SetConfig__doc__,
 615"alSetConfig: set the ALconfig of an audio ALport.");
 616
 617static PyObject *
 618alp_SetConfig(alpobject *self, PyObject *args)
 619{
 620	alcobject *config;
 621	if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
 622		return NULL;
 623	if (alSetConfig(self->port, config->config) < 0)
 624		return NULL;
 625	Py_INCREF(Py_None);
 626	return Py_None;
 627}
 628
 629
 630PyDoc_STRVAR(alp_GetConfig__doc__,
 631"alGetConfig: get the ALconfig of an audio ALport.");
 632
 633static PyObject *
 634alp_GetConfig(alpobject *self, PyObject *args)
 635{
 636	ALconfig config;
 637	if (!PyArg_ParseTuple(args, ":GetConfig"))
 638		return NULL;
 639	if ((config = alGetConfig(self->port)) == NULL)
 640		return NULL;
 641	return newalcobject(config);
 642}
 643
 644
 645PyDoc_STRVAR(alp_GetResource__doc__,
 646"alGetResource: get the resource associated with an audio port.");
 647
 648static PyObject *
 649alp_GetResource(alpobject *self, PyObject *args)
 650{
 651	int resource;
 652
 653	if (!PyArg_ParseTuple(args, ":GetResource"))
 654		return NULL;
 655	if ((resource = alGetResource(self->port)) == 0)
 656		return NULL;
 657	return PyInt_FromLong((long) resource);
 658}
 659
 660
 661PyDoc_STRVAR(alp_GetFD__doc__,
 662"alGetFD: get the file descriptor for an audio port.");
 663
 664static PyObject *
 665alp_GetFD(alpobject *self, PyObject *args)
 666{
 667	int fd;
 668
 669	if (!PyArg_ParseTuple(args, ":GetFD"))
 670		return NULL;
 671
 672	if ((fd = alGetFD(self->port)) < 0)
 673		return NULL;
 674
 675	return PyInt_FromLong((long) fd);
 676}
 677
 678
 679PyDoc_STRVAR(alp_GetFilled__doc__,
 680"alGetFilled: return the number of filled sample frames in "
 681"an audio port.");
 682
 683static PyObject *
 684alp_GetFilled(alpobject *self, PyObject *args)
 685{
 686	int filled;
 687
 688	if (!PyArg_ParseTuple(args, ":GetFilled"))
 689		return NULL;
 690	if ((filled = alGetFilled(self->port)) < 0)
 691		return NULL;
 692	return PyInt_FromLong((long) filled);
 693}
 694
 695
 696PyDoc_STRVAR(alp_GetFillable__doc__,
 697"alGetFillable: report the number of unfilled sample frames "
 698"in an audio port.");
 699
 700static PyObject *
 701alp_GetFillable(alpobject *self, PyObject *args)
 702{
 703	int fillable;
 704
 705	if (!PyArg_ParseTuple(args, ":GetFillable"))
 706		return NULL;
 707	if ((fillable = alGetFillable(self->port)) < 0)
 708		return NULL;
 709	return PyInt_FromLong((long) fillable);
 710}
 711
 712
 713PyDoc_STRVAR(alp_ReadFrames__doc__,
 714"alReadFrames: read sample frames from an audio port.");
 715
 716static PyObject *
 717alp_ReadFrames(alpobject *self, PyObject *args)
 718{
 719	int framecount;
 720	PyObject *v;
 721	int size;
 722	int ch;
 723	ALconfig c;
 724
 725	if (!PyArg_ParseTuple(args, "i:ReadFrames", &framecount))
 726		return NULL;
 727	if (framecount < 0) {
 728		PyErr_SetString(ErrorObject, "negative framecount");
 729		return NULL;
 730	}
 731	c = alGetConfig(self->port);
 732	switch (alGetSampFmt(c)) {
 733	case AL_SAMPFMT_TWOSCOMP:
 734		switch (alGetWidth(c)) {
 735		case AL_SAMPLE_8:
 736			size = 1;
 737			break;
 738		case AL_SAMPLE_16:
 739			size = 2;
 740			break;
 741		case AL_SAMPLE_24:
 742			size = 4;
 743			break;
 744		default:
 745			PyErr_SetString(ErrorObject, "can't determine width");
 746			alFreeConfig(c);
 747			return NULL;
 748		}
 749		break;
 750	case AL_SAMPFMT_FLOAT:
 751		size = 4;
 752		break;
 753	case AL_SAMPFMT_DOUBLE:
 754		size = 8;
 755		break;
 756	default:
 757		PyErr_SetString(ErrorObject, "can't determine format");
 758		alFreeConfig(c);
 759		return NULL;
 760	}
 761	ch = alGetChannels(c);
 762	alFreeConfig(c);
 763	if (ch < 0) {
 764		PyErr_SetString(ErrorObject, "can't determine # of channels");
 765		return NULL;
 766	}
 767	size *= ch;
 768	v = PyString_FromStringAndSize((char *) NULL, size * framecount);
 769	if (v == NULL)
 770		return NULL;
 771
 772	Py_BEGIN_ALLOW_THREADS
 773	alReadFrames(self->port, (void *) PyString_AS_STRING(v), framecount);
 774	Py_END_ALLOW_THREADS
 775
 776	return v;
 777}
 778
 779
 780PyDoc_STRVAR(alp_DiscardFrames__doc__,
 781"alDiscardFrames: discard audio from an audio port.");
 782
 783static PyObject *
 784alp_DiscardFrames(alpobject *self, PyObject *args)
 785{
 786	int framecount;
 787
 788	if (!PyArg_ParseTuple(args, "i:DiscardFrames", &framecount))
 789		return NULL;
 790
 791	Py_BEGIN_ALLOW_THREADS
 792	framecount = alDiscardFrames(self->port, framecount);
 793	Py_END_ALLOW_THREADS
 794
 795	if (framecount < 0)
 796		return NULL;
 797
 798	return PyInt_FromLong((long) framecount);
 799}
 800
 801
 802PyDoc_STRVAR(alp_ZeroFrames__doc__,
 803"alZeroFrames: write zero-valued sample frames to an audio port.");
 804
 805static PyObject *
 806alp_ZeroFrames(alpobject *self, PyObject *args)
 807{
 808	int framecount;
 809
 810	if (!PyArg_ParseTuple(args, "i:ZeroFrames", &framecount))
 811		return NULL;
 812
 813	if (framecount < 0) {
 814		PyErr_SetString(ErrorObject, "negative framecount");
 815		return NULL;
 816	}
 817
 818	Py_BEGIN_ALLOW_THREADS
 819	alZeroFrames(self->port, framecount);
 820	Py_END_ALLOW_THREADS
 821
 822	Py_INCREF(Py_None);
 823	return Py_None;
 824}
 825
 826
 827PyDoc_STRVAR(alp_SetFillPoint__doc__,
 828"alSetFillPoint: set low- or high-water mark for an audio port.");
 829
 830static PyObject *
 831alp_SetFillPoint(alpobject *self, PyObject *args)
 832{
 833	int fillpoint;
 834
 835	if (!PyArg_ParseTuple(args, "i:SetFillPoint", &fillpoint))
 836		return NULL;
 837
 838	if (alSetFillPoint(self->port, fillpoint) < 0)
 839		return NULL;
 840
 841	Py_INCREF(Py_None);
 842	return Py_None;
 843}
 844
 845
 846PyDoc_STRVAR(alp_GetFillPoint__doc__,
 847"alGetFillPoint: get low- or high-water mark for an audio port.");
 848
 849static PyObject *
 850alp_GetFillPoint(alpobject *self, PyObject *args)
 851{
 852	int fillpoint;
 853
 854	if (!PyArg_ParseTuple(args, ":GetFillPoint"))
 855		return NULL;
 856
 857	if ((fillpoint = alGetFillPoint(self->port)) < 0)
 858		return NULL;
 859
 860	return PyInt_FromLong((long) fillpoint);
 861}
 862
 863
 864PyDoc_STRVAR(alp_GetFrameNumber__doc__,
 865"alGetFrameNumber: get the absolute sample frame number "
 866"associated with a port.");
 867
 868static PyObject *
 869alp_GetFrameNumber(alpobject *self, PyObject *args)
 870{
 871	stamp_t fnum;
 872
 873	if (!PyArg_ParseTuple(args, ":GetFrameNumber"))
 874		return NULL;
 875
 876	if (alGetFrameNumber(self->port, &fnum) < 0)
 877		return NULL;
 878
 879	return PyLong_FromLongLong((long long) fnum);
 880}
 881
 882
 883PyDoc_STRVAR(alp_GetFrameTime__doc__,
 884"alGetFrameTime: get the time at which a sample frame came "
 885"in or will go out.");
 886
 887static PyObject *
 888alp_GetFrameTime(alpobject *self, PyObject *args)
 889{
 890	stamp_t fnum, time;
 891	PyObject *ret, *v0, *v1;
 892
 893	if (!PyArg_ParseTuple(args, ":GetFrameTime"))
 894		return NULL;
 895	if (alGetFrameTime(self->port, &fnum, &time) < 0)
 896		return NULL;
 897	v0 = PyLong_FromLongLong((long long) fnum);
 898	v1 = PyLong_FromLongLong((long long) time);
 899	if (PyErr_Occurred()) {
 900		Py_XDECREF(v0);
 901		Py_XDECREF(v1);
 902		return NULL;
 903	}
 904	ret = PyTuple_Pack(2, v0, v1);
 905	Py_DECREF(v0);
 906	Py_DECREF(v1);
 907	return ret;
 908}
 909
 910
 911PyDoc_STRVAR(alp_WriteFrames__doc__,
 912"alWriteFrames: write sample frames to an audio port.");
 913
 914static PyObject *
 915alp_WriteFrames(alpobject *self, PyObject *args)
 916{
 917	char *samples;
 918	int length;
 919	int size, ch;
 920	ALconfig c;
 921
 922	if (!PyArg_ParseTuple(args, "s#:WriteFrames", &samples, &length))
 923		return NULL;
 924	c = alGetConfig(self->port);
 925	switch (alGetSampFmt(c)) {
 926	case AL_SAMPFMT_TWOSCOMP:
 927		switch (alGetWidth(c)) {
 928		case AL_SAMPLE_8:
 929			size = 1;
 930			break;
 931		case AL_SAMPLE_16:
 932			size = 2;
 933			break;
 934		case AL_SAMPLE_24:
 935			size = 4;
 936			break;
 937		default:
 938			PyErr_SetString(ErrorObject, "can't determine width");
 939			alFreeConfig(c);
 940			return NULL;
 941		}
 942		break;
 943	case AL_SAMPFMT_FLOAT:
 944		size = 4;
 945		break;
 946	case AL_SAMPFMT_DOUBLE:
 947		size = 8;
 948		break;
 949	default:
 950		PyErr_SetString(ErrorObject, "can't determine format");
 951		alFreeConfig(c);
 952		return NULL;
 953	}
 954	ch = alGetChannels(c);
 955	alFreeConfig(c);
 956	if (ch < 0) {
 957		PyErr_SetString(ErrorObject, "can't determine # of channels");
 958		return NULL;
 959	}
 960	size *= ch;
 961	if (length % size != 0) {
 962		PyErr_SetString(ErrorObject,
 963				"buffer length not whole number of frames");
 964		return NULL;
 965	}
 966
 967	Py_BEGIN_ALLOW_THREADS
 968	alWriteFrames(self->port, (void *) samples, length / size);
 969	Py_END_ALLOW_THREADS
 970
 971	Py_INCREF(Py_None);
 972	return Py_None;
 973}
 974
 975
 976PyDoc_STRVAR(alp_ClosePort__doc__, "alClosePort: close an audio port.");
 977
 978static PyObject *
 979alp_ClosePort(alpobject *self, PyObject *args)
 980{
 981	if (!PyArg_ParseTuple(args, ":ClosePort"))
 982		return NULL;
 983	if (alClosePort(self->port) < 0)
 984		return NULL;
 985	self->port = NULL;
 986	Py_INCREF(Py_None);
 987	return Py_None;
 988}
 989
 990#endif /* AL_NO_ELEM */
 991
 992#ifdef OLD_INTERFACE
 993static PyObject *
 994alp_closeport(alpobject *self, PyObject *args)
 995{
 996	if (!PyArg_ParseTuple(args, ":ClosePort"))
 997		return NULL;
 998	if (ALcloseport(self->port) < 0)
 999		return NULL;
1000	self->port = NULL;
1001	Py_INCREF(Py_None);
1002	return Py_None;
1003}
1004
1005static PyObject *
1006alp_getfd(alpobject *self, PyObject *args)
1007{
1008	int fd;
1009
1010	if (!PyArg_ParseTuple(args, ":GetFD"))
1011		return NULL;
1012	if ((fd = ALgetfd(self-> port)) == -1)
1013		return NULL;
1014	return PyInt_FromLong(fd);
1015}
1016
1017static PyObject *
1018alp_getfilled(alpobject *self, PyObject *args)
1019{
1020	long count;
1021
1022	if (!PyArg_ParseTuple(args, ":GetFilled"))
1023		return NULL;
1024	if ((count = ALgetfilled(self-> port)) == -1)
1025		return NULL;
1026	return PyInt_FromLong(count);
1027}
1028
1029static PyObject *
1030alp_getfillable(alpobject *self, PyObject *args)
1031{
1032	long count;
1033
1034	if (!PyArg_ParseTuple(args, ":GetFillable"))
1035		return NULL;
1036	if ((count = ALgetfillable(self-> port)) == -1)
1037		return NULL;
1038	return PyInt_FromLong (count);
1039}
1040
1041static PyObject *
1042alp_readsamps(alpobject *self, PyObject *args)
1043{
1044	long count;
1045	PyObject *v;
1046	ALconfig c;
1047	int width;
1048	int ret;
1049
1050	if (!PyArg_ParseTuple(args, "l:readsamps", &count))
1051		return NULL;
1052
1053	if (count <= 0) {
1054		PyErr_SetString(ErrorObject, "al.readsamps : arg <= 0");
1055		return NULL;
1056	}
1057
1058	c = ALgetconfig(self->port);
1059#ifdef AL_405
1060	width = ALgetsampfmt(c);
1061	if (width == AL_SAMPFMT_FLOAT)
1062		width = sizeof(float);
1063	else if (width == AL_SAMPFMT_DOUBLE)
1064		width = sizeof(double);
1065	else
1066		width = ALgetwidth(c);
1067#else
1068	width = ALgetwidth(c);
1069#endif /* AL_405 */
1070	ALfreeconfig(c);
1071	v = PyString_FromStringAndSize((char *)NULL, width * count);
1072	if (v == NULL)
1073		return NULL;
1074
1075	Py_BEGIN_ALLOW_THREADS
1076	ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
1077	Py_END_ALLOW_THREADS
1078	if (ret == -1) {
1079		Py_DECREF(v);
1080		return NULL;
1081	}
1082
1083	return (v);
1084}
1085
1086static PyObject *
1087alp_writesamps(alpobject *self, PyObject *args)
1088{
1089	char *buf;
1090	int size, width;
1091	ALconfig c;
1092	int ret;
1093
1094	if (!PyArg_ParseTuple(args, "s#:writesamps", &buf, &size))
1095		return NULL;
1096
1097	c = ALgetconfig(self->port);
1098#ifdef AL_405
1099	width = ALgetsampfmt(c);
1100	if (width == AL_SAMPFMT_FLOAT)
1101		width = sizeof(float);
1102	else if (width == AL_SAMPFMT_DOUBLE)
1103		width = sizeof(double);
1104	else
1105		width = ALgetwidth(c);
1106#else
1107	width = ALgetwidth(c);
1108#endif /* AL_405 */
1109	ALfreeconfig(c);
1110	Py_BEGIN_ALLOW_THREADS
1111	ret = ALwritesamps (self->port, (void *) buf, (long) size / width);
1112	Py_END_ALLOW_THREADS
1113	if (ret == -1)
1114		return NULL;
1115
1116	Py_INCREF(Py_None);
1117	return Py_None;
1118}
1119
1120static PyObject *
1121alp_getfillpoint(alpobject *self, PyObject *args)
1122{
1123	long count;
1124
1125	if (!PyArg_ParseTuple(args, ":GetFillPoint"))
1126		return NULL;
1127	if ((count = ALgetfillpoint(self->port)) == -1)
1128		return NULL;
1129	return PyInt_FromLong(count);
1130}
1131
1132static PyObject *
1133alp_setfillpoint(alpobject *self, PyObject *args)
1134{
1135	long count;
1136
1137	if (!PyArg_ParseTuple(args, "l:SetFillPoint", &count))
1138		return NULL;
1139	if (ALsetfillpoint(self->port, count) == -1)
1140		return NULL;
1141	Py_INCREF(Py_None);
1142	return Py_None;
1143}
1144
1145static PyObject *
1146alp_setconfig(alpobject *self, PyObject *args)
1147{
1148	alcobject *config;
1149
1150	if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
1151		return NULL;
1152	if (ALsetconfig(self->port, config->config) == -1)
1153		return NULL;
1154	Py_INCREF(Py_None);
1155	return Py_None;
1156}
1157
1158static PyObject *
1159alp_getconfig(alpobject *self, PyObject *args)
1160{
1161	ALconfig config;
1162
1163	if (!PyArg_ParseTuple(args, ":GetConfig"))
1164		return NULL;
1165	config = ALgetconfig(self->port);
1166	if (config == NULL)
1167		return NULL;
1168	return newalcobject(config);
1169}
1170
1171#ifdef AL_405
1172static PyObject *
1173alp_getstatus(alpobject *self, PyObject *args)
1174{
1175	PyObject *list, *v;
1176	long *PVbuffer;
1177	long length;
1178	int i;
1179	
1180	if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
1181		return NULL;
1182	length = PyList_Size(list);
1183	PVbuffer = PyMem_NEW(long, length);
1184	if (PVbuffer == NULL)
1185		return PyErr_NoMemory();
1186	for (i = 0; i < length; i++) {
1187		v = PyList_GetItem(list, i);
1188		if (!PyInt_Check(v)) {
1189			PyMem_DEL(PVbuffer);
1190			PyErr_BadArgument();
1191			return NULL;
1192		}
1193		PVbuffer[i] = PyInt_AsLong(v);
1194	}
1195
1196	if (ALgetstatus(self->port, PVbuffer, length) == -1)
1197		return NULL;
1198
1199	for (i = 0; i < length; i++)
1200		PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
1201
1202	PyMem_DEL(PVbuffer);
1203
1204	Py_INCREF(Py_None);
1205	return Py_None;
1206}
1207#endif /* AL_405 */
1208
1209#endif /* OLD_INTERFACE */
1210
1211static struct PyMethodDef alp_methods[] = {
1212#ifdef AL_NO_ELEM		/* IRIX 6 */
1213	{"SetConfig",	(PyCFunction)alp_SetConfig,	METH_VARARGS,	alp_SetConfig__doc__},
1214	{"GetConfig",	(PyCFunction)alp_GetConfig,	METH_VARARGS,	alp_GetConfig__doc__},
1215	{"GetResource",	(PyCFunction)alp_GetResource,	METH_VARARGS,	alp_GetResource__doc__},
1216	{"GetFD",	(PyCFunction)alp_GetFD,	METH_VARARGS,	alp_GetFD__doc__},
1217	{"GetFilled",	(PyCFunction)alp_GetFilled,	METH_VARARGS,	alp_GetFilled__doc__},
1218	{"GetFillable",	(PyCFunction)alp_GetFillable,	METH_VARARGS,	alp_GetFillable__doc__},
1219	{"ReadFrames",	(PyCFunction)alp_ReadFrames,	METH_VARARGS,	alp_ReadFrames__doc__},
1220	{"DiscardFrames",	(PyCFunction)alp_DiscardFrames,	METH_VARARGS,	alp_DiscardFrames__doc__},
1221	{"ZeroFrames",	(PyCFunction)alp_ZeroFrames,	METH_VARARGS,	alp_ZeroFrames__doc__},
1222	{"SetFillPoint",	(PyCFunction)alp_SetFillPoint,	METH_VARARGS,	alp_SetFillPoint__doc__},
1223	{"GetFillPoint",	(PyCFunction)alp_GetFillPoint,	METH_VARARGS,	alp_GetFillPoint__doc__},
1224	{"GetFrameNumber",	(PyCFunction)alp_GetFrameNumber,	METH_VARARGS,	alp_GetFrameNumber__doc__},
1225	{"GetFrameTime",	(PyCFunction)alp_GetFrameTime,	METH_VARARGS,	alp_GetFrameTime__doc__},
1226	{"WriteFrames",	(PyCFunction)alp_WriteFrames,	METH_VARARGS,	alp_WriteFrames__doc__},
1227	{"ClosePort",	(PyCFunction)alp_ClosePort,	METH_VARARGS,	alp_ClosePort__doc__},
1228#endif /* AL_NO_ELEM */
1229#ifdef OLD_INTERFACE
1230	{"closeport",		(PyCFunction)alp_closeport,	METH_VARARGS},
1231	{"getfd",		(PyCFunction)alp_getfd,	METH_VARARGS},
1232        {"fileno",		(PyCFunction)alp_getfd,	METH_VARARGS},
1233	{"getfilled",		(PyCFunction)alp_getfilled,	METH_VARARGS},
1234	{"getfillable",		(PyCFunction)alp_getfillable,	METH_VARARGS},
1235	{"readsamps",		(PyCFunction)alp_readsamps,	METH_VARARGS},
1236	{"writesamps",		(PyCFunction)alp_writesamps,	METH_VARARGS},
1237	{"setfillpoint",	(PyCFunction)alp_setfillpoint,	METH_VARARGS},
1238	{"getfillpoint",	(PyCFunction)alp_getfillpoint,	METH_VARARGS},
1239	{"setconfig",		(PyCFunction)alp_setconfig,	METH_VARARGS},
1240	{"getconfig",		(PyCFunction)alp_getconfig,	METH_VARARGS},
1241#ifdef AL_405
1242	{"getstatus",		(PyCFunction)alp_getstatus,	METH_VARARGS},
1243#endif /* AL_405 */	    
1244#endif /* OLD_INTERFACE */
1245 
1246	{NULL,		NULL}		/* sentinel */
1247};
1248
1249/* ---------- */
1250
1251
1252static PyObject *
1253newalpobject(ALport port)
1254{
1255	alpobject *self;
1256	
1257	self = PyObject_New(alpobject, &Alptype);
1258	if (self == NULL)
1259		return NULL;
1260	/* XXXX Add your own initializers here */
1261	self->port = port;
1262	return (PyObject *) self;
1263}
1264
1265
1266static void
1267alp_dealloc(alpobject *self)
1268{
1269	/* XXXX Add your own cleanup code here */
1270	if (self->port) {
1271#ifdef AL_NO_ELEM		/* IRIX 6 */
1272		alClosePort(self->port);
1273#else
1274		ALcloseport(self->port);
1275#endif
1276	}
1277	PyObject_Del(self);
1278}
1279
1280static PyObject *
1281alp_getattr(alpobject *self, char *name)
1282{
1283	/* XXXX Add your own getattr code here */
1284	if (self->port == NULL) {
1285		PyErr_SetString(ErrorObject, "port already closed");
1286		return NULL;
1287	}
1288	return Py_FindMethod(alp_methods, (PyObject *)self, name);
1289}
1290
1291PyDoc_STRVAR(Alptype__doc__, "");
1292
1293static PyTypeObject Alptype = {
1294	PyObject_HEAD_INIT(&PyType_Type)
1295	0,				/*ob_size*/
1296	"al.port",			/*tp_name*/
1297	sizeof(alpobject),		/*tp_basicsize*/
1298	0,				/*tp_itemsize*/
1299	/* methods */
1300	(destructor)alp_dealloc,	/*tp_dealloc*/
1301	(printfunc)0,		/*tp_print*/
1302	(getattrfunc)alp_getattr,	/*tp_getattr*/
1303	(setattrfunc)0,	/*tp_setattr*/
1304	(cmpfunc)0,		/*tp_compare*/
1305	(reprfunc)0,		/*tp_repr*/
1306	0,			/*tp_as_number*/
1307	0,		/*tp_as_sequence*/
1308	0,		/*tp_as_mapping*/
1309	(hashfunc)0,		/*tp_hash*/
1310	(ternaryfunc)0,		/*tp_call*/
1311	(reprfunc)0,		/*tp_str*/
1312
1313	/* Space for future expansion */
1314	0L,0L,0L,0L,
1315	Alptype__doc__ /* Documentation string */
1316};
1317
1318/* End of code for port objects */
1319/* -------------------------------------------------------- */
1320
1321
1322#ifdef AL_NO_ELEM		/* IRIX 6 */
1323
1324PyDoc_STRVAR(al_NewConfig__doc__,
1325"alNewConfig: create and initialize an audio ALconfig structure.");
1326
1327static PyObject *
1328al_NewConfig(PyObject *self, PyObject *args)
1329{
1330	ALconfig config;
1331
1332	if (!PyArg_ParseTuple(args, ":NewConfig"))
1333		return NULL;
1334	if ((config = alNewConfig()) == NULL)
1335		return NULL;
1336	return newalcobject(config);
1337}
1338
1339PyDoc_STRVAR(al_OpenPort__doc__,
1340"alOpenPort: open an audio port.");
1341
1342static PyObject *
1343al_OpenPort(PyObject *self, PyObject *args)
1344{
1345	ALport port;
1346	char *name, *dir;
1347	alcobject *config = NULL;
1348
1349	if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
1350		return NULL;
1351	if ((port = alOpenPort(name, dir, config ? config->config : NULL)) == NULL)
1352		return NULL;
1353	return newalpobject(port);
1354}
1355
1356PyDoc_STRVAR(al_Connect__doc__,
1357"alConnect: connect two audio I/O resources.");
1358
1359static PyObject *
1360al_Connect(PyObject *self, PyObject *args)
1361{
1362	int source, dest, nprops = 0, id, i;
1363	ALpv *props = NULL;
1364	ALparamInfo *propinfo = NULL;
1365	PyObject *propobj = NULL;
1366
1367	if (!PyArg_ParseTuple(args, "ii|O!:Connect", &source, &dest, &PyList_Type, &propobj))
1368		return NULL;
1369	if (propobj != NULL) {
1370		nprops = python2params(source, dest, propobj, &props, &propinfo);
1371		if (nprops < 0)
1372			return NULL;
1373	}
1374
1375	id = alConnect(source, dest, props, nprops);
1376
1377	if (props) {
1378		for (i = 0; i < nprops; i++) {
1379			switch (propinfo[i].valueType) {
1380			case AL_SET_VAL:
1381			case AL_VECTOR_VAL:
1382				PyMem_DEL(props[i].value.ptr);
1383				break;
1384			}
1385		}
1386		PyMem_DEL(props);
1387		PyMem_DEL(propinfo);
1388	}
1389
1390	if (id < 0)
1391		return NULL;
1392	return PyInt_FromLong((long) id);
1393}
1394
1395PyDoc_STRVAR(al_Disconnect__doc__,
1396"alDisconnect: delete a connection between two audio I/O resources.");
1397
1398static PyObject *
1399al_Disconnect(PyObject *self, PyObject *args)
1400{
1401	int res;
1402
1403	if (!PyArg_ParseTuple(args, "i:Disconnect", &res))
1404		return NULL;
1405	if (alDisconnect(res) < 0)
1406		return NULL;
1407	Py_INCREF(Py_None);
1408	return Py_None;
1409}
1410
1411PyDoc_STRVAR(al_GetParams__doc__,
1412"alGetParams: get the values of audio resource parameters.");
1413
1414static PyObject *
1415al_GetParams(PyObject *self, PyObject *args)
1416{
1417	int resource;
1418	PyObject *pvslist, *item = NULL, *v = NULL;
1419	ALpv *pvs;
1420	int i, j, npvs;
1421	ALparamInfo *pinfo;
1422
1423	if (!PyArg_ParseTuple(args, "iO!:GetParams", &resource, &PyList_Type, &pvslist))
1424		return NULL;
1425	npvs = PyList_Size(pvslist);
1426	pvs = PyMem_NEW(ALpv, npvs);
1427	pinfo = PyMem_NEW(ALparamInfo, npvs);
1428	for (i = 0; i < npvs; i++) {
1429		item = PyList_GetItem(pvslist, i);
1430		if (!PyInt_Check(item)) {
1431			item = NULL;
1432			PyErr_SetString(ErrorObject, "list of integers expected");
1433			goto error;
1434		}
1435		pvs[i].param = (int) PyInt_AsLong(item);
1436		item = NULL;	/* not needed anymore */
1437		if (alGetParamInfo(resource, pvs[i].param, &pinfo[i]) < 0)
1438			goto error;
1439		switch (pinfo[i].valueType) {
1440		case AL_NO_VAL:
1441			break;
1442		case AL_MATRIX_VAL:
1443			pinfo[i].maxElems *= pinfo[i].maxElems2;
1444			/* fall through */
1445		case AL_STRING_VAL:
1446		case AL_SET_VAL:
1447		case AL_VECTOR_VAL:
1448			switch (pinfo[i].elementType) {
1449			case AL_INT32_ELEM:
1450			case AL_RESOURCE_ELEM:
1451			case AL_ENUM_ELEM:
1452				pvs[i].value.ptr = PyMem_NEW(int, pinfo[i].maxElems);
1453				pvs[i].sizeIn = pinfo[i].maxElems;
1454				break;
1455			case AL_INT64_ELEM:
1456			case AL_FIXED_ELEM:
1457				pvs[i].value.ptr = PyMem_NEW(long long, pinfo[i].maxElems);
1458				pvs[i].sizeIn = pinfo[i].maxElems;
1459				break;
1460			case AL_CHAR_ELEM:
1461				pvs[i].value.ptr = PyMem_NEW(char, 32);
1462				pvs[i].sizeIn = 32;
1463				break;
1464			case AL_NO_ELEM:
1465			case AL_PTR_ELEM:
1466			default:
1467				PyErr_SetString(ErrorObject, "internal error");
1468				goto error;
1469			}
1470			break;
1471		case AL_SCALAR_VAL:
1472			break;
1473		default:
1474			PyErr_SetString(ErrorObject, "internal error");
1475			goto error;
1476		}
1477		if (pinfo[i].valueType == AL_MATRIX_VAL) {
1478			pinfo[i].maxElems /= pinfo[i].maxElems2;
1479			pvs[i].sizeIn /= pinfo[i].maxElems2;
1480			pvs[i].size2In = pinfo[i].maxElems2;
1481		}
1482	}
1483	if (alGetParams(resource, pvs, npvs) < 0)
1484		goto error;
1485	if (!(v = PyList_New(npvs)))
1486		goto error;
1487	for (i = 0; i < npvs; i++) {
1488		if (pvs[i].sizeOut < 0) {
1489			char buf[32];
1490			PyOS_snprintf(buf, sizeof(buf),
1491				      "problem with param %d", i);
1492			PyErr_SetString(ErrorObject, buf);
1493			goto error;
1494		}
1495		switch (pinfo[i].valueType) {
1496		case AL_NO_VAL:
1497			item = Py_None;
1498			Py_INCREF(item);
1499			break;
1500		case AL_STRING_VAL:
1501			item = PyString_FromString(pvs[i].value.ptr);
1502			PyMem_DEL(pvs[i].value.ptr);
1503			break;
1504		case AL_MATRIX_VAL:
1505			/* XXXX this is not right */
1506			pvs[i].sizeOut *= pvs[i].size2Out;
1507			/* fall through */
1508		case AL_SET_VAL:
1509		case AL_VECTOR_VAL:
1510			item = PyList_New(pvs[i].sizeOut);
1511			for (j = 0; j < pvs[i].sizeOut; j++) {
1512				switch (pinfo[i].elementType) {
1513				case AL_INT32_ELEM:
1514				case AL_RESOURCE_ELEM:
1515				case AL_ENUM_ELEM:
1516					PyList_SetItem(item, j, PyInt_FromLong((long) ((int *) pvs[i].value.ptr)[j]));
1517					break;
1518				case AL_INT64_ELEM:
1519					PyList_SetItem(item, j, PyLong_FromLongLong(((long long *) pvs[i].value.ptr)[j]));
1520					break;
1521				case AL_FIXED_ELEM:
1522					PyList_SetItem(item, j, PyFloat_FromDouble(alFixedToDouble(((long long *) pvs[i].value.ptr)[j])));
1523					break;
1524				default:
1525					PyErr_SetString(ErrorObject, "internal error");
1526					goto error;
1527				}
1528			}
1529			PyMem_DEL(pvs[i].value.ptr);
1530			break;
1531		case AL_SCALAR_VAL:
1532			item = param2python(resource, pvs[i].param, pvs[i].value, &pinfo[i]);
1533			break;
1534		}
1535		if (PyErr_Occurred() ||
1536		    PyList_SetItem(v, i, Py_BuildValue("(iO)", pvs[i].param,
1537						       item)) < 0 ||
1538		    PyErr_Occurred())
1539			goto error;
1540		Py_DECREF(item);
1541	}
1542	PyMem_DEL(pvs);
1543	PyMem_DEL(pinfo);
1544	return v;
1545
1546  error:
1547	Py_XDECREF(v);
1548	Py_XDECREF(item);
1549	if (pvs)
1550		PyMem_DEL(pvs);
1551	if (pinfo)
1552		PyMem_DEL(pinfo);
1553	return NULL;
1554}
1555
1556PyDoc_STRVAR(al_SetParams__doc__,
1557"alSetParams: set the values of audio resource parameters.");
1558
1559static PyObject *
1560al_SetParams(PyObject *self, PyObject *args)
1561{
1562	int resource;
1563	PyObject *pvslist;
1564	ALpv *pvs;
1565	ALparamInfo *pinfo;
1566	int npvs, i;
1567
1568	if (!PyArg_ParseTuple(args, "iO!:SetParams", &resource, &PyList_Type, &pvslist))
1569		return NULL;
1570	npvs = python2params(resource, -1, pvslist, &pvs, &pinfo);
1571	if (npvs < 0)
1572		return NULL;
1573
1574	if (alSetParams(resource, pvs, npvs) < 0)
1575		goto error;
1576
1577	/* cleanup */
1578	for (i = 0; i < npvs; i++) {
1579		switch (pinfo[i].valueType) {
1580		case AL_SET_VAL:
1581		case AL_VECTOR_VAL:
1582			PyMem_DEL(pvs[i].value.ptr);
1583			break;
1584		}
1585	}
1586	PyMem_DEL(pvs);
1587	PyMem_DEL(pinfo);
1588
1589	Py_INCREF(Py_None);
1590	return Py_None;
1591
1592  error:
1593	/* XXXX we should clean up everything */
1594	if (pvs)
1595		PyMem_DEL(pvs);
1596	if (pinfo)
1597		PyMem_DEL(pinfo);
1598	return NULL;
1599}
1600
1601PyDoc_STRVAR(al_QueryValues__doc__,
1602"alQueryValues: get the set of possible values for a parameter.");
1603
1604static PyObject *
1605al_QueryValues(PyObject *self, PyObject *args)
1606{
1607	int resource, param;
1608	ALvalue *return_set = NULL;
1609	int setsize = 32, qualsize = 0, nvals, i;
1610	ALpv *quals = NULL;
1611	ALparamInfo pinfo;
1612	ALparamInfo *qualinfo = NULL;
1613	PyObject *qualobj = NULL;
1614	PyObject *res = NULL, *item;
1615
1616	if (!PyArg_ParseTuple(args, "ii|O!:QueryValues", &resource, &param,
1617			      &PyList_Type, &qualobj))
1618		return NULL;
1619	if (qualobj != NULL) {
1620		qualsize = python2params(resource, param, qualobj, &quals, &qualinfo);
1621		if (qualsize < 0)
1622			return NULL;
1623	}
1624	setsize = 32;
1625	return_set = PyMem_NEW(ALvalue, setsize);
1626	if (return_set == NULL) {
1627		PyErr_NoMemory();
1628		goto cleanup;
1629	}
1630
1631  retry:
1632	nvals = alQueryValues(resource, param, return_set, setsize, quals, qualsize);
1633	if (nvals < 0)
1634		goto cleanup;
1635	if (nvals > setsize) {
1636		ALvalue *old_return_set = return_set;
1637		setsize = nvals;
1638		PyMem_RESIZE(return_set, ALvalue, setsize);
1639		if (return_set == NULL) {
1640			return_set = old_return_set;
1641			PyErr_NoMemory();
1642			goto cleanup;
1643		}
1644		goto retry;
1645	}
1646
1647	if (alGetParamInfo(resource, param, &pinfo) < 0)
1648		goto cleanup;
1649
1650	res = PyList_New(nvals);
1651	if (res == NULL)
1652		goto cleanup;
1653	for (i = 0; i < nvals; i++) {
1654		item = param2python(resource, param, return_set[i], &pinfo);
1655		if (item == NULL ||
1656		    PyList_SetItem(res, i, item) < 0) {
1657			Py_DECREF(res);
1658			res = NULL;
1659			goto cleanup;
1660		}
1661	}
1662
1663  cleanup:
1664	if (return_set)
1665		PyMem_DEL(return_set);
1666	if (quals) {
1667		for (i = 0; i < qualsize; i++) {
1668			switch (qualinfo[i].valueType) {
1669			case AL_SET_VAL:
1670			case AL_VECTOR_VAL:
1671				PyMem_DEL(quals[i].value.ptr);
1672				break;
1673			}
1674		}
1675		PyMem_DEL(quals);
1676		PyMem_DEL(qualinfo);
1677	}
1678
1679	return res;
1680}
1681
1682PyDoc_STRVAR(al_GetParamInfo__doc__,
1683"alGetParamInfo: get information about a parameter on "
1684"a particular audio resource.");
1685
1686static PyObject *
1687al_GetParamInfo(PyObject *self, PyObject *args)
1688{
1689	int res, param;
1690	ALparamInfo pinfo;
1691	PyObject *v, *item;
1692
1693	if (!PyArg_ParseTuple(args, "ii:GetParamInfo", &res, &param))
1694		return NULL;
1695	if (alGetParamInfo(res, param, &pinfo) < 0)
1696		return NULL;
1697	v = PyDict_New();
1698	if (!v) return NULL;
1699
1700	item = PyInt_FromLong((long) pinfo.resource);
1701	PyDict_SetItemString(v, "resource", item);
1702	Py_DECREF(item);
1703
1704	item = PyInt_FromLong((long) pinfo.param);
1705	PyDict_SetItemString(v, "param", item);
1706	Py_DECREF(item);
1707
1708	item = PyInt_FromLong((long) pinfo.valueType);
1709	PyDict_SetItemString(v, "valueType", item);
1710	Py_DECREF(item);
1711
1712	if (pinfo.valueType != AL_NO_VAL && pinfo.valueType != AL_SCALAR_VAL) {
1713		/* multiple values */
1714		item = PyInt_FromLong((long) pinfo.maxElems);
1715		PyDict_SetItemString(v, "maxElems", item);
1716		Py_DECREF(item);
1717
1718		if (pinfo.valueType == AL_MATRIX_VAL) {
1719			/* 2 dimensional */
1720			item = PyInt_FromLong((long) pinfo.maxElems2);
1721			PyDict_SetItemString(v, "maxElems2", item);
1722			Py_DECREF(item);
1723		}
1724	}
1725
1726	item = PyInt_FromLong((long) pinfo.elementType);
1727	PyDict_SetItemString(v, "elementType", item);
1728	Py_DECREF(item);
1729
1730	item = PyString_FromString(pinfo.name);
1731	PyDict_SetItemString(v, "name", item);
1732	Py_DECREF(item);
1733
1734	item = param2python(res, param, pinfo.initial, &pinfo);
1735	PyDict_SetItemString(v, "initial", item);
1736	Py_DECREF(item);
1737
1738	if (pinfo.elementType != AL_ENUM_ELEM &&
1739	    pinfo.elementType != AL_RESOURCE_ELEM &&
1740	    pinfo.elementType != AL_CHAR_ELEM) {
1741		/* range param */
1742		item = param2python(res, param, pinfo.min, &pinfo);
1743		PyDict_SetItemString(v, "min", item);
1744		Py_DECREF(item);
1745
1746		item = param2python(res, param, pinfo.max, &pinfo);
1747		PyDict_SetItemString(v, "max", item);
1748		Py_DECREF(item);
1749
1750		item = param2python(res, param, pinfo.minDelta, &pinfo);
1751		PyDict_SetItemString(v, "minDelta", item);
1752		Py_DECREF(item);
1753
1754		item = param2python(res, param, pinfo.maxDelta, &pinfo);
1755		PyDict_SetItemString(v, "maxDelta", item);
1756		Py_DECREF(item);
1757
1758		item = PyInt_FromLong((long) pinfo.specialVals);
1759		PyDict_SetItemString(v, "specialVals", item);
1760		Py_DECREF(item);
1761	}
1762
1763	return v;
1764}
1765
1766PyDoc_STRVAR(al_GetResourceByName__doc__,
1767"alGetResourceByName: find an audio resource by name.");
1768
1769static PyObject *
1770al_GetResourceByName(PyObject *self, PyObject *args)
1771{
1772	int res, start_res, type;
1773	char *name;
1774
1775	if (!PyArg_ParseTuple(args, "isi:GetResourceByName", &start_res, &name, &type))
1776		return NULL;
1777	if ((res = alGetResourceByName(start_res, name, type)) == 0)
1778		return NULL;
1779	return PyInt_FromLong((long) res);
1780}
1781
1782PyDoc_STRVAR(al_IsSubtype__doc__,
1783"alIsSubtype: indicate if one resource type is a subtype of another.");
1784
1785static PyObject *
1786al_IsSubtype(PyObject *self, PyObject *args)
1787{
1788	int type, subtype;
1789
1790	if (!PyArg_ParseTuple(args, "ii:IsSubtype", &type, &subtype))
1791		return NULL;
1792	return PyInt_FromLong((long) alIsSubtype(type, subtype));
1793}
1794
1795PyDoc_STRVAR(al_SetErrorHandler__doc__, "");
1796
1797static PyObject *
1798al_SetErrorHandler(PyObject *self, PyObject *args)
1799{
1800
1801	if (!PyArg_ParseTuple(args, ":SetErrorHandler"))
1802		return NULL;
1803	Py_INCREF(Py_None);
1804	return Py_None;
1805}
1806
1807#endif /* AL_NO_ELEM */
1808
1809#ifdef OLD_INTERFACE
1810
1811static PyObject *
1812al_openport(PyObject *self, PyObject *args)
1813{
1814	char *name, *dir;
1815	ALport port;
1816	alcobject *config = NULL;
1817
1818	if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
1819		return NULL;
1820	if ((port = ALopenport(name, dir, config ? config->config : NULL)) == NULL)
1821		return NULL;
1822	return newalpobject(port);
1823}
1824
1825static PyObject *
1826al_newconfig(PyObject *self, PyObject *args)
1827{
1828	ALconfig config;
1829
1830	if (!PyArg_ParseTuple(args, ":NewConfig"))
1831		return NULL;
1832	if ((config = ALnewconfig ()) == NULL)
1833		return NULL;
1834	return newalcobject(config);
1835}
1836
1837static PyObject *
1838al_queryparams(PyObject *self, PyObject *args)
1839{
1840	long device;
1841	long length;
1842	long *PVbuffer;
1843	long PVdummy[2];
1844	PyObject *v = NULL;
1845	int i;
1846
1847	if (!PyArg_ParseTuple(args, "l:queryparams", &device))
1848		return NULL;
1849	if ((length = ALqueryparams(device, PVdummy, 2L)) == -1)
1850		return NULL;
1851	if ((PVbuffer = PyMem_NEW(long, length)) == NULL)
1852		return PyErr_NoMemory();
1853	if (ALqueryparams(device, PVbuffer, length) >= 0 &&
1854	    (v = PyList_New((int)length)) != NULL) {
1855		for (i = 0; i < length; i++)
1856			PyList_SetItem(v, i, PyInt_FromLong(PVbuffer[i]));
1857	}
1858	PyMem_DEL(PVbuffer);
1859	return v;
1860}
1861
1862static PyObject *
1863doParams(PyObject *args, int (*func)(long, long *, long), int modified)
1864{
1865	long device;
1866	PyObject *list, *v;
1867	long *PVbuffer;
1868	long length;
1869	int i;
1870	
1871	if (!PyArg_ParseTuple(args, "lO!", &device, &PyList_Type, &list))
1872		return NULL;
1873	length = PyList_Size(list);
1874	PVbuffer = PyMem_NEW(long, length);
1875	if (PVbuffer == NULL)
1876		return PyErr_NoMemory();
1877	for (i = 0; i < length; i++) {
1878		v = PyList_GetItem(list, i);
1879		if (!PyInt_Check(v)) {
1880			PyMem_DEL(PVbuffer);
1881			PyErr_BadArgument();
1882			return NULL;
1883		}
1884		PVbuffer[i] = PyInt_AsLong(v);
1885	}
1886
1887	if ((*func)(device, PVbuffer, length) == -1) {
1888		PyMem_DEL(PVbuffer);
1889		return NULL;
1890	}
1891
1892	if (modified) {
1893		for (i = 0; i < length; i++)
1894			PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
1895	}
1896
1897	PyMem_DEL(PVbuffer);
1898
1899	Py_INCREF(Py_None);
1900	return Py_None;
1901}
1902
1903static PyObject *
1904al_getparams(PyObject *self, PyObject *args)
1905{
1906	return doParams(args, ALgetparams, 1);
1907}
1908
1909static PyObject *
1910al_setparams(PyObject *self, PyObject *args)
1911{
1912	return doParams(args, ALsetparams, 0);
1913}
1914
1915static PyObject *
1916al_getname(PyObject *self, PyObject *args)
1917{
1918	long device, descriptor;
1919	char *name;
1920
1921	if (!PyArg_ParseTuple(args, "ll:getname", &device, &descriptor))
1922		return NULL;
1923	if ((name = ALgetname(device, descriptor)) == NULL)
1924		return NULL;
1925	return PyString_FromString(name);
1926}
1927
1928static PyObject *
1929al_getdefault(PyObject *self, PyObject *args)
1930{
1931	long device, descriptor, value;
1932
1933	if (!PyArg_ParseTuple(args, "ll:getdefault", &device, &descriptor))
1934		return NULL;
1935	if ((value = ALgetdefault(device, descriptor)) == -1)
1936		return NULL;
1937	return PyLong_FromLong(value);
1938}
1939
1940static PyObject *
1941al_getminmax(PyObject *self, PyObject *args)
1942{
1943	long device, descriptor, min, max;
1944
1945	if (!PyArg_ParseTuple(args, "ll:getminmax", &device, &descriptor))
1946		return NULL;
1947	min = -1;
1948	max = -1;
1949	if (ALgetminmax(device, descriptor, &min, &max) == -1)
1950		return NULL;
1951	return Py_BuildValue("ll", min, max);
1952}
1953
1954#endif /* OLD_INTERFACE */
1955
1956/* List of methods defined in the module */
1957
1958static struct PyMethodDef al_methods[] = {
1959#ifdef AL_NO_ELEM		/* IRIX 6 */
1960	{"NewConfig",	(PyCFunction)al_NewConfig,	METH_VARARGS,	al_NewConfig__doc__},
1961	{"OpenPort",	(PyCFunction)al_OpenPort,	METH_VARARGS,	al_OpenPort__doc__},
1962	{"Connect",	(PyCFunction)al_Connect,	METH_VARARGS,	al_Connect__doc__},
1963	{"Disconnect",	(PyCFunction)al_Disconnect,	METH_VARARGS,	al_Disconnect__doc__},
1964	{"GetParams",	(PyCFunction)al_GetParams,	METH_VARARGS,	al_GetParams__doc__},
1965	{"SetParams",	(PyCFunction)al_SetParams,	METH_VARARGS,	al_SetParams__doc__},
1966	{"QueryValues",	(PyCFunction)al_QueryValues,	METH_VARARGS,	al_QueryValues__doc__},
1967	{"GetParamInfo",	(PyCFunction)al_GetParamInfo,	METH_VARARGS,	al_GetParamInfo__doc__},
1968	{"GetResourceByName",	(PyCFunction)al_GetResourceByName,	METH_VARARGS,	al_GetResourceByName__doc__},
1969	{"IsSubtype",	(PyCFunction)al_IsSubtype,	METH_VARARGS,	al_IsSubtype__doc__},
1970#if 0
1971	/* this one not supported */
1972	{"SetErrorHandler",	(PyCFunction)al_SetErrorHandler,	METH_VARARGS,	al_SetErrorHandler__doc__},
1973#endif
1974#endif /* AL_NO_ELEM */
1975#ifdef OLD_INTERFACE
1976	{"openport",		(PyCFunction)al_openport,	METH_VARARGS},
1977	{"newconfig",		(PyCFunction)al_newconfig,	METH_VARARGS},
1978	{"queryparams",		(PyCFunction)al_queryparams,	METH_VARARGS},
1979	{"getparams",		(PyCFunction)al_getparams,	METH_VARARGS},
1980	{"setparams",		(PyCFunction)al_setparams,	METH_VARARGS},
1981	{"getname",		(PyCFunction)al_getname,	METH_VARARGS},
1982	{"getdefault",		(PyCFunction)al_getdefault,	METH_VARARGS},
1983	{"getminmax",		(PyCFunction)al_getminmax,	METH_VARARGS},
1984#endif /* OLD_INTERFACE */
1985
1986	{NULL,	 (PyCFunction)NULL, 0, NULL}		/* sentinel */
1987};
1988
1989
1990/* Initialization function for the module (*must* be called inital) */
1991
1992PyDoc_STRVAR(al_module_documentation, "");
1993
1994void
1995inital(void)
1996{
1997	PyObject *m, *d, *x;
1998
1999	if (PyErr_WarnPy3k("the al module has been removed in "
2000	                   "Python 3.0", 2) < 0)
2001	    return;	
2002
2003	/* Create the module and add the functions */
2004	m = Py_InitModule4("al", al_methods,
2005		al_module_documentation,
2006		(PyObject*)NULL,PYTHON_API_VERSION);
2007	if (m == NULL)
2008		return;
2009
2010	/* Add some symbolic constants to the module */
2011	d = PyModule_GetDict(m);
2012	ErrorObject = PyErr_NewException("al.error", NULL, NULL);
2013	PyDict_SetItemString(d, "error", ErrorObject);
2014
2015	/* XXXX Add constants here */
2016#ifdef AL_4CHANNEL
2017	x =  PyInt_FromLong((long) AL_4CHANNEL);
2018	if (x == NULL || PyDict_SetItemString(d, "FOURCHANNEL", x) < 0)
2019		goto error;
2020	Py_DECREF(x);
2021#endif
2022#ifdef AL_ADAT_IF_TYPE
2023	x =  PyInt_FromLong((long) AL_ADAT_IF_TYPE);
2024	if (x == NULL || PyDict_SetItemString(d, "ADAT_IF_TYPE", x) < 0)
2025		goto error;
2026	Py_DECREF(x);
2027#endif
2028#ifdef AL_ADAT_MCLK_TYPE
2029	x =  PyInt_FromLong((long) AL_ADAT_MCLK_TYPE);
2030	if (x == NULL || PyDict_SetItemString(d, "ADAT_MCLK_TYPE", x) < 0)
2031		goto error;
2032	Py_DECREF(x);
2033#endif
2034#ifdef AL_AES_IF_TYPE
2035	x =  PyInt_FromLong((long) AL_AES_IF_TYPE);
2036	if (x == NULL || PyDict_SetItemString(d, "AES_IF_TYPE", x) < 0)
2037		goto error;
2038	Py_DECREF(x);
2039#endif
2040#ifdef AL_AES_MCLK_TYPE
2041	x =  PyInt_FromLong((long) AL_AES_MCLK_TYPE);
2042	if (x == NULL || PyDict_SetItemString(d, "AES_MCLK_TYPE", x) < 0)
2043		goto error;
2044	Py_DECREF(x);
2045#endif
2046#ifdef AL_ANALOG_IF_TYPE
2047	x =  PyInt_FromLong((long) AL_ANALOG_IF_TYPE);
2048	if (x == NULL || PyDict_SetItemString(d, "ANALOG_IF_TYPE", x) < 0)
2049		goto error;
2050	Py_DECREF(x);
2051#endif
2052#ifdef AL_ASSOCIATE
2053	x =  PyInt_FromLong((long) AL_ASSOCIATE);
2054	if (x == NULL || PyDict_SetItemString(d, "ASSOCIATE", x) < 0)
2055		goto error;
2056	Py_DECREF(x);
2057#endif
2058#ifdef AL_BAD_BUFFER_NULL
2059	x =  PyInt_FromLong((long) AL_BAD_BUFFER_NULL);
2060	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFER_NULL", x) < 0)
2061		goto error;
2062	Py_DECREF(x);
2063#endif
2064#ifdef AL_BAD_BUFFERLENGTH
2065	x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH);
2066	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH", x) < 0)
2067		goto error;
2068	Py_DECREF(x);
2069#endif
2070#ifdef AL_BAD_BUFFERLENGTH_NEG
2071	x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_NEG);
2072	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_NEG", x) < 0)
2073		goto error;
2074	Py_DECREF(x);
2075#endif
2076#ifdef AL_BAD_BUFFERLENGTH_ODD
2077	x =  PyInt_FromLong((long) AL_BAD_BUFFERLENGTH_ODD);
2078	if (x == NULL || PyDict_SetItemString(d, "BAD_BUFFERLENGTH_ODD", x) < 0)
2079		goto error;
2080	Py_DECREF(x);
2081#endif
2082#ifdef AL_BAD_CHANNELS
2083	x =  PyInt_FromLong((long) AL_BAD_CHANNELS);
2084	if (x == NULL || PyDict_SetItemString(d, "BAD_CHANNELS", x) < 0)
2085		goto error;
2086	Py_DECREF(x);
2087#endif
2088#ifdef AL_BAD_CONFIG
2089	x =  PyInt_FromLong((long) AL_BAD_CONFIG);
2090	if (x == NULL || PyDict_SetItemString(d, "BAD_CONFIG", x) < 0)
2091		goto error;
2092	Py_DECREF(x);
2093#endif
2094#ifdef AL_BAD_COUNT_NEG
2095	x =  PyInt_FromLong((long) AL_BAD_COUNT_NEG);
2096	if (x == NULL || PyDict_SetItemString(d, "BAD_COUNT_NEG", x) < 0)
2097		goto error;
2098	Py_DECREF(x);
2099#endif
2100#ifdef AL_BAD_DEVICE
2101	x =  PyInt_FromLong((long) AL_BAD_DEVICE);
2102	if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE", x) < 0)
2103		goto error;
2104	Py_DECREF(x);
2105#endif
2106#ifdef AL_BAD_DEVICE_ACCESS
2107	x =  PyInt_FromLong((long) AL_BAD_DEVICE_ACCESS);
2108	if (x == NULL || PyDict_SetItemString(d, "BAD_DEVICE_ACCESS", x) < 0)
2109		goto error;
2110	Py_DECREF(x);
2111#endif
2112#ifdef AL…

Large files files are truncated, but you can click here to view the full file