📄 almodule.c
字号:
}
static PyObject *
alp_getfilled(alpobject *self, PyObject *args)
{
long count;
if (!PyArg_ParseTuple(args, ":GetFilled"))
return NULL;
if ((count = ALgetfilled(self-> port)) == -1)
return NULL;
return PyInt_FromLong(count);
}
static PyObject *
alp_getfillable(alpobject *self, PyObject *args)
{
long count;
if (!PyArg_ParseTuple(args, ":GetFillable"))
return NULL;
if ((count = ALgetfillable(self-> port)) == -1)
return NULL;
return PyInt_FromLong (count);
}
static PyObject *
alp_readsamps(alpobject *self, PyObject *args)
{
long count;
PyObject *v;
ALconfig c;
int width;
int ret;
if (!PyArg_ParseTuple(args, "l:readsamps", &count))
return NULL;
if (count <= 0) {
PyErr_SetString(ErrorObject, "al.readsamps : arg <= 0");
return NULL;
}
c = ALgetconfig(self->port);
#ifdef AL_405
width = ALgetsampfmt(c);
if (width == AL_SAMPFMT_FLOAT)
width = sizeof(float);
else if (width == AL_SAMPFMT_DOUBLE)
width = sizeof(double);
else
width = ALgetwidth(c);
#else
width = ALgetwidth(c);
#endif /* AL_405 */
ALfreeconfig(c);
v = PyString_FromStringAndSize((char *)NULL, width * count);
if (v == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
ret = ALreadsamps(self->port, (void *) PyString_AsString(v), count);
Py_END_ALLOW_THREADS
if (ret == -1) {
Py_DECREF(v);
return NULL;
}
return (v);
}
static PyObject *
alp_writesamps(alpobject *self, PyObject *args)
{
char *buf;
int size, width;
ALconfig c;
int ret;
if (!PyArg_ParseTuple(args, "s#:writesamps", &buf, &size))
return NULL;
c = ALgetconfig(self->port);
#ifdef AL_405
width = ALgetsampfmt(c);
if (width == AL_SAMPFMT_FLOAT)
width = sizeof(float);
else if (width == AL_SAMPFMT_DOUBLE)
width = sizeof(double);
else
width = ALgetwidth(c);
#else
width = ALgetwidth(c);
#endif /* AL_405 */
ALfreeconfig(c);
Py_BEGIN_ALLOW_THREADS
ret = ALwritesamps (self->port, (void *) buf, (long) size / width);
Py_END_ALLOW_THREADS
if (ret == -1)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
alp_getfillpoint(alpobject *self, PyObject *args)
{
long count;
if (!PyArg_ParseTuple(args, ":GetFillPoint"))
return NULL;
if ((count = ALgetfillpoint(self->port)) == -1)
return NULL;
return PyInt_FromLong(count);
}
static PyObject *
alp_setfillpoint(alpobject *self, PyObject *args)
{
long count;
if (!PyArg_ParseTuple(args, "l:SetFillPoint", &count))
return NULL;
if (ALsetfillpoint(self->port, count) == -1)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
alp_setconfig(alpobject *self, PyObject *args)
{
alcobject *config;
if (!PyArg_ParseTuple(args, "O!:SetConfig", &Alctype, &config))
return NULL;
if (ALsetconfig(self->port, config->config) == -1)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
alp_getconfig(alpobject *self, PyObject *args)
{
ALconfig config;
if (!PyArg_ParseTuple(args, ":GetConfig"))
return NULL;
config = ALgetconfig(self->port);
if (config == NULL)
return NULL;
return newalcobject(config);
}
#ifdef AL_405
static PyObject *
alp_getstatus(alpobject *self, PyObject *args)
{
PyObject *list, *v;
long *PVbuffer;
long length;
int i;
if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &list))
return NULL;
length = PyList_Size(list);
PVbuffer = PyMem_NEW(long, length);
if (PVbuffer == NULL)
return PyErr_NoMemory();
for (i = 0; i < length; i++) {
v = PyList_GetItem(list, i);
if (!PyInt_Check(v)) {
PyMem_DEL(PVbuffer);
PyErr_BadArgument();
return NULL;
}
PVbuffer[i] = PyInt_AsLong(v);
}
if (ALgetstatus(self->port, PVbuffer, length) == -1)
return NULL;
for (i = 0; i < length; i++)
PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));
PyMem_DEL(PVbuffer);
Py_INCREF(Py_None);
return Py_None;
}
#endif /* AL_405 */
#endif /* OLD_INTERFACE */
static struct PyMethodDef alp_methods[] = {
#ifdef AL_NO_ELEM /* IRIX 6 */
{"SetConfig", (PyCFunction)alp_SetConfig, METH_VARARGS, alp_SetConfig__doc__},
{"GetConfig", (PyCFunction)alp_GetConfig, METH_VARARGS, alp_GetConfig__doc__},
{"GetResource", (PyCFunction)alp_GetResource, METH_VARARGS, alp_GetResource__doc__},
{"GetFD", (PyCFunction)alp_GetFD, METH_VARARGS, alp_GetFD__doc__},
{"GetFilled", (PyCFunction)alp_GetFilled, METH_VARARGS, alp_GetFilled__doc__},
{"GetFillable", (PyCFunction)alp_GetFillable, METH_VARARGS, alp_GetFillable__doc__},
{"ReadFrames", (PyCFunction)alp_ReadFrames, METH_VARARGS, alp_ReadFrames__doc__},
{"DiscardFrames", (PyCFunction)alp_DiscardFrames, METH_VARARGS, alp_DiscardFrames__doc__},
{"ZeroFrames", (PyCFunction)alp_ZeroFrames, METH_VARARGS, alp_ZeroFrames__doc__},
{"SetFillPoint", (PyCFunction)alp_SetFillPoint, METH_VARARGS, alp_SetFillPoint__doc__},
{"GetFillPoint", (PyCFunction)alp_GetFillPoint, METH_VARARGS, alp_GetFillPoint__doc__},
{"GetFrameNumber", (PyCFunction)alp_GetFrameNumber, METH_VARARGS, alp_GetFrameNumber__doc__},
{"GetFrameTime", (PyCFunction)alp_GetFrameTime, METH_VARARGS, alp_GetFrameTime__doc__},
{"WriteFrames", (PyCFunction)alp_WriteFrames, METH_VARARGS, alp_WriteFrames__doc__},
{"ClosePort", (PyCFunction)alp_ClosePort, METH_VARARGS, alp_ClosePort__doc__},
#endif /* AL_NO_ELEM */
#ifdef OLD_INTERFACE
{"closeport", (PyCFunction)alp_closeport, METH_VARARGS},
{"getfd", (PyCFunction)alp_getfd, METH_VARARGS},
{"fileno", (PyCFunction)alp_getfd, METH_VARARGS},
{"getfilled", (PyCFunction)alp_getfilled, METH_VARARGS},
{"getfillable", (PyCFunction)alp_getfillable, METH_VARARGS},
{"readsamps", (PyCFunction)alp_readsamps, METH_VARARGS},
{"writesamps", (PyCFunction)alp_writesamps, METH_VARARGS},
{"setfillpoint", (PyCFunction)alp_setfillpoint, METH_VARARGS},
{"getfillpoint", (PyCFunction)alp_getfillpoint, METH_VARARGS},
{"setconfig", (PyCFunction)alp_setconfig, METH_VARARGS},
{"getconfig", (PyCFunction)alp_getconfig, METH_VARARGS},
#ifdef AL_405
{"getstatus", (PyCFunction)alp_getstatus, METH_VARARGS},
#endif /* AL_405 */
#endif /* OLD_INTERFACE */
{NULL, NULL} /* sentinel */
};
/* ---------- */
static PyObject *
newalpobject(ALport port)
{
alpobject *self;
self = PyObject_New(alpobject, &Alptype);
if (self == NULL)
return NULL;
/* XXXX Add your own initializers here */
self->port = port;
return (PyObject *) self;
}
static void
alp_dealloc(alpobject *self)
{
/* XXXX Add your own cleanup code here */
if (self->port) {
#ifdef AL_NO_ELEM /* IRIX 6 */
alClosePort(self->port);
#else
ALcloseport(self->port);
#endif
}
PyObject_Del(self);
}
static PyObject *
alp_getattr(alpobject *self, char *name)
{
/* XXXX Add your own getattr code here */
if (self->port == NULL) {
PyErr_SetString(ErrorObject, "port already closed");
return NULL;
}
return Py_FindMethod(alp_methods, (PyObject *)self, name);
}
static char Alptype__doc__[] =
""
;
static PyTypeObject Alptype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"al.port", /*tp_name*/
sizeof(alpobject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)alp_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
(getattrfunc)alp_getattr, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
(hashfunc)0, /*tp_hash*/
(ternaryfunc)0, /*tp_call*/
(reprfunc)0, /*tp_str*/
/* Space for future expansion */
0L,0L,0L,0L,
Alptype__doc__ /* Documentation string */
};
/* End of code for port objects */
/* -------------------------------------------------------- */
#ifdef AL_NO_ELEM /* IRIX 6 */
static char al_NewConfig__doc__[] =
"alNewConfig: create and initialize an audio ALconfig structure."
;
static PyObject *
al_NewConfig(PyObject *self, PyObject *args)
{
ALconfig config;
if (!PyArg_ParseTuple(args, ":NewConfig"))
return NULL;
if ((config = alNewConfig()) == NULL)
return NULL;
return newalcobject(config);
}
static char al_OpenPort__doc__[] =
"alOpenPort: open an audio port."
;
static PyObject *
al_OpenPort(PyObject *self, PyObject *args)
{
ALport port;
char *name, *dir;
alcobject *config = NULL;
if (!PyArg_ParseTuple(args, "ss|O!:OpenPort", &name, &dir, &Alctype, &config))
return NULL;
if ((port = alOpenPort(name, dir, config ? config->config : NULL)) == NULL)
return NULL;
return newalpobject(port);
}
static char al_Connect__doc__[] =
"alConnect: connect two audio I/O resources."
;
static PyObject *
al_Connect(PyObject *self, PyObject *args)
{
int source, dest, nprops = 0, id, i;
ALpv *props = NULL;
ALparamInfo *propinfo = NULL;
PyObject *propobj = NULL;
if (!PyArg_ParseTuple(args, "ii|O!:Connect", &source, &dest, &PyList_Type, &propobj))
return NULL;
if (propobj != NULL) {
nprops = python2params(source, dest, propobj, &props, &propinfo);
if (nprops < 0)
return NULL;
}
id = alConnect(source, dest, props, nprops);
if (props) {
for (i = 0; i < nprops; i++) {
switch (propinfo[i].valueType) {
case AL_SET_VAL:
case AL_VECTOR_VAL:
PyMem_DEL(props[i].value.ptr);
break;
}
}
PyMem_DEL(props);
PyMem_DEL(propinfo);
}
if (id < 0)
return NULL;
return PyInt_FromLong((long) id);
}
static char al_Disconnect__doc__[] =
"alDisconnect: delete a connection between two audio I/O resources."
;
static PyObject *
al_Disconnect(PyObject *self, PyObject *args)
{
int res;
if (!PyArg_ParseTuple(args, "i:Disconnect", &res))
return NULL;
if (alDisconnect(res) < 0)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static char al_GetParams__doc__[] =
"alGetParams: get the values of audio resource parameters."
;
static PyObject *
al_GetParams(PyObject *self, PyObject *args)
{
int resource;
PyObject *pvslist, *item = NULL, *v = NULL;
ALpv *pvs;
int i, j, npvs;
ALparamInfo *pinfo;
if (!PyArg_ParseTuple(args, "iO!:GetParams", &resource, &PyList_Type, &pvslist))
return NULL;
npvs = PyList_Size(pvslist);
pvs = PyMem_NEW(ALpv, npvs);
pinfo = PyMem_NEW(ALparamInfo, npvs);
for (i = 0; i < npvs; i++) {
item = PyList_GetItem(pvslist, i);
if (!PyInt_Check(item)) {
item = NULL;
PyErr_SetString(ErrorObject, "list of integers expected");
goto error;
}
pvs[i].param = (int) PyInt_AsLong(item);
item = NULL; /* not needed anymore */
if (alGetParamInfo(resource, pvs[i].param, &pinfo[i]) < 0)
goto error;
switch (pinfo[i].valueType) {
case AL_NO_VAL:
break;
case AL_MATRIX_VAL:
pinfo[i].maxElems *= pinfo[i].maxElems2;
/* fall through */
case AL_STRING_VAL:
case AL_SET_VAL:
case AL_VECTOR_VAL:
switch (pinfo[i].elementType) {
case AL_INT32_ELEM:
case AL_RESOURCE_ELEM:
case AL_ENUM_ELEM:
pvs[i].value.ptr = PyMem_NEW(int, pinfo[i].maxElems);
pvs[i].sizeIn = pinfo[i].maxElems;
break;
case AL_INT64_ELEM:
case AL_FIXED_ELEM:
pvs[i].value.ptr = PyMem_NEW(long long, pinfo[i].maxElems);
pvs[i].sizeIn = pinfo[i].maxElems;
break;
case AL_CHAR_ELEM:
pvs[i].value.ptr = PyMem_NEW(char, 32);
pvs[i].sizeIn = 32;
break;
case AL_NO_ELEM:
case AL_PTR_ELEM:
default:
PyErr_SetString(ErrorObject, "internal error");
goto error;
}
break;
case AL_SCALAR_VAL:
break;
default:
PyErr_SetString(ErrorObject, "internal error");
goto error;
}
if (pinfo[i].valueType == AL_MATRIX_VAL) {
pinfo[i].maxElems /= pinfo[i].maxElems2;
pvs[i].sizeIn /= pinfo[i].maxElems2;
pvs[i].size2In = pinfo[i].maxElems2;
}
}
if (alGetParams(resource, pvs, npvs) < 0)
goto error;
v = PyList_New(npvs);
for (i = 0; i < npvs; i++) {
if (pvs[i].sizeOut < 0) {
char buf[32];
PyOS_snprintf(buf, sizeof(buf),
"problem with param %d", i);
PyErr_SetString(ErrorObject, buf);
goto error;
}
switch (pinfo[i].valueType) {
case AL_NO_VAL:
item = Py_None;
Py_INCREF(item);
break;
case AL_STRING_VAL:
item = PyString_FromString(pvs[i].value.ptr);
PyMem_DEL(pvs[i].value.ptr);
break;
case AL_MATRIX_VAL:
/* XXXX this is not right */
pvs[i].sizeOut *= pvs[i].size2Out;
/* fall through */
case AL_SET_VAL:
case AL_VECTOR_VAL:
item = PyList_New(pvs[i].sizeOut);
for (j = 0; j < pvs[i].sizeOut; j++) {
switch (pinfo[i].elementType) {
case AL_INT32_ELEM:
case AL_RESOURCE_ELEM:
case AL_ENUM_ELEM:
PyList_SetItem(item, j, PyInt_FromLong((long) ((int *) pvs[i].value.ptr)[j]));
break;
case AL_INT64_ELEM:
PyList_SetItem(item, j, PyLong_FromLongLong(((long long *) pvs[i].value.ptr)[j]));
break;
case AL_FIXED_ELEM:
PyList_SetItem(item, j, PyFloat_FromDouble(alFixedToDouble(((long long *) pvs[i].value.ptr)[j])));
break;
default:
PyErr_SetString(ErrorObject, "internal error");
goto error;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -