/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 are truncated click here to view the full file

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