From 75c5ef978b78193c13c08149322bd0e5421d312f Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Wed, 15 Apr 1998 14:08:51 +0000 Subject: Module with hooks for sound input --- Mac/Modules/snd/Sndihooks.c | 514 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 514 insertions(+) create mode 100644 Mac/Modules/snd/Sndihooks.c diff --git a/Mac/Modules/snd/Sndihooks.c b/Mac/Modules/snd/Sndihooks.c new file mode 100644 index 0000000..5c152d7 --- /dev/null +++ b/Mac/Modules/snd/Sndihooks.c @@ -0,0 +1,514 @@ +/*********************************************************** +Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, +The Netherlands. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Stichting Mathematisch +Centrum or CWI or Corporation for National Research Initiatives or +CNRI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +While CWI is the initial source for this software, a modified version +is made available by the Corporation for National Research Initiatives +(CNRI) at the Internet address ftp://ftp.python.org. + +STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH +CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR +PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + +#include "Python.h" +#include "macglue.h" +#include + +#pragma options align=mac68k +struct SampleRateAvailable_arg { + short numrates; + Handle rates; +}; + +struct SampleSizeAvailable_arg { + short numsizes; + Handle sizes; +}; + +#pragma options align=reset + +extern PyObject *ResObj_New(Handle); + +static PyObject *ErrorObject; + + +/* Convert Python object to unsigned Fixed */ +static int +PyMac_GetUFixed(PyObject *v, Fixed *f) +{ + double d; + unsigned long uns; + + if( !PyArg_Parse(v, "d", &d)) + return 0; + uns = (unsigned long)(d * 0x10000); + *f = (Fixed)uns; + return 1; +} + +/* Convert a Point to a Python object */ +static PyObject * +PyMac_BuildUFixed(Fixed f) +{ + double d; + unsigned long funs; + + funs = (unsigned long)f; + + d = funs; + d = d / 0x10000; + return Py_BuildValue("d", d); +} + + +/* ----------------------------------------------------- */ + +static char sndih_getChannelAvailable__doc__[] = +"" +; + +static PyObject * +sndih_getChannelAvailable(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short nchannel; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siChannelAvailable, (Ptr)&nchannel)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("h", nchannel); +} + +static char sndih_getNumberChannels__doc__[] = +"" +; + +static PyObject * +sndih_getNumberChannels(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short nchannel; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siNumberChannels, (Ptr)&nchannel)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("h", nchannel); +} + +static char sndih_setNumberChannels__doc__[] = +"" +; + +static PyObject * +sndih_setNumberChannels(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short nchannel; + OSErr err; + + if (!PyArg_ParseTuple(args, "lh", &inRefNum, &nchannel)) + return NULL; + + if( (err=SPBSetDeviceInfo(inRefNum, siNumberChannels, (Ptr)&nchannel)) != noErr ) + return PyMac_Error(err); + Py_INCREF(Py_None); + return Py_None; +} + +static char sndih_getContinuous__doc__[] = +"" +; + +static PyObject * +sndih_getContinuous(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short onoff; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siContinuous, (Ptr)&onoff)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("h", onoff); +} + +static char sndih_setContinuous__doc__[] = +"" +; + +static PyObject * +sndih_setContinuous(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short onoff; + OSErr err; + + if (!PyArg_ParseTuple(args, "lh", &inRefNum, &onoff)) + return NULL; + + if( (err=SPBSetDeviceInfo(inRefNum, siContinuous, (Ptr)&onoff)) != noErr ) + return PyMac_Error(err); + Py_INCREF(Py_None); + return Py_None; +} + +static char sndih_getInputSourceNames__doc__[] = +"" +; + +static PyObject * +sndih_getInputSourceNames(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + Handle names; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siInputSourceNames, (Ptr)&names)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("O&", ResObj_New, names); +} + +static char sndih_getInputSource__doc__[] = +"" +; + +static PyObject * +sndih_getInputSource(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short source; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siInputSource, (Ptr)&source)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("h", source); +} + +static char sndih_setInputSource__doc__[] = +"" +; + +static PyObject * +sndih_setInputSource(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short source; + OSErr err; + + if (!PyArg_ParseTuple(args, "lh", &inRefNum, &source)) + return NULL; + + if( (err=SPBSetDeviceInfo(inRefNum, siInputSource, (Ptr)&source)) != noErr ) + return PyMac_Error(err); + Py_INCREF(Py_None); + return Py_None; +} + +static char sndih_getPlayThruOnOff__doc__[] = +"" +; + +static PyObject * +sndih_getPlayThruOnOff(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short onoff; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siPlayThruOnOff, (Ptr)&onoff)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("h", onoff); +} + +static char sndih_setPlayThruOnOff__doc__[] = +"" +; + +static PyObject * +sndih_setPlayThruOnOff(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short onoff; + OSErr err; + + if (!PyArg_ParseTuple(args, "lh", &inRefNum, &onoff)) + return NULL; + + if( (err=SPBSetDeviceInfo(inRefNum, siPlayThruOnOff, (Ptr)&onoff)) != noErr ) + return PyMac_Error(err); + Py_INCREF(Py_None); + return Py_None; +} + +static char sndih_getSampleRate__doc__[] = +"" +; + +static PyObject * +sndih_getSampleRate(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + Fixed sample_rate; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siSampleRate, (Ptr)&sample_rate)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("O&", PyMac_BuildUFixed, sample_rate); +} + +static char sndih_setSampleRate__doc__[] = +"" +; + +static PyObject * +sndih_setSampleRate(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + Fixed sample_rate; + OSErr err; + + if (!PyArg_ParseTuple(args, "lO&", &inRefNum, PyMac_GetUFixed, &sample_rate)) + return NULL; + + if( (err=SPBSetDeviceInfo(inRefNum, siSampleRate, (Ptr)&sample_rate)) != noErr ) + return PyMac_Error(err); + Py_INCREF(Py_None); + return Py_None; +} + +static char sndih_getSampleSize__doc__[] = +"" +; + +static PyObject * +sndih_getSampleSize(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short bits; + OSErr err; + + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siSampleSize, (Ptr)&bits)) != noErr ) + return PyMac_Error(err); + return Py_BuildValue("h", bits); +} + +static char sndih_setSampleSize__doc__[] = +"" +; + +static PyObject * +sndih_setSampleSize(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + short size; + OSErr err; + + if (!PyArg_ParseTuple(args, "lh", &inRefNum, &size)) + return NULL; + + if( (err=SPBSetDeviceInfo(inRefNum, siSampleSize, (Ptr)&size)) != noErr ) + return PyMac_Error(err); + Py_INCREF(Py_None); + return Py_None; +} + +static char sndih_getSampleSizeAvailable__doc__[] = +"" +; + +static PyObject * +sndih_getSampleSizeAvailable(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + long inRefNum; + struct SampleSizeAvailable_arg arg; + OSErr err; + PyObject *rsizes; + short *fsizes; + int i; + + arg.sizes = NULL; + rsizes = NULL; + if (!PyArg_ParseTuple(args, "l", &inRefNum)) + return NULL; + + if( (err=SPBGetDeviceInfo(inRefNum, siSampleSizeAvailable, (Ptr)&arg)) != noErr ) { + return PyMac_Error(err); + } + fsizes = (short *)*(arg.sizes); + /* Handle contains a list of rates */ + if( (rsizes = PyTuple_New(arg.numsizes)) == NULL) + return NULL; + for( i=0; i