#define OLD_INTERFACE /* define for pre-Irix 6 interface */ #include "Python.h"#include "stringobject.h"#include <audio.h>#include <stdarg.h> #ifndef AL_NO_ELEM#ifndef OLD_INTERFACE#define OLD_INTERFACE#endif /* OLD_INTERFACE */#endif /* AL_NO_ELEM */ static PyObject *ErrorObject; /* ----------------------------------------------------- */ /* Declarations for objects of type port */ typedef struct { PyObject_HEAD /* XXXX Add your own stuff here */ ALport port;} alpobject; static PyTypeObject Alptype; /* ---------------------------------------------------------------- */ /* Declarations for objects of type config */ typedef struct { PyObject_HEAD /* XXXX Add your own stuff here */ ALconfig config;} alcobject; static PyTypeObject Alctype; static voidErrorHandler(long code, const char *fmt, ...){ va_list args; char buf[128]; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); PyErr_SetString(ErrorObject, buf);} #ifdef AL_NO_ELEM /* IRIX 6 */ static PyObject *param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo){ ALparamInfo info; if (pinfo == NULL) { pinfo = &info; if (alGetParamInfo(resource, param, &info) < 0) return NULL; } switch (pinfo->elementType) { case AL_PTR_ELEM: /* XXXX don't know how to handle this */ case AL_NO_ELEM: Py_INCREF(Py_None); return Py_None; case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: return PyInt_FromLong((long) value.i); case AL_INT64_ELEM: return PyLong_FromLongLong(value.ll); case AL_FIXED_ELEM: return PyFloat_FromDouble(alFixedToDouble(value.ll)); case AL_CHAR_ELEM: if (value.ptr == NULL) { Py_INCREF(Py_None); return Py_None; } return PyString_FromString((char *) value.ptr); default: PyErr_SetString(ErrorObject, "unknown element type"); return NULL; }} static intpython2elem(PyObject *item, void *ptr, int elementType){ switch (elementType) { case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: if (!PyInt_Check(item)) { PyErr_BadArgument(); return -1; } *((int *) ptr) = PyInt_AsLong(item); break; case AL_INT64_ELEM: if (PyInt_Check(item)) *((long long *) ptr) = PyInt_AsLong(item); else if (PyLong_Check(item)) *((long long *) ptr) = PyLong_AsLongLong(item); else { PyErr_BadArgument(); return -1; } break; case AL_FIXED_ELEM: if (PyInt_Check(item)) *((long long *) ptr) = alDoubleToFixed((double) PyInt_AsLong(item)); else if (PyFloat_Check(item)) *((long long *) ptr) = alDoubleToFixed(PyFloat_AsDouble(item)); else { PyErr_BadArgument(); return -1; } break; default: PyErr_SetString(ErrorObject, "unknown element type"); return -1; } return 0;} static intpython2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo){ ALparamInfo info; int i, stepsize; PyObject *item; if (pinfo == NULL) { pinfo = &info; if (alGetParamInfo(resource, param->param, &info) < 0) return -1; } switch (pinfo->valueType) { case AL_STRING_VAL: if (pinfo->elementType != AL_CHAR_ELEM) { PyErr_SetString(ErrorObject, "unknown element type"); return -1; } if (!PyString_Check(value)) { PyErr_BadArgument(); return -1; } param->value.ptr = PyString_AS_STRING(value); param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/ break; case AL_SET_VAL: case AL_VECTOR_VAL: if (!PyList_Check(value) && !PyTuple_Check(value)) { PyErr_BadArgument(); return -1; } switch (pinfo->elementType) { case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: param->sizeIn = PySequence_Size(value); param->value.ptr = PyMem_NEW(int, param->sizeIn); stepsize = sizeof(int); break; case AL_INT64_ELEM: case AL_FIXED_ELEM: param->sizeIn = PySequence_Size(value); param->value.ptr = PyMem_NEW(long long, param->sizeIn); stepsize = sizeof(long long); break; } for (i = 0; i < param->sizeIn; i++) { item = PySequence_GetItem(value, i); if (python2elem(item, (void *) ((char *) param->value.ptr + i*stepsize), pinfo->elementType) < 0) { PyMem_DEL(param->value.ptr); return -1; } } break; case AL_SCALAR_VAL: switch (pinfo->elementType) { case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: return python2elem(value, (void *) ¶m->value.i, pinfo->elementType); case AL_INT64_ELEM: case AL_FIXED_ELEM: return python2elem(value, (void *) ¶m->value.ll, pinfo->elementType); default: PyErr_SetString(ErrorObject, "unknown element type"); return -1; } } return 0;} static intpython2params(int resource1, int resource2, PyObject *list, ALpv **pvsp, ALparamInfo **pinfop){ PyObject *item; ALpv *pvs; ALparamInfo *pinfo; int npvs, i; npvs = PyList_Size(list); pvs = PyMem_NEW(ALpv, npvs); pinfo = PyMem_NEW(ALparamInfo, npvs); for (i = 0; i < npvs; i++) { item = PyList_GetItem(list, i); if (!PyArg_ParseTuple(item, "iO", &pvs[i].param, &item)) goto error; if (alGetParamInfo(resource1, pvs[i].param, &pinfo[i]) < 0 && alGetParamInfo(resource2, pvs[i].param, &pinfo[i]) < 0) goto error; if (python2param(resource1, &pvs[i], item, &pinfo[i]) < 0) goto error; } *pvsp = pvs; *pinfop = pinfo; return npvs; error: /* XXXX we should clean up everything */ if (pvs) PyMem_DEL(pvs); if (pinfo) PyMem_DEL(pinfo); return -1;} /* -------------------------------------------------------- */ static PyObject *SetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig, int)){ int par; if (!PyArg_ParseTuple(args, "i:SetConfig", &par)) return NULL; if ((*func)(self->config, par) == -1) return NULL; Py_INCREF(Py_None); return Py_None;} static PyObject *GetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig)){ int par; if (!PyArg_ParseTuple(args, ":GetConfig")) return NULL; if ((par = (*func)(self->config)) == -1) return NULL; return PyInt_FromLong((long) par);} PyDoc_STRVAR(alc_SetWidth__doc__,"alSetWidth: set the wordsize for integer audio data."); static PyObject *alc_SetWidth(alcobject *self, PyObject *args){ return SetConfig(self, args, alSetWidth);} PyDoc_STRVAR(alc_GetWidth__doc__,"alGetWidth: get the wordsize for integer audio data."); static PyObject *alc_GetWidth(alcobject *self, PyObject *args){ return GetConfig(self, args, alGetWidth);} PyDoc_STRVAR(alc_SetSampFmt__doc__,"alSetSampFmt: set the sample format setting in an audio ALconfig ""structure."); static PyObject *alc_SetSampFmt(alcobject *self, PyObject *args){ return SetConfig(self, args, alSetSampFmt);} PyDoc_STRVAR(alc_GetSampFmt__doc__,"alGetSampFmt: get the sample format setting in an audio ALconfig ""structure."); static PyObject *alc_GetSampFmt(alcobject *self, PyObject *args){ return GetConfig(self, args, alGetSampFmt);} PyDoc_STRVAR(alc_SetChannels__doc__,"alSetChannels: set the channel settings in an audio ALconfig."); static PyObject *alc_SetChannels(alcobject *self, PyObject *args){ return SetConfig(self, args, alSetChannels);} PyDoc_STRVAR(alc_GetChannels__doc__,"alGetChannels: get the channel settings in an audio ALconfig."); static PyObject *alc_GetChannels(alcobject *self, PyObject *args){ return GetConfig(self, args, alGetChannels);} PyDoc_STRVAR(alc_SetFloatMax__doc__,"alSetFloatMax: set the maximum value of floating point sample data."); static PyObject *alc_SetFloatMax(alcobject *self, PyObject *args){ double maximum_value; if (!PyArg_ParseTuple(args, "d:SetFloatMax", &maximum_value)) return NULL; if (alSetFloatMax(self->config, maximum_value) < 0) return NULL; Py_INCREF(Py_None); return Py_None;} PyDoc_STRVAR(alc_GetFloatMax__doc__,"alGetFloatMax: get the maximum value of floating point sample data."); static PyObject *alc_GetFloatMax(alcobject *self, PyObject *args){ double maximum_value; if (!PyArg_ParseTuple(args, ":GetFloatMax")) return NULL; if ((maximum_value = alGetFloatMax(self->config)) == 0) return NULL; return PyFloat_FromDouble(maximum_value);} PyDoc_STRVAR(alc_SetDevice__doc__,"alSetDevice: set the device setting in an audio ALconfig structure."); static PyObject *alc_SetDevice(alcobject *self, PyObject *args){ return SetConfig(self, args, alSetDevice);} PyDoc_STRVAR(alc_GetDevice__doc__,"alGetDevice: get the device setting in an audio ALconfig structure."); static PyObject *alc_GetDevice(alcobject *self, PyObject *args){ return GetConfig(self, args, alGetDevice);} PyDoc_STRVAR(alc_SetQueueSize__doc__,"alSetQueueSize: set audio port buffer size."); static PyObject *alc_SetQueueSize(alcobject *self, PyObject *args){ return SetConfig(self, args, alSetQueueSize);} PyDoc_STRVAR(alc_GetQueueSize__doc__,"alGetQueueSize: get audio port buffer size."); static PyObject *alc_GetQueueSize(alcobject *self, PyObject *args){ return GetConfig(self, args, alGetQueueSize);} #endif /* AL_NO_ELEM */ static PyObject *setconfig(alcobject *self, PyObject *args, int (*func)(ALconfig, long)){ long par; if (!PyArg_ParseTuple(args, "l:SetConfig", &par)) return NULL; if ((*func)(self->config, par) == -1) return NULL; Py_INCREF(Py_None); return Py_None;} static PyObject *getconfig(alcobject *self, PyObject *args, long (*func)(ALconfig)){ long par; if (!PyArg_ParseTuple(args, ":GetConfig")) return NULL; if ((par = (*func)(self->config)) == -1) return NULL; return PyInt_FromLong((long) par);} static PyObject *alc_setqueuesize (alcobject *self, PyObject *args){ return setconfig(self, args, ALsetqueuesize);} static PyObject *alc_getqueuesize (alcobject *self, PyObject *args){ return getconfig(self, args, ALgetqueuesize);} static PyObject *alc_setwidth (alcobject *self, PyObject *args){ return setconfig(self, args, ALsetwidth);} static PyObject *alc_getwidth (alcobject *self, PyObject *args){ return getconfig(self, args, ALgetwidth); } static PyObject *alc_getchannels (alcobject *self, PyObject *args){ return getconfig(self, args, ALgetchannels); } static PyObject *alc_setchannels (alcobject *self, PyObject *args){ return setconfig(self, args, ALsetchannels);} #ifdef AL_405 static PyObject *alc_getsampfmt (alcobject *self, PyObject *args){ return getconfig(self, args, ALgetsampfmt); } static PyObject *alc_setsampfmt (alcobject *self, PyObject *args){ return setconfig(self, args, ALsetsampfmt);} static PyObject *alc_getfloatmax(alcobject *self, PyObject *args){ double arg; if (!PyArg_ParseTuple(args, ":GetFloatMax")) return 0; if ((arg = ALgetfloatmax(self->config)) == 0) return NULL; return PyFloat_FromDouble(arg);} Lines 1–500 of 3226. Load more
#define OLD_INTERFACE /* define for pre-Irix 6 interface */ #include "Python.h" #include "stringobject.h" #include <audio.h> #include <stdarg.h> #ifndef AL_NO_ELEM #ifndef OLD_INTERFACE #define OLD_INTERFACE #endif /* OLD_INTERFACE */ #endif /* AL_NO_ELEM */ static PyObject *ErrorObject; /* ----------------------------------------------------- */ /* Declarations for objects of type port */ typedef struct { PyObject_HEAD /* XXXX Add your own stuff here */ ALport port; } alpobject; static PyTypeObject Alptype; /* ---------------------------------------------------------------- */ /* Declarations for objects of type config */ typedef struct { PyObject_HEAD /* XXXX Add your own stuff here */ ALconfig config; } alcobject; static PyTypeObject Alctype; static void ErrorHandler(long code, const char *fmt, ...) { va_list args; char buf[128]; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); PyErr_SetString(ErrorObject, buf); } #ifdef AL_NO_ELEM /* IRIX 6 */ static PyObject * param2python(int resource, int param, ALvalue value, ALparamInfo *pinfo) { ALparamInfo info; if (pinfo == NULL) { pinfo = &info; if (alGetParamInfo(resource, param, &info) < 0) return NULL; } switch (pinfo->elementType) { case AL_PTR_ELEM: /* XXXX don't know how to handle this */ case AL_NO_ELEM: Py_INCREF(Py_None); return Py_None; case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: return PyInt_FromLong((long) value.i); case AL_INT64_ELEM: return PyLong_FromLongLong(value.ll); case AL_FIXED_ELEM: return PyFloat_FromDouble(alFixedToDouble(value.ll)); case AL_CHAR_ELEM: if (value.ptr == NULL) { Py_INCREF(Py_None); return Py_None; } return PyString_FromString((char *) value.ptr); default: PyErr_SetString(ErrorObject, "unknown element type"); return NULL; } } static int python2elem(PyObject *item, void *ptr, int elementType) { switch (elementType) { case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: if (!PyInt_Check(item)) { PyErr_BadArgument(); return -1; } *((int *) ptr) = PyInt_AsLong(item); break; case AL_INT64_ELEM: if (PyInt_Check(item)) *((long long *) ptr) = PyInt_AsLong(item); else if (PyLong_Check(item)) *((long long *) ptr) = PyLong_AsLongLong(item); else { PyErr_BadArgument(); return -1; } break; case AL_FIXED_ELEM: if (PyInt_Check(item)) *((long long *) ptr) = alDoubleToFixed((double) PyInt_AsLong(item)); else if (PyFloat_Check(item)) *((long long *) ptr) = alDoubleToFixed(PyFloat_AsDouble(item)); else { PyErr_BadArgument(); return -1; } break; default: PyErr_SetString(ErrorObject, "unknown element type"); return -1; } return 0; } static int python2param(int resource, ALpv *param, PyObject *value, ALparamInfo *pinfo) { ALparamInfo info; int i, stepsize; PyObject *item; if (pinfo == NULL) { pinfo = &info; if (alGetParamInfo(resource, param->param, &info) < 0) return -1; } switch (pinfo->valueType) { case AL_STRING_VAL: if (pinfo->elementType != AL_CHAR_ELEM) { PyErr_SetString(ErrorObject, "unknown element type"); return -1; } if (!PyString_Check(value)) { PyErr_BadArgument(); return -1; } param->value.ptr = PyString_AS_STRING(value); param->sizeIn = PyString_GET_SIZE(value)+1; /*account for NUL*/ break; case AL_SET_VAL: case AL_VECTOR_VAL: if (!PyList_Check(value) && !PyTuple_Check(value)) { PyErr_BadArgument(); return -1; } switch (pinfo->elementType) { case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: param->sizeIn = PySequence_Size(value); param->value.ptr = PyMem_NEW(int, param->sizeIn); stepsize = sizeof(int); break; case AL_INT64_ELEM: case AL_FIXED_ELEM: param->sizeIn = PySequence_Size(value); param->value.ptr = PyMem_NEW(long long, param->sizeIn); stepsize = sizeof(long long); break; } for (i = 0; i < param->sizeIn; i++) { item = PySequence_GetItem(value, i); if (python2elem(item, (void *) ((char *) param->value.ptr + i*stepsize), pinfo->elementType) < 0) { PyMem_DEL(param->value.ptr); return -1; } } break; case AL_SCALAR_VAL: switch (pinfo->elementType) { case AL_INT32_ELEM: case AL_RESOURCE_ELEM: case AL_ENUM_ELEM: return python2elem(value, (void *) ¶m->value.i, pinfo->elementType); case AL_INT64_ELEM: case AL_FIXED_ELEM: return python2elem(value, (void *) ¶m->value.ll, pinfo->elementType); default: PyErr_SetString(ErrorObject, "unknown element type"); return -1; } } return 0; } static int python2params(int resource1, int resource2, PyObject *list, ALpv **pvsp, ALparamInfo **pinfop) { PyObject *item; ALpv *pvs; ALparamInfo *pinfo; int npvs, i; npvs = PyList_Size(list); pvs = PyMem_NEW(ALpv, npvs); pinfo = PyMem_NEW(ALparamInfo, npvs); for (i = 0; i < npvs; i++) { item = PyList_GetItem(list, i); if (!PyArg_ParseTuple(item, "iO", &pvs[i].param, &item)) goto error; if (alGetParamInfo(resource1, pvs[i].param, &pinfo[i]) < 0 && alGetParamInfo(resource2, pvs[i].param, &pinfo[i]) < 0) goto error; if (python2param(resource1, &pvs[i], item, &pinfo[i]) < 0) goto error; } *pvsp = pvs; *pinfop = pinfo; return npvs; error: /* XXXX we should clean up everything */ if (pvs) PyMem_DEL(pvs); if (pinfo) PyMem_DEL(pinfo); return -1; } /* -------------------------------------------------------- */ static PyObject * SetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig, int)) { int par; if (!PyArg_ParseTuple(args, "i:SetConfig", &par)) return NULL; if ((*func)(self->config, par) == -1) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject * GetConfig(alcobject *self, PyObject *args, int (*func)(ALconfig)) { int par; if (!PyArg_ParseTuple(args, ":GetConfig")) return NULL; if ((par = (*func)(self->config)) == -1) return NULL; return PyInt_FromLong((long) par); } PyDoc_STRVAR(alc_SetWidth__doc__, "alSetWidth: set the wordsize for integer audio data."); static PyObject * alc_SetWidth(alcobject *self, PyObject *args) { return SetConfig(self, args, alSetWidth); } PyDoc_STRVAR(alc_GetWidth__doc__, "alGetWidth: get the wordsize for integer audio data."); static PyObject * alc_GetWidth(alcobject *self, PyObject *args) { return GetConfig(self, args, alGetWidth); } PyDoc_STRVAR(alc_SetSampFmt__doc__, "alSetSampFmt: set the sample format setting in an audio ALconfig " "structure."); static PyObject * alc_SetSampFmt(alcobject *self, PyObject *args) { return SetConfig(self, args, alSetSampFmt); } PyDoc_STRVAR(alc_GetSampFmt__doc__, "alGetSampFmt: get the sample format setting in an audio ALconfig " "structure."); static PyObject * alc_GetSampFmt(alcobject *self, PyObject *args) { return GetConfig(self, args, alGetSampFmt); } PyDoc_STRVAR(alc_SetChannels__doc__, "alSetChannels: set the channel settings in an audio ALconfig."); static PyObject * alc_SetChannels(alcobject *self, PyObject *args) { return SetConfig(self, args, alSetChannels); } PyDoc_STRVAR(alc_GetChannels__doc__, "alGetChannels: get the channel settings in an audio ALconfig."); static PyObject * alc_GetChannels(alcobject *self, PyObject *args) { return GetConfig(self, args, alGetChannels); } PyDoc_STRVAR(alc_SetFloatMax__doc__, "alSetFloatMax: set the maximum value of floating point sample data."); static PyObject * alc_SetFloatMax(alcobject *self, PyObject *args) { double maximum_value; if (!PyArg_ParseTuple(args, "d:SetFloatMax", &maximum_value)) return NULL; if (alSetFloatMax(self->config, maximum_value) < 0) return NULL; Py_INCREF(Py_None); return Py_None; } PyDoc_STRVAR(alc_GetFloatMax__doc__, "alGetFloatMax: get the maximum value of floating point sample data."); static PyObject * alc_GetFloatMax(alcobject *self, PyObject *args) { double maximum_value; if (!PyArg_ParseTuple(args, ":GetFloatMax")) return NULL; if ((maximum_value = alGetFloatMax(self->config)) == 0) return NULL; return PyFloat_FromDouble(maximum_value); } PyDoc_STRVAR(alc_SetDevice__doc__, "alSetDevice: set the device setting in an audio ALconfig structure."); static PyObject * alc_SetDevice(alcobject *self, PyObject *args) { return SetConfig(self, args, alSetDevice); } PyDoc_STRVAR(alc_GetDevice__doc__, "alGetDevice: get the device setting in an audio ALconfig structure."); static PyObject * alc_GetDevice(alcobject *self, PyObject *args) { return GetConfig(self, args, alGetDevice); } PyDoc_STRVAR(alc_SetQueueSize__doc__, "alSetQueueSize: set audio port buffer size."); static PyObject * alc_SetQueueSize(alcobject *self, PyObject *args) { return SetConfig(self, args, alSetQueueSize); } PyDoc_STRVAR(alc_GetQueueSize__doc__, "alGetQueueSize: get audio port buffer size."); static PyObject * alc_GetQueueSize(alcobject *self, PyObject *args) { return GetConfig(self, args, alGetQueueSize); } #endif /* AL_NO_ELEM */ static PyObject * setconfig(alcobject *self, PyObject *args, int (*func)(ALconfig, long)) { long par; if (!PyArg_ParseTuple(args, "l:SetConfig", &par)) return NULL; if ((*func)(self->config, par) == -1) return NULL; Py_INCREF(Py_None); return Py_None; } static PyObject * getconfig(alcobject *self, PyObject *args, long (*func)(ALconfig)) { long par; if (!PyArg_ParseTuple(args, ":GetConfig")) return NULL; if ((par = (*func)(self->config)) == -1) return NULL; return PyInt_FromLong((long) par); } static PyObject * alc_setqueuesize (alcobject *self, PyObject *args) { return setconfig(self, args, ALsetqueuesize); } static PyObject * alc_getqueuesize (alcobject *self, PyObject *args) { return getconfig(self, args, ALgetqueuesize); } static PyObject * alc_setwidth (alcobject *self, PyObject *args) { return setconfig(self, args, ALsetwidth); } static PyObject * alc_getwidth (alcobject *self, PyObject *args) { return getconfig(self, args, ALgetwidth); } static PyObject * alc_getchannels (alcobject *self, PyObject *args) { return getconfig(self, args, ALgetchannels); } static PyObject * alc_setchannels (alcobject *self, PyObject *args) { return setconfig(self, args, ALsetchannels); } #ifdef AL_405 static PyObject * alc_getsampfmt (alcobject *self, PyObject *args) { return getconfig(self, args, ALgetsampfmt); } static PyObject * alc_setsampfmt (alcobject *self, PyObject *args) { return setconfig(self, args, ALsetsampfmt); } static PyObject * alc_getfloatmax(alcobject *self, PyObject *args) { double arg; if (!PyArg_ParseTuple(args, ":GetFloatMax")) return 0; if ((arg = ALgetfloatmax(self->config)) == 0) return NULL; return PyFloat_FromDouble(arg); }