From 03c7468fcc51888c8271b904e4d6400ed5c1cbb1 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 7 Mar 2007 13:40:14 +0000 Subject: multiply inlets for py (hot and cold inlets) small optimizations and fixes use PyGILState_\*() functionality (enabled with PY_USE_GIL) updates for DSP processing __str__ method for pyext, to enable print self calls added message bundle functionality (pyext.Bundle class) enable compiled-only scripts (without .py) enable optimization of Python code in reease build let _inlets and _outlets default to 0 fix for numpy some ASSERTs for explicitly created pyext classes (should be runtime checks i guess) open editor for script under OS X fixing numpy initialization quirks enable symbol binding for all callables (not only functions and methods) _isthreaded is now a data member instead of a method fix for gcc4 added pyext._list and pyext._tuple to convert input lists to Python sequence objects enable module packages (module/__init__.py[co]), now also for Max python-like dotted module.function syntax cleaned up float vs. int pyext tags compiler flag to exclude DSP objects some optimizations and py reload fix more safety for calls where association python-pd has already been removed always run Python interpreter in the background svn path=/trunk/; revision=7474 --- externals/grill/py/scripts/sig.py | 200 +++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 100 deletions(-) (limited to 'externals/grill/py/scripts/sig.py') diff --git a/externals/grill/py/scripts/sig.py b/externals/grill/py/scripts/sig.py index 8aa1ce65..09be7b66 100644 --- a/externals/grill/py/scripts/sig.py +++ b/externals/grill/py/scripts/sig.py @@ -1,100 +1,100 @@ -# py/pyext - python script objects for PD and MaxMSP -# -# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org) -# For information on usage and redistribution, and for a DISCLAIMER OF ALL -# WARRANTIES, see the file, "license.txt," in this distribution. -# - -"""This is an example script for the py/pyext signal support. - -For numarray see http://numeric.scipy.org -It will probably once be replaced by Numeric(3) -""" - -try: - import pyext -except: - print "ERROR: This script must be loaded by the PD/Max py/pyext external" - -try: - import psyco - psyco.full() - print "Using JIT compilation" -except: - # don't care - pass - -import sys,math - -try: - import numarray -except: - print "Failed importing numarray module:",sys.exc_value - - -class gain(pyext._class): - """Just a simple gain stage""" - - gain = 0 - - def _signal(self): - # Multiply input vector by gain and copy to output - try: - self._outvec(0)[:] = self._invec(0)*self.gain - except: - pass - - -class gain2(pyext._class): - """More optimized version""" - - gain = 0 - - def _dsp(self): - if not self._arraysupport(): - print "No DSP support" - return False - - # cache vectors in this scope - self.invec = self._invec(0) - self.outvec = self._outvec(0) - # initialize _signal method here for optimized version - if self.invec is self.outvec: - self._signal = self.signal1 - else: - self._signal = self.signal2 - return True - - def signal1(self): - # Multiply signal vector in place - self.outvec *= self.gain - - def signal2(self): - # Multiply input vector by gain and copy to output - self.outvec[:] = self.invec*self.gain - - -class pan(pyext._class): - """Stereo panning""" - - def __init__(self): - self.float_1(0.5) - - def float_1(self,pos): - """pos ranges from 0 to 1""" - x = pos*math.pi/2 - self.fl = math.cos(x) - self.fr = math.sin(x) - - def _dsp(self): - # if _dsp is present it must return True to enable DSP - return pyext._arraysupport() - - def _signal(self): - # Multiply input vector by gain and copy to output - iv = self._invec(0) - # first process right output channel because left one could be - # identical to input - # we could also test with 'self._outvec(1)[:] is iv' - self._outvec(1)[:] = iv*self.fr - self._outvec(0)[:] = iv*self.fl +# py/pyext - python script objects for PD and MaxMSP +# +# Copyright (c) 2002-2005 Thomas Grill (gr@grrrr.org) +# For information on usage and redistribution, and for a DISCLAIMER OF ALL +# WARRANTIES, see the file, "license.txt," in this distribution. +# + +"""This is an example script for the py/pyext signal support. + +For numarray see http://numeric.scipy.org +It will probably once be replaced by Numeric(3) +""" + +try: + import pyext +except: + print "ERROR: This script must be loaded by the PD/Max py/pyext external" + +try: + import psyco + psyco.full() + print "Using JIT compilation" +except: + # don't care + pass + +import sys,math + +try: + import numarray +except: + print "Failed importing numarray module:",sys.exc_value + + +class gain(pyext._class): + """Just a simple gain stage""" + + gain = 0 + + def _signal(self): + # Multiply input vector by gain and copy to output + try: + self._outvec(0)[:] = self._invec(0)*self.gain + except: + pass + + +class gain2(pyext._class): + """More optimized version""" + + gain = 0 + + def _dsp(self): + if not self._arraysupport(): + print "No DSP support" + return False + + # cache vectors in this scope + self.invec = self._invec(0) + self.outvec = self._outvec(0) + # initialize _signal method here for optimized version + if self.invec is self.outvec: + self._signal = self.signal1 + else: + self._signal = self.signal2 + return True + + def signal1(self): + # Multiply signal vector in place + self.outvec *= self.gain + + def signal2(self): + # Multiply input vector by gain and copy to output + self.outvec[:] = self.invec*self.gain + + +class pan(pyext._class): + """Stereo panning""" + + def __init__(self): + self.float_1(0.5) + + def float_1(self,pos): + """pos ranges from 0 to 1""" + x = pos*math.pi/2 + self.fl = math.cos(x) + self.fr = math.sin(x) + + def _dsp(self): + # if _dsp is present it must return True to enable DSP + return pyext._arraysupport() + + def _signal(self): + # Multiply input vector by gain and copy to output + iv = self._invec(0) + # first process right output channel because left one could be + # identical to input + # we could also test with 'self._outvec(1)[:] is iv' + self._outvec(1)[:] = iv*self.fr + self._outvec(0)[:] = iv*self.fl -- cgit v1.2.1