From 432472fe416edfb1f5548e7a4998e62869ff41e5 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 21 May 2003 10:50:37 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r641, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=642 --- tbext/make-files.txt | 6 +++ tbext/makefile | 114 +++++++++++++++++++++++++++++++++++++++++++++ tbext/source/main.cpp | 64 +++++++++++++++++++++++++ tbext/source/tbpow~.cpp | 100 +++++++++++++++++++++++++++++++++++++++ tbext/source/tbroute.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++++ tbext/source/tbsig~.cpp | 85 +++++++++++++++++++++++++++++++++ tbext/source/tbsroute~.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++ tbext/source/tbstrg.cpp | 95 +++++++++++++++++++++++++++++++++++++ tbext/tbroute.pd | 13 ++++++ tbext/tbroute~.pd | 9 ++++ tbext/tbsig~.pd | 16 +++++++ tbext/tbstrg.pd | 10 ++++ 12 files changed, 733 insertions(+) create mode 100755 tbext/make-files.txt create mode 100644 tbext/makefile create mode 100644 tbext/source/main.cpp create mode 100644 tbext/source/tbpow~.cpp create mode 100644 tbext/source/tbroute.cpp create mode 100644 tbext/source/tbsig~.cpp create mode 100644 tbext/source/tbsroute~.cpp create mode 100644 tbext/source/tbstrg.cpp create mode 100644 tbext/tbroute.pd create mode 100644 tbext/tbroute~.pd create mode 100644 tbext/tbsig~.pd create mode 100644 tbext/tbstrg.pd diff --git a/tbext/make-files.txt b/tbext/make-files.txt new file mode 100755 index 0000000..609e57b --- /dev/null +++ b/tbext/make-files.txt @@ -0,0 +1,6 @@ +# all the source files from the package +SRCS= \ + main.cpp tbroute.cpp tbstrg.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp + +#HDRS= \ + main.h diff --git a/tbext/makefile b/tbext/makefile new file mode 100644 index 0000000..a9577e7 --- /dev/null +++ b/tbext/makefile @@ -0,0 +1,114 @@ +# Makefile for icc @ linux adapted from Thomas Grill's xsample makefile +# +# usage: +# to build run "make" +# to install (as root), do "make install" +# + + + + +# your c++ compiler (if not g++) + CXX=icc + +# where does the PD installation reside? +PD=/usr/lib/pdsrc/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC= + +# where do the flext libraries reside? +FLEXTPATH=/usr/lib/flext + +# where should the objects be built? +TARGDIR=./ + +# where should tbext be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/externs + +# where should the tbext help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 +# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 +UFLAGS= -O3 -xW -tpp7 -ip -ipo #icc + + +FLEXTLIB=$(FLEXTPATH)/flext.a + +# compiler stuff +INCLUDES=$(PDINC) +FLAGS=-DFLEXT_SYS=2 -D__GNUG__ +CFLAGS=${UFLAGS} -O6 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions +LDFLAGS=$(CFLAGS) +LIBS=m + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=tbext +SRCDIR=source + +include make-files.txt + +MAKEFILE=makefile +TARGET=$(TARGDIR)/$(NAME).pd_linux + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) $(LDFLAGS) -shared $^ $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) + chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGDIR)/*.il $(TARGET) + + + + + + + + + + + + diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp new file mode 100644 index 0000000..c4317fd --- /dev/null +++ b/tbext/source/main.cpp @@ -0,0 +1,64 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbext is the collection of some external i wrote. */ +/* some are useful, others aren't... */ +/* */ +/* */ +/* tbext uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Hamid Drake & Assif Tsahar: Soul Bodies, Vol. 1 */ +/* I.S.O.: I.S.O */ +/* */ + + + +#include +#define TBEXT_VERSION "0.01" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) +#error upgrade your flext version!!!!!! +#endif + +void ttbext_setup() +{ + post("TBEXT: by tim blechmann"); + post("version "TBEXT_VERSION); + post("compiled on "__DATE__); + post(""); + + FLEXT_SETUP(tbroute); + FLEXT_SETUP(tbstrg); + FLEXT_DSP_SETUP(tbsroute); + FLEXT_DSP_SETUP(tbsig); + FLEXT_DSP_SETUP(tbpow); + +} + +FLEXT_LIB_SETUP(tbext,ttbext_setup) diff --git a/tbext/source/tbpow~.cpp b/tbext/source/tbpow~.cpp new file mode 100644 index 0000000..14a383c --- /dev/null +++ b/tbext/source/tbpow~.cpp @@ -0,0 +1,100 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbpow~ calculates the power of each sample. In fact i expected it to sound */ +/* better than it does. but maybe someone is interested in using it... */ +/* */ +/* */ +/* tbpow~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Assif Tsahar & Susie Ibarra: Home Cookin' */ +/* Painkiller: Talisman */ +/* */ + + + +#include + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class tbpow: public flext_dsp +{ + FLEXT_HEADER(tbpow,flext_dsp); + +public: // constructor + tbpow(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + + void set_power(float f); + +private: + float power; + + FLEXT_CALLBACK_1(set_power,float) + +}; + + +FLEXT_LIB_DSP("tbpow~",tbpow); + +tbpow::tbpow() +{ + AddInSignal(); + AddInFloat(); + AddOutSignal(); + + FLEXT_ADDMETHOD(1,set_power); + power=1; +} + + +void tbpow::m_signal(int n, float *const *in, float *const *out) +{ + const float *ins=in[0]; + float *outs = out[0]; + + while (n--) + { + *outs = pow(*ins,power); + *outs++; + *ins++; + } + +} + +void tbpow::set_power(float f) +{ + power=f; +} diff --git a/tbext/source/tbroute.cpp b/tbext/source/tbroute.cpp new file mode 100644 index 0000000..83d85a0 --- /dev/null +++ b/tbext/source/tbroute.cpp @@ -0,0 +1,112 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbroute is an advanced router. */ +/* the signal to the first inlet is being routed to the outlet specified */ +/* by the second inlet. */ +/* the number of outlets is specified by the creation argument */ +/* */ +/* */ +/* tbroute uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Hamid Drake & Assif Tsahar: Soul Bodies, Vol. 1 */ +/* I.S.O.: I.S.O */ +/* */ +/* */ + + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) +#error upgrade your flext version!!!!!! +#endif + +class tbroute: public flext_base +{ + FLEXT_HEADER(tbroute,flext_base); + +public: // constructor + tbroute(t_int chan); + +protected: + void route(t_float f); + + void routebang(); + void set_route(t_int i); + +private: + FLEXT_CALLBACK_1(route,t_float); + + FLEXT_CALLBACK(routebang); + FLEXT_CALLBACK_1(set_route,t_int); + t_int dest; +}; + + +FLEXT_LIB_1("tbroute",tbroute,int); + +tbroute::tbroute(t_int chan) +{ + AddInAnything(); + AddInInt(); + + for (t_int i=0; i!=chan;++i) + { + AddOutAnything(); + } + + FLEXT_ADDMETHOD(0,route); + FLEXT_ADDBANG(0,routebang); + FLEXT_ADDMETHOD(1,set_route); + dest=0; +} + +void tbroute::route(t_float f) +{ + ToOutFloat(dest,f); +} + + +void tbroute::routebang() +{ + ToOutBang(dest); +} + +void tbroute::set_route(t_int i) +{ + --i; + if ((i>-1) && (i + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class tbsig: public flext_dsp +{ + FLEXT_HEADER(tbsig,flext_dsp); + +public: // constructor + tbsig(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + +}; + + +FLEXT_LIB_DSP("tbsig~",tbsig); + +tbsig::tbsig() +{ + AddInSignal(); + AddOutSignal(); +} + + +void tbsig::m_signal(int n, float *const *in, float *const *out) +{ + const float *ins=in[0]; + float *outs = out[0]; + + while (n--) + { + if (*ins>0) + *outs = 1; + else + *outs = -1; + *outs++; + *ins++; + } + +} diff --git a/tbext/source/tbsroute~.cpp b/tbext/source/tbsroute~.cpp new file mode 100644 index 0000000..3d2264d --- /dev/null +++ b/tbext/source/tbsroute~.cpp @@ -0,0 +1,109 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbsroute~ is an advanced signal router. */ +/* the signal to the first inlet is being routed to the outlet specified */ +/* by the second inlet. */ +/* the number of outlets is specified by the creation argument */ +/* */ +/* */ +/* tbsroute~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: AMM: AMMMUSIC 1966 */ +/* Sun Ra: Dancing Shadows */ +/* */ + + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class tbsroute: public flext_dsp +{ + FLEXT_HEADER(tbsroute,flext_dsp) + +public: // constructor + tbsroute(int chan); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_route(int i); + +private: + FLEXT_CALLBACK_1(set_route,t_int) + t_int dest; +}; + + +FLEXT_LIB_DSP_1("tbroute~",tbsroute,int) + + tbsroute::tbsroute(t_int chan):dest(0) +{ + AddInSignal(); + AddInInt(); + + for (t_int i=0; i!=chan;++i) + { + AddOutSignal(); + } + + FLEXT_ADDMETHOD(1,set_route); +} + + +void tbsroute::m_signal(int n, float *const *in, float *const *out) +{ + + CopySamples(out[dest],in[0],n); + + for (int i = 0; i != CntOutSig(); i++) + if (i!=dest) ZeroSamples(out[i],n); + + + + +} + + +void tbsroute::set_route(t_int i) +{ + --i; + if ((i>-1) && (i + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) +#error upgrade your flext version!!!!!! +#endif + +class tbstrg: public flext_base +{ + FLEXT_HEADER(tbstrg,flext_base); + +public: // constructor + tbstrg(t_int chan); + +protected: + void set_route(t_int i); + +private: + + FLEXT_CALLBACK_1(set_route,t_int); + t_int dest; +}; + + +FLEXT_LIB_1("tbstrg",tbstrg,int); + +tbstrg::tbstrg(t_int chan) +{ + AddInInt(); + + for (t_int i=0; i!=chan;++i) + { + AddOutAnything(); + } + + + FLEXT_ADDMETHOD(0,set_route); + dest=0; +} + +void tbstrg::set_route(t_int i) +{ + if (i != dest) + { + --i; + if ((i>-1) && (i Date: Sun, 7 Sep 2003 00:42:00 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=934 --- tbext/config-pd-linux.txt | 36 ++++++++++++++ tbext/make-files.txt | 4 +- tbext/makefile | 114 --------------------------------------------- tbext/makefile.pd-linux | 92 ++++++++++++++++++++++++++++++++++++ tbext/source/main.cpp | 5 +- tbext/source/tbroute.cpp | 16 +++---- tbext/source/tbsroute~.cpp | 12 ++--- tbext/source/tbstrg.cpp | 2 +- 8 files changed, 150 insertions(+), 131 deletions(-) create mode 100755 tbext/config-pd-linux.txt delete mode 100644 tbext/makefile create mode 100644 tbext/makefile.pd-linux diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt new file mode 100755 index 0000000..e1fa248 --- /dev/null +++ b/tbext/config-pd-linux.txt @@ -0,0 +1,36 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile + +# your c++ compiler (if not g++) + CXX=icc + + +# where does the PD installation reside? +PD=/usr/lib/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=/home/tim/pd/devel_0_36/pd/src + +# where do the flext libraries reside? +FLEXTPATH=/usr/lib/flext + +# where should xsample objects be built? +TARGDIR=./pd-linux + +# where should xsample be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/externs + +# where should the xsample help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-xW -tpp7 -ip -ipo_obj -g # icc +# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 + +# define to link against shared flext library (flext version >= 0.5.0) +FLEXT_SHARED=1 + diff --git a/tbext/make-files.txt b/tbext/make-files.txt index 609e57b..ba3fe55 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -1,6 +1,8 @@ # all the source files from the package +SRCDIR = source SRCS= \ - main.cpp tbroute.cpp tbstrg.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp + main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp tbfft1.cpp # tbg7xx.cpp tbstrg.cpp + #HDRS= \ main.h diff --git a/tbext/makefile b/tbext/makefile deleted file mode 100644 index a9577e7..0000000 --- a/tbext/makefile +++ /dev/null @@ -1,114 +0,0 @@ -# Makefile for icc @ linux adapted from Thomas Grill's xsample makefile -# -# usage: -# to build run "make" -# to install (as root), do "make install" -# - - - - -# your c++ compiler (if not g++) - CXX=icc - -# where does the PD installation reside? -PD=/usr/lib/pdsrc/pd - -# where are the PD header files? -# leave it blank if it is a system directory (like /usr/local/include), -# since gcc 3.2 complains about it -PDINC= - -# where do the flext libraries reside? -FLEXTPATH=/usr/lib/flext - -# where should the objects be built? -TARGDIR=./ - -# where should tbext be installed? -# (leave blank to omit installation) -INSTDIR=${PD}/externs - -# where should the tbext help be installed? -# (leave blank to omit installation) -HELPDIR=${PD}/doc/5.reference - -# additional compiler flags -# (check whether they fit to your system!) -# UFLAGS=-mcpu=pentiumpro # gcc 2.95 -# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 -UFLAGS= -O3 -xW -tpp7 -ip -ipo #icc - - -FLEXTLIB=$(FLEXTPATH)/flext.a - -# compiler stuff -INCLUDES=$(PDINC) -FLAGS=-DFLEXT_SYS=2 -D__GNUG__ -CFLAGS=${UFLAGS} -O6 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions -LDFLAGS=$(CFLAGS) -LIBS=m - -# ---------------------------------------------- -# the rest can stay untouched -# ---------------------------------------------- - -NAME=tbext -SRCDIR=source - -include make-files.txt - -MAKEFILE=makefile -TARGET=$(TARGDIR)/$(NAME).pd_linux - -# default target -all: $(TARGDIR) $(TARGET) - -$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) - touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) - -$(TARGDIR): - -mkdir $(TARGDIR) - -$(TARGDIR)/%.o : $(SRCDIR)/%.cpp - $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ - -$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) - $(CXX) $(LDFLAGS) -shared $^ $(patsubst %,-l%,$(LIBS)) -o $@ - strip --strip-unneeded $@ - chmod 755 $@ - -$(INSTDIR): - -mkdir $(INSTDIR) - -install:: $(INSTDIR) - -install:: $(TARGET) - cp $^ $(INSTDIR) - chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) - -$(HELPDIR): - -mkdir $(HELPDIR) - -install-help:: $(HELPDIR) - -install-help:: ./pd - chmod 644 $^/*.* - cp $^/*.* $(HELPDIR) - - -.PHONY: clean -clean: - rm -f $(TARGDIR)/*.o $(TARGDIR)/*.il $(TARGET) - - - - - - - - - - - - diff --git a/tbext/makefile.pd-linux b/tbext/makefile.pd-linux new file mode 100644 index 0000000..25b7f3b --- /dev/null +++ b/tbext/makefile.pd-linux @@ -0,0 +1,92 @@ +# xsample - extended sample objects for Max/MSP and pd (pure data) +# Copyright (c) 2001-2003 Thomas Grill (xovo@gmx.net) +# +# Makefile for gcc @ linux +# +# usage: +# to build run "make -f makefile.pd-linux" +# to install (as root), do "make -f makefile.pd-linux install" +# + +CONFIG=config-pd-linux.txt + +include ${CONFIG} + +FLEXTLIB=$(FLEXTPATH)/flext.a + +# compiler stuff +INCLUDES=$(PDINC) +FLAGS=-DFLEXT_SYS=2 +CFLAGS=${UFLAGS} -O3 -I/usr/lib/flext -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions +LIBS=m + +ifdef FLEXT_SHARED +CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS +LDFLAGS+=-Bdynamic +LINKFLEXT=-lflext #-L/usr/lib/flext/libflext.so +else +LINKFLEXT=$(FLEXTLIB) +endif + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=tbext + +include make-files.txt + +MAKEFILE=makefile.pd-linux +TARGET=$(TARGDIR)/$(NAME).pd_linux + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) + $(CXX) $(LDFLAGS) -shared $^ $(patsubst %,-l%,$(LIBS)) -L$(FLEXTPATH) $(LINKFLEXT) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) + chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) + + + + + + + + + + + + diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index c4317fd..9cfbd24 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -54,10 +54,13 @@ void ttbext_setup() post(""); FLEXT_SETUP(tbroute); - FLEXT_SETUP(tbstrg); + //FLEXT_SETUP(tbstrg); FLEXT_DSP_SETUP(tbsroute); FLEXT_DSP_SETUP(tbsig); FLEXT_DSP_SETUP(tbpow); + // FLEXT_DSP_SETUP(tbg7xx); + FLEXT_DSP_SETUP(tbfft1); + } diff --git a/tbext/source/tbroute.cpp b/tbext/source/tbroute.cpp index 83d85a0..3218886 100644 --- a/tbext/source/tbroute.cpp +++ b/tbext/source/tbroute.cpp @@ -40,7 +40,6 @@ /* */ /* */ - #include #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) @@ -52,31 +51,32 @@ class tbroute: public flext_base FLEXT_HEADER(tbroute,flext_base); public: // constructor - tbroute(t_int chan); + tbroute(int chan); protected: void route(t_float f); void routebang(); - void set_route(t_int i); + void set_route(int i); private: FLEXT_CALLBACK_1(route,t_float); FLEXT_CALLBACK(routebang); - FLEXT_CALLBACK_1(set_route,t_int); - t_int dest; + FLEXT_CALLBACK_1(set_route,int); + + int dest; }; FLEXT_LIB_1("tbroute",tbroute,int); -tbroute::tbroute(t_int chan) +tbroute::tbroute(int chan) { AddInAnything(); AddInInt(); - for (t_int i=0; i!=chan;++i) + for (int i=0; i!=chan;++i) { AddOutAnything(); } @@ -98,7 +98,7 @@ void tbroute::routebang() ToOutBang(dest); } -void tbroute::set_route(t_int i) +void tbroute::set_route(int i) { --i; if ((i>-1) && (i-1) && (i Date: Sun, 7 Sep 2003 00:52:31 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=935 --- tbext/source/tbfft1.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tbext/source/tbfft1.cpp diff --git a/tbext/source/tbfft1.cpp b/tbext/source/tbfft1.cpp new file mode 100644 index 0000000..8bff178 --- /dev/null +++ b/tbext/source/tbfft1.cpp @@ -0,0 +1,134 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbfft1~ transforms the fft spectrum */ +/* */ +/* tbfft1~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: John Zorn / Mike Patton / Ikue Mori: Hemophiliac */ +/* Rashied Ali / Frank Lowe: Duo Exchange */ +/* Keith Rowe / John Tilbury: Duos For Doris */ +/* */ + + + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + + +class tbfft1: public flext_dsp +{ + FLEXT_HEADER(tbfft1,flext_dsp); + +public: // constructor + tbfft1(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_freq(t_float); + void set_fact(t_float); + +private: + FLEXT_CALLBACK_1(set_freq,t_float) + FLEXT_CALLBACK_1(set_fact,t_float) + + t_int center; + t_float factor; + + t_float pos; + t_int posi; + + float *ins; + float *outs; + + t_float s; + t_float b; + + +}; + + +FLEXT_LIB_DSP("tbfft1~",tbfft1) + +tbfft1::tbfft1() +{ + AddInSignal(); + AddOutSignal(); + FLEXT_ADDMETHOD_F(0,"center",set_freq); + FLEXT_ADDMETHOD_F(0,"factor",set_fact); +} + + +void tbfft1::m_signal(int n, t_float *const *in, t_float *const *out) +{ + ins = in[0]; + outs = out[0]; + + n=n/2+1; + while(n!=0) + { + pos= n + factor * (center-n); + posi=t_int(pos); + + + if (n < t_int(center)) + { + *(outs+n) = ((pos-t_float(posi)) * (*(ins+posi)))/2 + +((1-pos+t_float(posi)) * (*(ins+posi+1)))/2; + } + else + { + *(outs+n) = ((pos-t_float(posi)) * (*(ins+posi-1)))/2 + +((1-pos+t_float(posi)) * (*(ins+posi)))/2; + } + + --n; + } + + +} + +void tbfft1::set_freq(t_float freq) +{ + s=Samplerate(); + + b=Blocksize(); + + center=freq/(s/b); + post("%i",int(center)); +} + + +void tbfft1::set_fact(t_float f) +{ + factor=f; +} -- cgit v1.2.1 From 12c9210a8592cf46616d453dda02f5ea56c44cc4 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 8 Sep 2003 21:49:34 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=946 --- tbext/source/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index 9cfbd24..e8bf9e3 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -40,7 +40,7 @@ #include -#define TBEXT_VERSION "0.01" +#define TBEXT_VERSION "0.02" #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) #error upgrade your flext version!!!!!! -- cgit v1.2.1 From 5cc947f46350f347575cc61df0e3c07c6458542b Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 14 Sep 2003 16:38:25 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=962 --- tbext/source/tbfft1.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tbext/source/tbfft1.cpp b/tbext/source/tbfft1.cpp index 8bff178..e941bfd 100644 --- a/tbext/source/tbfft1.cpp +++ b/tbext/source/tbfft1.cpp @@ -124,11 +124,11 @@ void tbfft1::set_freq(t_float freq) b=Blocksize(); center=freq/(s/b); - post("%i",int(center)); } void tbfft1::set_fact(t_float f) { - factor=f; + if (f<2) + factor=f; } -- cgit v1.2.1 From 533c8ad7244dce612aa821e9b18c282c42fa0f37 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 14 Sep 2003 16:41:01 +0000 Subject: Added tbfft2 svn path=/trunk/externals/tb/; revision=963 --- tbext/source/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index e8bf9e3..c64c2fc 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -56,11 +56,13 @@ void ttbext_setup() FLEXT_SETUP(tbroute); //FLEXT_SETUP(tbstrg); FLEXT_DSP_SETUP(tbsroute); + // FLEXT_SETUP(tblock); FLEXT_DSP_SETUP(tbsig); FLEXT_DSP_SETUP(tbpow); // FLEXT_DSP_SETUP(tbg7xx); FLEXT_DSP_SETUP(tbfft1); - + FLEXT_DSP_SETUP(tbfft2); + // FLEXT_DSP_SETUP(fftbuf); } -- cgit v1.2.1 From 7ee4655a5bd0324808cb851a54e0d4cc402c9ada Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 14 Sep 2003 16:45:54 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=964 --- tbext/make-files.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tbext/make-files.txt b/tbext/make-files.txt index ba3fe55..7816e3c 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -1,7 +1,7 @@ # all the source files from the package SRCDIR = source SRCS= \ - main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp tbfft1.cpp # tbg7xx.cpp tbstrg.cpp + main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp tbfft1.cpp tbfft2.cpp #fftbuf.cpp # tbg7xx.cpp tbstrg.cpp #HDRS= \ -- cgit v1.2.1 From e06c0dcda335f4c6009750c9cf9366e7c2e72fe8 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 15 Sep 2003 04:49:59 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=966 --- tbext/make-files.txt | 2 +- tbext/source/main.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tbext/make-files.txt b/tbext/make-files.txt index 7816e3c..846ab54 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -1,7 +1,7 @@ # all the source files from the package SRCDIR = source SRCS= \ - main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp tbfft1.cpp tbfft2.cpp #fftbuf.cpp # tbg7xx.cpp tbstrg.cpp + main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp # tbg7xx.cpp tbstrg.cpp #HDRS= \ diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index c64c2fc..1cb0992 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -56,13 +56,12 @@ void ttbext_setup() FLEXT_SETUP(tbroute); //FLEXT_SETUP(tbstrg); FLEXT_DSP_SETUP(tbsroute); - // FLEXT_SETUP(tblock); FLEXT_DSP_SETUP(tbsig); FLEXT_DSP_SETUP(tbpow); // FLEXT_DSP_SETUP(tbg7xx); FLEXT_DSP_SETUP(tbfft1); FLEXT_DSP_SETUP(tbfft2); - // FLEXT_DSP_SETUP(fftbuf); + FLEXT_DSP_SETUP(fftbuf); } -- cgit v1.2.1 From f4c793955cb1170ff0fa0a2e30a8b619ee582325 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 18 Sep 2003 05:04:12 +0000 Subject: Some spectral processors have been added svn path=/trunk/externals/tb/; revision=1007 --- tbext/source/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index 1cb0992..bd6d833 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -40,7 +40,7 @@ #include -#define TBEXT_VERSION "0.02" +#define TBEXT_VERSION "0.03" #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) #error upgrade your flext version!!!!!! @@ -62,7 +62,9 @@ void ttbext_setup() FLEXT_DSP_SETUP(tbfft1); FLEXT_DSP_SETUP(tbfft2); FLEXT_DSP_SETUP(fftbuf); - + FLEXT_DSP_SETUP(fftgrsort); + FLEXT_DSP_SETUP(fftgrshuf); + FLEXT_DSP_SETUP(fftgrrev); } FLEXT_LIB_SETUP(tbext,ttbext_setup) -- cgit v1.2.1 From b2f05c9b120dc9a6578a06053207bd567254ce36 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 18 Sep 2003 05:05:30 +0000 Subject: some spectral processors have been added svn path=/trunk/externals/tb/; revision=1008 --- tbext/make-files.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tbext/make-files.txt b/tbext/make-files.txt index 846ab54..273787a 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -1,7 +1,9 @@ # all the source files from the package SRCDIR = source SRCS= \ - main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp # tbg7xx.cpp tbstrg.cpp + main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp \ + tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp fftgrshuf.cpp \ + fftgrrev.cpp # tbg7xx.cpp tbstrg.cpp #HDRS= \ -- cgit v1.2.1 From 81d751e8824f6a9b3975c1da517d1d163a2eace5 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 20 Sep 2003 00:05:08 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1012 --- tbext/bufline~.pd | 56 ++++++++++ tbext/config-pd-linux.txt | 6 +- tbext/make-files.txt | 6 +- tbext/makefile.pd-linux | 2 +- tbext/reverse.pd | 49 +++++++++ tbext/shuf.pd | 49 +++++++++ tbext/sort.pd | 51 ++++++++++ tbext/source/fftbuf.cpp | 247 +++++++++++++++++++++++++++++++++++++++++++++ tbext/source/fftgrrev.cpp | 165 ++++++++++++++++++++++++++++++ tbext/source/fftgrshuf.cpp | 161 +++++++++++++++++++++++++++++ tbext/source/fftgrsort.cpp | 176 ++++++++++++++++++++++++++++++++ tbext/source/main.cpp | 1 + tbext/source/tbfft2.cpp | 147 +++++++++++++++++++++++++++ tbext/tbfft1.pd | 44 ++++++++ tbext/tbfft2.pd | 50 +++++++++ 15 files changed, 1203 insertions(+), 7 deletions(-) create mode 100644 tbext/bufline~.pd create mode 100644 tbext/reverse.pd create mode 100644 tbext/shuf.pd create mode 100644 tbext/sort.pd create mode 100644 tbext/source/fftbuf.cpp create mode 100644 tbext/source/fftgrrev.cpp create mode 100644 tbext/source/fftgrshuf.cpp create mode 100644 tbext/source/fftgrsort.cpp create mode 100644 tbext/source/tbfft2.cpp create mode 100644 tbext/tbfft1.pd create mode 100644 tbext/tbfft2.pd diff --git a/tbext/bufline~.pd b/tbext/bufline~.pd new file mode 100644 index 0000000..7fd7d59 --- /dev/null +++ b/tbext/bufline~.pd @@ -0,0 +1,56 @@ +#N canvas 221 141 714 505 10; +#N canvas 0 0 450 300 graph1 0; +#X array from1 64 float 1; +#A 0 0 0 0 0 0 0 0.0285714 0.0357143 0.0428571 0.0714286 0.0857143 +0.114286 0.128571 0.142857 0.142857 0.157143 0.171429 0.185714 0.2 +0.214286 0.242857 0.242857 0.242857 0.242857 0.242857 0.214286 0.2 +0.15 0.0714286 0.0714286 1.86265e-09 -0.0142857 -0.0285714 0 0 0 0 +0 0 0 0 -0.0142857 -0.0285714 -0.0428571 -0.0571429 -0.0571429 -0.0571429 +-0.0571429 -0.0571429 -0.0571429 -0.0571429 0.00714286 0.0714286 0.142857 +0.242857 0.314286 0.457143 0 0 0 0 0 0 0; +#X coords 0 1 63 -1 200 140 1; +#X restore 80 20 graph; +#X obj 607 14 block~ 128; +#N canvas 0 0 450 300 graph1 0; +#X array from2 64 float 1; +#A 0 0 0 0 0 0 0 0 0 0 0.0285714 0.0571429 0.0761905 0.0952381 0.114286 +0.12381 0.133333 0.142857 0.2 0.207143 0.228571 0.228571 0.257143 0.257143 +0.257143 0.242857 -0.0142857 0 0 0 0 0 0 0 0 0 -0.471429 -0.628572 +-0.685714 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; +#X coords 0 1 63 -1 200 140 1; +#X restore 335 23 graph; +#N canvas 0 0 450 300 graph1 0; +#X array to 64 float 1; +#A 0 0 0 0 0 0 0 0.00682475 0.00853045 0.0102368 0.0388103 0.0639679 +0.0852809 0.10321 0.121109 0.128353 0.139015 0.149682 0.196567 0.205455 +0.225179 0.232002 0.253755 0.253755 0.253755 0.242854 0.0403107 0.047774 +0.0358276 0.0170609 0.0170609 4.44924e-10 -0.00341237 -0.00682475 0 +0 -0.35882 -0.478471 -0.521873 0 0 0 -0.00341233 -0.00682466 -0.0102368 +-0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.0136493 +0.00170617 0.0170609 0.0341218 0.0580107 0.0750683 0.109195 0 0 0 0 +0 0 0; +#X coords 0 1 63 -1 200 140 1; +#X restore 456 301 graph; +#X obj 144 412 tabwrite~ to; +#X obj 208 373 metro 50; +#X obj 208 349 loadbang; +#X obj 83 280 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 212 269 set from1; +#X msg 212 292 set from2; +#X msg 133 271 line 5000; +#X obj 63 385 print~; +#X obj 26 332 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 88 321 bufline~ 128; +#X msg 119 239 line 400; +#X connect 5 0 4 0; +#X connect 6 0 5 0; +#X connect 7 0 13 0; +#X connect 8 0 13 0; +#X connect 9 0 13 0; +#X connect 10 0 13 0; +#X connect 12 0 11 0; +#X connect 13 0 11 0; +#X connect 13 0 4 0; +#X connect 14 0 13 0; diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt index e1fa248..495aad9 100755 --- a/tbext/config-pd-linux.txt +++ b/tbext/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for tbext, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) - CXX=icc +# CXX=icc # where does the PD installation reside? @@ -10,7 +10,7 @@ PD=/usr/lib/pd # where are the PD header files? # leave it blank if it is a system directory (like /usr/local/include), # since gcc 3.2 complains about it -PDINC=/home/tim/pd/devel_0_36/pd/src +PDINC=/home/tim/pd/pd-0.37-0/src # where do the flext libraries reside? FLEXTPATH=/usr/lib/flext @@ -28,7 +28,7 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) -UFLAGS=-xW -tpp7 -ip -ipo_obj -g # icc +#UFLAGS=-xW -tpp7 -ip -ipo_obj -g # icc # UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) diff --git a/tbext/make-files.txt b/tbext/make-files.txt index 273787a..e299154 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -1,9 +1,9 @@ # all the source files from the package SRCDIR = source SRCS= \ - main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbpow~.cpp \ - tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp fftgrshuf.cpp \ - fftgrrev.cpp # tbg7xx.cpp tbstrg.cpp + main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbssel~.cpp \ + tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp \ + fftgrshuf.cpp fftgrrev.cpp # tbg7xx.cpp tbstrg.cpp #HDRS= \ diff --git a/tbext/makefile.pd-linux b/tbext/makefile.pd-linux index 25b7f3b..7948a19 100644 --- a/tbext/makefile.pd-linux +++ b/tbext/makefile.pd-linux @@ -17,7 +17,7 @@ FLEXTLIB=$(FLEXTPATH)/flext.a # compiler stuff INCLUDES=$(PDINC) FLAGS=-DFLEXT_SYS=2 -CFLAGS=${UFLAGS} -O3 -I/usr/lib/flext -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions +CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions LIBS=m ifdef FLEXT_SHARED diff --git a/tbext/reverse.pd b/tbext/reverse.pd new file mode 100644 index 0000000..34ac6d4 --- /dev/null +++ b/tbext/reverse.pd @@ -0,0 +1,49 @@ +#N canvas 245 106 453 369 10; +#N canvas 0 0 450 300 graph2 0; +#X array array1 63 float 1; +#A 0 0 0 0 0 0 0 0 0 -0.0142857 -0.0428571 -0.0714286 -0.0857143 -0.128571 +-0.214286 -0.285714 -0.357143 -0.4 -0.428571 -0.428571 -0.428571 -0.428571 +-0.428571 -0.414286 -0.414286 -0.4 -0.371429 -0.328571 -0.328571 -0.314286 +-0.3 -0.271429 -0.242857 -0.228571 -0.214286 -0.157143 -0.128571 -0.0714286 +-0.0571429 -0.0285715 0.0571428 0.1 0.128571 0.135714 0.142857 0.171429 +0.214286 0.228571 0.242857 0.271429 0.271429 0.3 0.3 -0.0571429 -0.0857143 +0.0214285 0.0285714 0.0571428 0.0714285 0.0714285 0.057143 0.0428573 +0.0428573 0; +#X coords 0 1 62 -1 200 140 1; +#X restore -67 3 graph; +#N canvas 0 0 450 300 graph3 0; +#X array array2 64 float 1; +#A 0 0 0 0 0 0 0 0 0 -0.0142857 -0.0428571 -0.0714286 -0.0857143 -0.128571 +-0.214286 -0.285714 -0.357143 -0.4 -0.428571 -0.428571 -0.428571 -0.428571 +-0.414286 -0.428571 -0.4 -0.414286 -0.328571 -0.371429 -0.314286 -0.328571 +-0.271429 -0.3 -0.228571 -0.242857 -0.157143 -0.214286 -0.0714286 -0.128571 +-0.0285715 -0.0571429 0.1 0.0571428 0.135714 0.128571 0.3 0.3 0.271429 +0.271429 0.242857 0.228571 0.214286 0.171429 0.142857 0.0714285 0.0714285 +0.057143 0.0571428 0.0428573 0.0428573 0.0285714 0.0214285 0 0 0 -0.0571429 +; +#X coords 0 1 63 -1 200 140 1; +#X restore 159 1 graph; +#X obj 30 234 tabplay~ array1; +#X obj -28 270 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 30 323 tabwrite~ array2; +#X floatatom 229 240 5 0 0 0 - - -; +#X obj -68 307 metro 50; +#X obj -81 275 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 267 183 block~ 128; +#X msg 229 259 grains \$1; +#X obj 209 291 hsl 128 15 -64 64 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X msg 206 315 offset \$1; +#X obj 29 276 fftgrrev~ 128; +#X connect 2 0 12 0; +#X connect 3 0 2 0; +#X connect 3 0 4 0; +#X connect 5 0 9 0; +#X connect 6 0 3 0; +#X connect 7 0 6 0; +#X connect 9 0 12 0; +#X connect 10 0 11 0; +#X connect 11 0 12 0; +#X connect 12 0 4 0; diff --git a/tbext/shuf.pd b/tbext/shuf.pd new file mode 100644 index 0000000..1144ffe --- /dev/null +++ b/tbext/shuf.pd @@ -0,0 +1,49 @@ +#N canvas 245 106 453 369 10; +#N canvas 0 0 450 300 graph2 0; +#X array array1 63 float 1; +#A 0 0 0 0 0 0 0 0 0 -0.0142857 -0.0428571 -0.0714286 -0.0857143 -0.128571 +-0.214286 -0.285714 -0.357143 -0.4 -0.428571 -0.428571 -0.428571 -0.428571 +-0.428571 -0.414286 -0.414286 -0.4 -0.371429 -0.328571 -0.328571 -0.314286 +-0.3 -0.271429 -0.242857 -0.228571 -0.214286 -0.157143 -0.128571 -0.0714286 +-0.0571429 -0.0285715 0.0571428 0.1 0.128571 0.135714 0.142857 0.171429 +0.214286 0.228571 0.242857 0.271429 0.271429 0.3 0.3 -0.0571429 -0.0857143 +0.0214285 0.0285714 0.0571428 0.0714285 0.0714285 0.057143 0.0428573 +0.0428573 0; +#X coords 0 1 62 -1 200 140 1; +#X restore -67 3 graph; +#N canvas 0 0 450 300 graph3 0; +#X array array2 64 float 1; +#A 0 0 0.0214285 -0.371429 -0.0571429 -0.0857143 0.128571 0.0571428 +0.0285714 0 0.0714285 -0.314286 0.0571428 -0.128571 -0.428571 -0.214286 +0.1 -0.328571 -0.271429 -0.428571 0 0.142857 -0.157143 0.228571 0 -0.128571 +-0.428571 0 -0.228571 0 0.0428573 0 -0.0714286 -0.428571 -0.414286 +0.271429 0.057143 -0.328571 0.0714285 -0.0285715 -0.428571 -0.0142857 +-0.242857 -0.285714 -0.0714286 0.242857 -0.4 -0.3 -0.0857143 0.3 0.214286 +-0.0428571 -0.414286 0.135714 0.3 -0.214286 -0.357143 -0.0571429 0 +0 0.171429 0 0.0428573 0.271429 -0.4; +#X coords 0 1 63 -1 200 140 1; +#X restore 159 1 graph; +#X obj 30 234 tabplay~ array1; +#X obj -28 270 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 30 323 tabwrite~ array2; +#X floatatom 229 240 5 0 0 0 - - -; +#X obj -68 307 metro 50; +#X obj -81 275 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 267 183 block~ 128; +#X msg 229 259 grains \$1; +#X obj 209 291 hsl 128 15 -64 64 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 1; +#X msg 206 315 offset \$1; +#X obj 29 276 fftgrshuf~ 128; +#X connect 2 0 12 0; +#X connect 3 0 2 0; +#X connect 3 0 4 0; +#X connect 5 0 9 0; +#X connect 6 0 3 0; +#X connect 7 0 6 0; +#X connect 9 0 12 0; +#X connect 10 0 11 0; +#X connect 11 0 12 0; +#X connect 12 0 4 0; diff --git a/tbext/sort.pd b/tbext/sort.pd new file mode 100644 index 0000000..482cf31 --- /dev/null +++ b/tbext/sort.pd @@ -0,0 +1,51 @@ +#N canvas 245 106 453 369 10; +#N canvas 0 0 450 300 graph2 0; +#X array array1 63 float 1; +#A 0 0 0 0 0 0 0 0 0 -0.0142857 -0.0428571 -0.0714286 -0.0857143 -0.128571 +-0.214286 -0.285714 -0.357143 -0.4 -0.428571 -0.428571 -0.428571 -0.428571 +-0.428571 -0.414286 -0.414286 -0.4 -0.371429 -0.328571 -0.328571 -0.314286 +-0.3 -0.271429 -0.242857 -0.228571 -0.214286 -0.157143 -0.128571 -0.0714286 +-0.0571429 -0.0285715 0.0571428 0.1 0.128571 0.135714 0.142857 0.171429 +0.214286 0.228571 0.242857 0.271429 0.271429 0.3 0.3 -0.0571429 -0.0857143 +0.0214285 0.0285714 0.0571428 0.0714285 0.0714285 0.057143 0.0428573 +0.0428573 0; +#X coords 0 1 62 -1 200 140 1; +#X restore -67 3 graph; +#N canvas 0 0 450 300 graph3 0; +#X array array2 64 float 1; +#A 0 0 0 0 0 0 0 0 0 -0.0142857 -0.0428571 -0.0714286 -0.0857143 -0.128571 +-0.214286 -0.285714 -0.357143 -0.4 -0.428571 -0.428571 -0.428571 -0.428571 +-0.414286 -0.428571 -0.4 -0.414286 -0.328571 -0.371429 -0.314286 -0.328571 +-0.271429 -0.3 -0.228571 -0.242857 -0.157143 -0.214286 -0.0714286 -0.128571 +-0.0285715 -0.0571429 0.1 0.0571428 0.135714 0.128571 0.3 0.3 0.271429 +0.271429 0.242857 0.228571 0.214286 0.171429 0.142857 0.0714285 0.0714285 +0.057143 0.0571428 0.0428573 0.0428573 0.0285714 0.0214285 0 0 0 -0.0571429 +; +#X coords 0 1 63 -1 200 140 1; +#X restore 159 1 graph; +#X obj 30 234 tabplay~ array1; +#X obj -28 270 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 30 323 tabwrite~ array2; +#X floatatom 229 240 5 0 0 0 - - -; +#X obj -68 307 metro 50; +#X obj -81 275 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 267 183 block~ 128; +#X msg 229 259 grains \$1; +#X obj 209 291 hsl 128 15 -64 64 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 6300 1; +#X msg 206 315 offset \$1; +#X obj 29 276 fftgrsort~ 128; +#X msg 168 203 reverse; +#X connect 2 0 12 0; +#X connect 3 0 2 0; +#X connect 3 0 4 0; +#X connect 5 0 9 0; +#X connect 6 0 3 0; +#X connect 7 0 6 0; +#X connect 9 0 12 0; +#X connect 10 0 11 0; +#X connect 11 0 12 0; +#X connect 12 0 4 0; +#X connect 13 0 12 0; diff --git a/tbext/source/fftbuf.cpp b/tbext/source/fftbuf.cpp new file mode 100644 index 0000000..eff81e3 --- /dev/null +++ b/tbext/source/fftbuf.cpp @@ -0,0 +1,247 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* fftbuf~ fades between two buffers. it is intended to be used as fft */ +/* synthesis tool... */ +/* */ +/* */ +/* fftbuf~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Jérôme Noetinger/ErikM: What a Wonderful World */ +/* Cosmos: Tears */ +/* Burkhard Stangl/Dieb13: eh */ +/* */ + + + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + + +class fftbuf: public flext_dsp +{ + FLEXT_HEADER(fftbuf,flext_dsp); + +public: // constructor + + fftbuf(int); + ~fftbuf(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + bool check(buffer *); + + + void set_buf(int argc, t_atom *argv); //selects a new buffer + void set_line(int argc, t_atom *argv); //sets the time for the transformance + + template + void clear(T *); //destroys an object + + void perform(); //starts transformation + + int blknumber(); //number of blocks that a performance needs + +private: + FLEXT_CALLBACK_V(set_buf); + FLEXT_CALLBACK_V(set_line); + FLEXT_CALLBACK(perform); + + float *ins; + float *outs; + + t_symbol * bufname; + buffer * buf; + + int delay; //delay for fading from local buffer to new one + t_sample * data; // pointer to array of samples + t_sample * offset; // pointer to array of samples + + int bs; //blocksize+1 + int sr; //samplerate + int counter; +}; + + +FLEXT_LIB_DSP_1("bufline~",fftbuf,int); + +fftbuf::fftbuf(int arg): + buf(NULL),data(NULL),sr(Samplerate()),delay(0),counter(0) +{ + bs=arg+1; + AddInAnything(); + AddOutSignal(); + FLEXT_ADDMETHOD_(0,"set",set_buf); + FLEXT_ADDMETHOD_(0,"line",set_line); + FLEXT_ADDBANG(0,perform); + + + data= new t_sample[bs]; + offset= new t_sample[bs]; + ZeroSamples(data,bs); + ZeroSamples(offset,bs); +} + + +fftbuf::~fftbuf() +{ + delete data; + delete offset; +} + + +void fftbuf::m_signal(int n, t_float *const *in, t_float *const *out) +{ + outs = out[0]; + + if (counter!=0) + { + n=n/2+1; + while (--n) + data[n] = data[n] - offset[n]; + + + /* for(int i=0;i!=bs;++i) + { + data[i] = data[i] - offset[i]; + } + */ + + --counter; + } + + CopySamples(out[0],data,bs); +} + +void fftbuf::perform() +{ + counter=blknumber(); + if (counter) + { + for(int i=0;i!=bs;++i) + { + offset[i]=(data[i]-*(buf->Data()+i))/counter; + } + + } + else + { + CopySamples(data,buf->Data(),bs); + } +} + +void fftbuf::set_buf(int argc, t_atom *argv) +{ + if(argc == 0) + { + post("No buffer selected!!!"); + return; + } + if (argc == 1 && IsSymbol(argv[0])) + { + clear(buf); + bufname=GetSymbol(argv[0]); + + buf= new buffer(bufname); + + if(!buf->Ok()) + { + post("buffer %s is currently not valid",bufname); + } + } + else if ((argc == 2 && IsSymbol(argv[0]) && + (IsInt(argv[1]) || IsFloat(argv[1])))) + { + clear(buf); + bufname=GetSymbol(argv[0]); + + buf= new buffer(bufname); + + if(!buf->Ok()) + { + post("buffer %s is currently not valid",bufname); + return; + } + delay=GetInt(argv[1]); + } +} + +template +/*inline*/ void fftbuf::clear(T* buf) +{ + if (buf) + { + delete buf; + buf=NULL; + } +} + +inline bool fftbuf::check(buffer * buf) +{ +//code taken from the flext tutorial (buffer 1) by thomas grill + + if(buf->Update()) + { + // buffer parameters have been updated + if(buf->Valid()) + { + post("%s (%s) - updated buffer reference", + thisName(),GetString(thisTag())); + return true; + } + else + { + post("%s (%s) - buffer has become invalid", + thisName(),GetString(thisTag())); + return false; + } + } + else + return true; +} + +void fftbuf::set_line(int argc, t_atom *argv) +{ + if(argc==1 && (IsInt(argv[0]) || IsFloat(argv[0]))) + { + delay=GetInt(argv[0]); + } + else + post("syntax incorrect"); +} + +inline int fftbuf::blknumber() +{ + // post("%i %i %i",delay,bs,sr); + // post("computer counter: %i",delay*bs/sr*1000); + return delay*bs/sr*1000; //ms/sample +} diff --git a/tbext/source/fftgrrev.cpp b/tbext/source/fftgrrev.cpp new file mode 100644 index 0000000..e26135c --- /dev/null +++ b/tbext/source/fftgrrev.cpp @@ -0,0 +1,165 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* fftgrshuf divides the incoming fft signal into single grains and reverses */ +/* the samples in every grain */ +/* */ +/* fftgrrev uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Howard Skempton/John Tilbury: Well, well, Cornelius*/ +/* */ +/* */ + + + +#include +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class fftgrrev: public flext_dsp +{ + FLEXT_HEADER(fftgrrev,flext_dsp); + +public: // constructor + fftgrrev(int); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_grains(t_int); + void set_offset(t_int); + void set_reverse(); + +private: + FLEXT_CALLBACK_1(set_grains,t_int) + FLEXT_CALLBACK_1(set_offset,t_int) + + t_int grains; + t_int grainsize; + t_int offset; + + t_int bs; //blocksize + t_int bs1; //bs+1 + t_int counter; + + t_sample * data; //array with data + t_sample * d1; //1. element in array with data + t_sample * dend; //1 element after the last element + + t_sample * ins; + t_sample * outs; + + bool reverse; + +}; + + +FLEXT_LIB_DSP_1("fftgrrev~",fftgrrev,int) + +fftgrrev::fftgrrev(int arg): + grains(1),offset(0),counter(1) +{ + bs=arg/2; + grainsize=bs; + bs1=bs+1; + post("blocksize: %i",bs); + + data = new t_sample[bs+1]; + + data[0]=0; + d1=data+1; + dend=data+bs+1; + + AddInSignal(); + AddOutSignal(); + FLEXT_ADDMETHOD_I(0,"grains",set_grains); + FLEXT_ADDMETHOD_I(0,"offset",set_offset); +} + +void fftgrrev::m_signal(int n, t_float * const *in, t_float *const *out) +{ + ins = in[0]; + outs = out[0]; + + + if (offset>0) + { + CopySamples(d1+bs-offset,ins,offset); + CopySamples(d1,ins+offset,bs-offset); + } + else if (offset<0) + { + CopySamples(d1-offset,ins,bs+offset); + CopySamples(d1,ins+bs+offset,-offset); + } + else + CopySamples(data,ins,bs1); + + + //grains + + counter=1; + + while (counter!=grains) + { + std::reverse(d1+grainsize*(counter-1),d1+grainsize*counter); + ++counter; + } + + std::reverse(d1+grainsize*(counter-1),dend); + + CopySamples(outs,data,bs1); +} + +void fftgrrev::set_offset(t_int o) +{ + if (o-bs<0 && o+bs>0) + { + offset=-o; + post("offset %i",o); + } + else + post("Offset out of range!"); +} + + +void fftgrrev::set_grains(t_int g) +{ + if ( (g > 0) ) + { + grains=g; + grainsize=(bs)/grains; + } +} + + + + diff --git a/tbext/source/fftgrshuf.cpp b/tbext/source/fftgrshuf.cpp new file mode 100644 index 0000000..b490dcf --- /dev/null +++ b/tbext/source/fftgrshuf.cpp @@ -0,0 +1,161 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* fftgrshuf divides the incoming fft signal into single grains and */ +/* random_shuffles the samples in every grain */ +/* */ +/* fftgrshuf uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: New York Underground Orchestra: The Labyrinth */ +/* */ +/* */ + + + +#include +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class fftgrshuf: public flext_dsp +{ + FLEXT_HEADER(fftgrshuf,flext_dsp); + +public: // constructor + fftgrshuf(int); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_grains(t_int); + void set_offset(t_int); + +private: + FLEXT_CALLBACK_1(set_grains,t_int) + FLEXT_CALLBACK_1(set_offset,t_int) + + t_int grains; + t_int grainsize; + t_int offset; + + t_int bs; //blocksize + t_int bs1; //bs+1 + t_int counter; + + t_sample * data; //array with data + t_sample * d1; //1. element in array with data + t_sample * dend; //1 element after the last element + + t_sample * ins; + t_sample * outs; + + +}; + + +FLEXT_LIB_DSP_1("fftgrshuf~",fftgrshuf,int) + +fftgrshuf::fftgrshuf(int arg): + grains(1),offset(0),counter(1) +{ + bs=arg/2; + grainsize=bs; + bs1=bs+1; + post("blocksize: %i",bs); + + data = new t_sample[bs+1]; + + data[0]=0; + d1=data+1; + dend=data+bs+1; + + AddInSignal(); + AddOutSignal(); + FLEXT_ADDMETHOD_I(0,"grains",set_grains); + FLEXT_ADDMETHOD_I(0,"offset",set_offset); +} + +void fftgrshuf::m_signal(int n, t_float * const *in, t_float *const *out) +{ + ins = in[0]; + outs = out[0]; + + + if (offset>0) + { + CopySamples(d1+bs-offset,ins,offset); + CopySamples(d1,ins+offset,bs-offset); + } + else if (offset<0) + { + CopySamples(d1-offset,ins,bs+offset); + CopySamples(d1,ins+bs+offset,-offset); + } + else + CopySamples(data,ins,bs1); + + + //grains + + counter=1; + + while (counter!=grains) + { + std::random_shuffle(d1+grainsize*(counter-1),d1+grainsize*counter); + ++counter; + } + + std::random_shuffle(d1+grainsize*(counter-1),dend); + + + CopySamples(outs,data,bs1); +} + +void fftgrshuf::set_offset(t_int o) +{ + if (o-bs<0 && o+bs>0) + { + offset=o; + post("offset %i",-o); + } + else + post("offset out of range!"); +} + + +void fftgrshuf::set_grains(t_int g) +{ + if ( (g > 0) ) + { + grains=g; + grainsize=(bs)/grains; + } +} + diff --git a/tbext/source/fftgrsort.cpp b/tbext/source/fftgrsort.cpp new file mode 100644 index 0000000..f24ed0f --- /dev/null +++ b/tbext/source/fftgrsort.cpp @@ -0,0 +1,176 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* fftgrsort divides the incoming fft signal into single grains and sorts the */ +/* samples in every grain */ +/* */ +/* fftgrsort uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: William Parker: Posium Pendasem */ +/* Rowe/Lehn/Schmickler: Rabbit Run */ +/* Derek Bailey: Ballads */ +/* */ + + + +#include +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class fftgrsort: public flext_dsp +{ + FLEXT_HEADER(fftgrsort,flext_dsp); + +public: // constructor + fftgrsort(int); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_grains(t_int); + void set_offset(t_int); + void set_reverse(); + +private: + FLEXT_CALLBACK_1(set_grains,t_int) + FLEXT_CALLBACK_1(set_offset,t_int) + FLEXT_CALLBACK(set_reverse) + + t_int grains; + t_int grainsize; + t_int offset; + + t_int bs; //blocksize + t_int bs1; //bs+1 + t_int counter; + + t_sample * data; //array with data + t_sample * d1; //1. element in array with data + t_sample * dend; //1 element after the last element + + t_sample * ins; + t_sample * outs; + + bool reverse; + +}; + + +FLEXT_LIB_DSP_1("fftgrsort~",fftgrsort,int) + +fftgrsort::fftgrsort(int arg): + grains(1),offset(0),counter(1),reverse(0) +{ + bs=arg/2; + grainsize=bs; + bs1=bs+1; + post("blocksize: %i",bs); + + data = new t_sample[bs+1]; + + data[0]=0; + d1=data+1; + dend=data+bs+1; + + AddInSignal(); + AddOutSignal(); + FLEXT_ADDMETHOD_I(0,"grains",set_grains); + FLEXT_ADDMETHOD_I(0,"offset",set_offset); + FLEXT_ADDMETHOD_(0,"reverse",set_reverse); +} + +void fftgrsort::m_signal(int n, t_float * const *in, t_float *const *out) +{ + ins = in[0]; + outs = out[0]; + + + if (offset>0) + { + CopySamples(d1+bs-offset,ins,offset); + CopySamples(d1,ins+offset,bs-offset); + } + else if (offset<0) + { + CopySamples(d1-offset,ins,bs+offset); + CopySamples(d1,ins+bs+offset,-offset); + } + else + CopySamples(data,ins,bs1); + + + //grains + + counter=1; + + while (counter!=grains) + { + std::sort(d1+grainsize*(counter-1),d1+grainsize*counter); + if (reverse) + std::reverse(d1+grainsize*(counter-1),d1+grainsize*counter); + ++counter; + } + + std::sort(d1+grainsize*(counter-1),dend); + if (reverse) + std::reverse(d1+grainsize*(counter-1),dend); + + + CopySamples(outs,data,bs1); +} + +void fftgrsort::set_offset(t_int o) +{ + if (o-bs<0 && o+bs>0) + { + offset=-o; + post("offset %i",o); + } + else + post("offset out of range!"); +} + + +void fftgrsort::set_grains(t_int g) +{ + if ( (g > 0) ) + { + grains=g; + grainsize=(bs)/grains; + } +} + +void fftgrsort::set_reverse() +{ + reverse=!reverse; +} + + diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index bd6d833..4b204f6 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -56,6 +56,7 @@ void ttbext_setup() FLEXT_SETUP(tbroute); //FLEXT_SETUP(tbstrg); FLEXT_DSP_SETUP(tbsroute); + FLEXT_DSP_SETUP(tbssel); FLEXT_DSP_SETUP(tbsig); FLEXT_DSP_SETUP(tbpow); // FLEXT_DSP_SETUP(tbg7xx); diff --git a/tbext/source/tbfft2.cpp b/tbext/source/tbfft2.cpp new file mode 100644 index 0000000..6ed71d9 --- /dev/null +++ b/tbext/source/tbfft2.cpp @@ -0,0 +1,147 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbfft2~ transforms the fft spectrum. it reverses the order of the samples in */ +/* the fft spectrum. see the help file for further instruction... */ +/* */ +/* */ +/* tbfft2~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Naked City: Heretic, Jeux Des Dames Cruelles */ +/* Bob Ostertag: Attention Span */ +/* */ +/* */ + + + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + + +class tbfft2: public flext_dsp +{ + FLEXT_HEADER(tbfft2,flext_dsp); + +public: // constructor + tbfft2(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_freq(t_float); + void set_width(t_float); + +private: + FLEXT_CALLBACK_1(set_freq,t_float) + FLEXT_CALLBACK_1(set_width,t_float) + + t_int center; + t_int width; + + t_float pos; + t_int posi; + + float *ins; + float *outs; + float *tmps; + t_float tmp[2049]; + + t_float s; + t_float b; + + t_int n0; +}; + + +FLEXT_LIB_DSP("tbfft2~",tbfft2) + +tbfft2::tbfft2() +{ + AddInSignal(); + AddOutSignal(); + FLEXT_ADDMETHOD_F(0,"center",set_freq); + FLEXT_ADDMETHOD_F(0,"width",set_width); +} + + +void tbfft2::m_signal(int n, t_float *const *in, t_float *const *out) +{ + ins = in[0]; + outs = out[0]; + + CopySamples(tmp,ins,n); + + n0=n/2; + + if (center-width>0) + { + n=center-width; + } + else + n=0; + + while (nn0) + { + width=n0-center; + return; + } + if (center-w<0) + { + width=center; + return; + } + + width=w; +} + + diff --git a/tbext/tbfft1.pd b/tbext/tbfft1.pd new file mode 100644 index 0000000..c9ced88 --- /dev/null +++ b/tbext/tbfft1.pd @@ -0,0 +1,44 @@ +#N canvas 245 106 453 369 10; +#N canvas 0 0 450 300 graph2 0; +#X array array1 63 float 1; +#A 0 0 0 0 0 0 0 0 0 0 -1 -1.24286 -1.45714 -1.61429 -1.7 -1.82857 +-1.88571 -1.92857 -2.04286 -2.17143 -2.18571 -2.2 -2.21429 -2.27143 +-2.28571 -2.28571 -2.3 -2.31429 -2.31429 -2.32857 -0.528571 -0.528571 +-0.542857 -0.514286 -0.485714 -0.4 -0.357143 -0.314286 -0.185714 -0.114286 +-0.0142857 0.185714 0.214286 0.314286 0.342857 0.4 0.5 0.514286 0.557143 +0.571429 0.628572 0.642857 0.671429 1.14286 0.428572 0.3 0.228572 0.157143 +0.114286 0.057143 0.057143 0.0428573 0.0428573 0; +#X coords 0 1 62 -1 200 140 1; +#X restore -67 3 graph; +#N canvas 0 0 450 300 graph3 0; +#X array array2 64 float 1; +#A 0 0 0 0 0 0 0 0 0 0 -0.4 -0.585 -0.685714 -0.767857 -0.824286 -0.869286 +-0.92 -0.945 -0.154551 -0.309103 -0.445624 -0.567631 -0.678947 -0.786968 +-0.876442 -0.953638 -1.02425 -1.04246 -0.02064 -0.031224 -0.04128 -0.0648 +-0.087 -0.147857 -0.191429 -0.4 -0.357143 -0.314286 -0.185714 -0.114286 +-0.0142857 0.185714 0.214286 0.314286 0.342857 0.4 0.5 0.514286 0.557143 +0.571429 0.628572 0.642857 0.671429 1.14286 0.428572 0.3 0.228572 0.157143 +0.114286 0.057143 0.057143 0.0428573 0.0428573 0 0; +#X coords 0 1 63 -1 200 140 1; +#X restore 159 1 graph; +#X obj -20 153 tabplay~ array1; +#X obj -78 189 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj -20 242 tabwrite~ array2; +#X obj -21 195 tbfft1~; +#X obj 164 152 hsl 128 15 -0.1 0.1 0 0 empty empty empty -2 -6 0 8 +-262144 -1 -1 0 1; +#X obj 150 216 hsl 128 15 0 44100 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 1400 1; +#X msg 161 176 factor \$1; +#X msg 147 235 center \$1; +#X floatatom 272 188 5 0 0 0 - - -; +#X connect 2 0 5 0; +#X connect 3 0 2 0; +#X connect 3 0 4 0; +#X connect 5 0 4 0; +#X connect 6 0 8 0; +#X connect 6 0 10 0; +#X connect 7 0 9 0; +#X connect 8 0 5 0; +#X connect 9 0 5 0; diff --git a/tbext/tbfft2.pd b/tbext/tbfft2.pd new file mode 100644 index 0000000..044b4aa --- /dev/null +++ b/tbext/tbfft2.pd @@ -0,0 +1,50 @@ +#N canvas 245 106 453 369 10; +#N canvas 0 0 450 300 graph2 0; +#X array array1 63 float 1; +#A 0 0 0 0 0 0 0 0.0571429 0.142857 0.171429 0.228571 0.314286 0.385714 +0.457143 0.542857 0.628572 0.714286 0.757143 0.742857 0.714286 0.671429 +0.628571 0.6 0 0 0 0.00714286 0.0142857 0.0142857 0.0142857 0.0142857 +0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 +0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0285714 0.0714286 +0.121429 0.171429 0.192857 0.214286 0.257143 0.328571 0.342857 0.385714 +0.414286 0.442857 1.86265e-09 0.0142857 0.0142857 0.0142857 0.0142857 +0.0142857 0.0142857 0.0142857 0.0142857; +#X coords 0 1 62 -1 200 140 1; +#X restore -67 3 graph; +#N canvas 444 250 450 300 graph3 0; +#X array array2 64 float 1; +#A 0 0 0 0 0 0 0 0.0571429 0.142857 0.171429 0.228571 0.314286 0.385714 +0.457143 0.542857 0.628572 0.714286 0.757143 0.742857 0.714286 0.671429 +0.628571 0.6 0 0 0 0.00714286 0.0142857 0.0142857 0.0142857 0.0142857 +0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 +0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0285714 0.0714286 +0 0 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 0.0142857 +0.0142857 1.86265e-09 0.442857 0.414286 0.385714 0.342857 0.328571 +0.257143 0.214286 0.192857 0.171429; +#X coords 0 1 63 -1 200 140 1; +#X restore 148 4 graph; +#X obj -20 153 tabplay~ array1; +#X obj -78 189 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj -20 242 tabwrite~ array2; +#X obj 164 152 hsl 128 15 0 64 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 2800 1; +#X obj 150 216 hsl 128 15 0 64 0 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 10900 1; +#X msg 147 235 center \$1; +#X floatatom 272 188 5 0 0 0 - - -; +#X obj -21 195 tbfft2~; +#X msg 161 176 width \$1; +#X obj -20 329 print~; +#X obj 140 308 block~ 128; +#X connect 2 0 9 0; +#X connect 3 0 2 0; +#X connect 3 0 4 0; +#X connect 3 0 11 0; +#X connect 5 0 10 0; +#X connect 5 0 8 0; +#X connect 6 0 7 0; +#X connect 7 0 9 0; +#X connect 9 0 4 0; +#X connect 9 0 11 0; +#X connect 10 0 9 0; -- cgit v1.2.1 From 80e47e2a02fc3cb39baeea8db56ef362b86c6e04 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 20 Sep 2003 15:37:44 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1013 --- tbext/make-files.txt | 2 +- tbext/source/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tbext/make-files.txt b/tbext/make-files.txt index e299154..b3a83b5 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -1,7 +1,7 @@ # all the source files from the package SRCDIR = source SRCS= \ - main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp tbssel~.cpp \ + main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp \ tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp \ fftgrshuf.cpp fftgrrev.cpp # tbg7xx.cpp tbstrg.cpp diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index 4b204f6..dd007df 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -56,7 +56,7 @@ void ttbext_setup() FLEXT_SETUP(tbroute); //FLEXT_SETUP(tbstrg); FLEXT_DSP_SETUP(tbsroute); - FLEXT_DSP_SETUP(tbssel); + // FLEXT_DSP_SETUP(tbssel); FLEXT_DSP_SETUP(tbsig); FLEXT_DSP_SETUP(tbpow); // FLEXT_DSP_SETUP(tbg7xx); -- cgit v1.2.1 From 4ab9c44294867638df5c092bb2a9de1923a63dd2 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 20 Sep 2003 15:54:40 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1014 --- tbext/config-pd-linux.txt | 2 +- tbext/makefile.pd-linux | 4 +- tbext/source/tbssel~.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 tbext/source/tbssel~.cpp diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt index 495aad9..7c9fbde 100755 --- a/tbext/config-pd-linux.txt +++ b/tbext/config-pd-linux.txt @@ -32,5 +32,5 @@ HELPDIR=${PD}/doc/5.reference # UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) -FLEXT_SHARED=1 +#FLEXT_SHARED=1 diff --git a/tbext/makefile.pd-linux b/tbext/makefile.pd-linux index 7948a19..56fbc17 100644 --- a/tbext/makefile.pd-linux +++ b/tbext/makefile.pd-linux @@ -17,11 +17,11 @@ FLEXTLIB=$(FLEXTPATH)/flext.a # compiler stuff INCLUDES=$(PDINC) FLAGS=-DFLEXT_SYS=2 -CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions +CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions -DFLEXT_THREADS LIBS=m ifdef FLEXT_SHARED -CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS +CFLAGS+=-DFLEXT_SHARED LDFLAGS+=-Bdynamic LINKFLEXT=-lflext #-L/usr/lib/flext/libflext.so else diff --git a/tbext/source/tbssel~.cpp b/tbext/source/tbssel~.cpp new file mode 100644 index 0000000..f9111aa --- /dev/null +++ b/tbext/source/tbssel~.cpp @@ -0,0 +1,100 @@ +/* Copyright (c) 2003 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* tbssel~ selects one signal from the incoming signals */ +/* the number of inlets is specified by the creation argument */ +/* */ +/* */ +/* tbssel~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: AMM: AMMMUSIC 1966 */ +/* Sun Ra: Dancing Shadows */ +/* */ + + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class tbssel: public flext_dsp +{ + FLEXT_HEADER(tbssel,flext_dsp) + +public: // constructor + tbssel(t_int chan); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + void set_source(int i); + +private: + FLEXT_CALLBACK_1(set_source,int) + t_int source; +}; + + +FLEXT_LIB_DSP_1("tbroute~",tbssel,int); + +tbssel::tbssel (t_int chan): + source(0) +{ + for (t_int i=0; i!=chan;++i) + { + AddInSignal(); + } + + AddOutSignal(); + + FLEXT_ADDMETHOD(1,set_source); +} + + +void tbssel::m_signal(int n, float *const *in, float *const *out) +{ + + CopySamples(out[0],in[source],n); + + +} + +void tbssel::set_source(int i) +{ + if ((i>-1) && (i Date: Wed, 28 Jan 2004 11:09:13 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1298 --- tbext/bufline~.pd | 315 ++++++++++++++++++++++++++++++++++++++++++---- tbext/config-pd-linux.txt | 9 +- tbext/make-files.txt | 2 +- tbext/makefile.pd-linux | 4 +- tbext/source/fftbuf.cpp | 38 ++++-- tbext/source/main.cpp | 5 +- tbext/source/tbfft2.cpp | 2 +- 7 files changed, 328 insertions(+), 47 deletions(-) diff --git a/tbext/bufline~.pd b/tbext/bufline~.pd index 7fd7d59..66d35c0 100644 --- a/tbext/bufline~.pd +++ b/tbext/bufline~.pd @@ -1,35 +1,294 @@ #N canvas 221 141 714 505 10; #N canvas 0 0 450 300 graph1 0; -#X array from1 64 float 1; +#X array from1 1024 float 1; #A 0 0 0 0 0 0 0 0.0285714 0.0357143 0.0428571 0.0714286 0.0857143 0.114286 0.128571 0.142857 0.142857 0.157143 0.171429 0.185714 0.2 0.214286 0.242857 0.242857 0.242857 0.242857 0.242857 0.214286 0.2 0.15 0.0714286 0.0714286 1.86265e-09 -0.0142857 -0.0285714 0 0 0 0 0 0 0 0 -0.0142857 -0.0285714 -0.0428571 -0.0571429 -0.0571429 -0.0571429 -0.0571429 -0.0571429 -0.0571429 -0.0571429 0.00714286 0.0714286 0.142857 -0.242857 0.314286 0.457143 0 0 0 0 0 0 0; -#X coords 0 1 63 -1 200 140 1; +0.242857 0.314286 0.457143 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0142857 -0.0190476 +-0.0238095 -0.0285714 -0.0333333 -0.0380952 -0.0428571 -0.0476191 -0.052381 +-0.0571429 -0.0619048 -0.0666667 -0.0714286 -0.0761905 -0.0809524 -0.0857141 +-0.0884919 -0.0912697 -0.0940475 -0.0968252 -0.099603 -0.102381 -0.105159 +-0.107936 -0.110714 -0.113492 -0.11627 -0.119047 -0.121825 -0.124603 +-0.127381 -0.130159 -0.132936 -0.135714 -0.138492 -0.14127 -0.144048 +-0.146825 -0.149603 -0.152381 -0.155159 -0.157936 -0.160714 -0.163492 +-0.16627 -0.169048 -0.171825 -0.174603 -0.177381 -0.180159 -0.182937 +-0.185714 -0.189796 -0.193877 -0.197959 -0.202041 -0.206122 -0.210204 +-0.214286 -0.218367 -0.222449 -0.226531 -0.230612 -0.234694 -0.238775 +-0.242857 -0.246939 -0.25102 -0.255102 -0.259184 -0.263265 -0.267347 +-0.271429 -0.27551 -0.279592 -0.283673 -0.287755 -0.291837 -0.295918 +-0.3 -0.304082 -0.308163 -0.312245 -0.316327 -0.320408 -0.32449 -0.328571 +-0.330494 -0.332417 -0.33434 -0.336263 -0.338186 -0.34011 -0.342033 +-0.343956 -0.345879 -0.347802 -0.349725 -0.351648 -0.353571 -0.355494 +-0.357417 -0.35934 -0.361263 -0.363187 -0.36511 -0.367033 -0.368956 +-0.370879 -0.372802 -0.374725 -0.376648 -0.378571 -0.380494 -0.382417 +-0.38434 -0.386264 -0.388187 -0.39011 -0.392033 -0.393956 -0.395879 +-0.397802 -0.399725 -0.401648 -0.403571 -0.405494 -0.407418 -0.409341 +-0.411264 -0.413187 -0.41511 -0.417033 -0.418956 -0.420879 -0.422802 +-0.424725 -0.426648 -0.428572 -0.432056 -0.435541 -0.439025 -0.442509 +-0.445993 -0.449478 -0.452962 -0.456446 -0.459931 -0.463415 -0.466899 +-0.470384 -0.473868 -0.477352 -0.480837 -0.484321 -0.487805 -0.491289 +-0.494774 -0.498258 -0.501742 -0.505227 -0.508711 -0.512195 -0.51568 +-0.519164 -0.522648 -0.526133 -0.529617 -0.533101 -0.536586 -0.54007 +-0.543554 -0.547038 -0.550523 -0.554007 -0.557491 -0.560976 -0.56446 +-0.567944 -0.571429 -0.573669 -0.57591 -0.578151 -0.580392 -0.582633 +-0.584874 -0.587115 -0.589356 -0.591597 -0.593838 -0.596078 -0.598319 +-0.60056 -0.602801 -0.605042 -0.607283 -0.609524 -0.611765 -0.614006 +-0.616247 -0.618487 -0.620728 -0.622969 -0.62521 -0.627451 -0.629692 +-0.631933 -0.634174 -0.636415 -0.638655 -0.640896 -0.643137 -0.645378 +-0.647619 -0.64986 -0.652101 -0.654342 -0.656583 -0.658824 -0.661064 +-0.663305 -0.665546 -0.667787 -0.670028 -0.672269 -0.67451 -0.676751 +-0.678992 -0.681233 -0.683473 -0.685714 -0.687143 -0.688571 -0.69 -0.691428 +-0.692857 -0.694286 -0.695714 -0.697143 -0.698571 -0.7 -0.702286 -0.704571 +-0.706857 -0.709143 -0.711429 -0.713714 -0.716 -0.718286 -0.720571 +-0.722857 -0.725143 -0.727429 -0.729714 -0.732 -0.734286 -0.736571 +-0.738857 -0.741143 -0.743429 -0.745714 -0.748 -0.750286 -0.752571 +-0.754857 -0.757143 -0.757143 -0.757143 -0.757143 -0.757143 -0.757143 +-0.757143 -0.758571 -0.76 -0.761428 -0.762857 -0.764286 -0.765714 -0.767143 +-0.768571 -0.77 -0.771429 -0.771429 -0.771429 -0.771429 -0.771429 -0.771429 +-0.774286 -0.777143 -0.78 -0.782857 -0.8 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; +#A 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; +#X coords 0 1 1023 -1 200 140 1; #X restore 80 20 graph; -#X obj 607 14 block~ 128; #N canvas 0 0 450 300 graph1 0; -#X array from2 64 float 1; +#X array from2 1024 float 1; #A 0 0 0 0 0 0 0 0 0 0 0.0285714 0.0571429 0.0761905 0.0952381 0.114286 0.12381 0.133333 0.142857 0.2 0.207143 0.228571 0.228571 0.257143 0.257143 0.257143 0.242857 -0.0142857 0 0 0 0 0 0 0 0 0 -0.471429 -0.628572 --0.685714 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; -#X coords 0 1 63 -1 200 140 1; +-0.685714 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 1.86265e-10 0.00428571 0.00857143 0.0128571 +0.0171429 0.0214286 0.0257143 0.03 0.0342857 0.0385714 0.0428572 0.0457143 +0.0485715 0.0514286 0.0542857 0.0571429 0.06 0.0628572 0.0657143 0.0685714 +0.0714286 0.0742857 0.0771429 0.08 0.0828571 0.0857144 0.0884794 0.0912443 +0.0940093 0.0967743 0.0995393 0.102304 0.105069 0.107834 0.110599 0.113364 +0.116129 0.118894 0.121659 0.124424 0.127189 0.129954 0.132719 0.135484 +0.138249 0.141014 0.143779 0.146544 0.149309 0.152074 0.154839 0.157604 +0.160369 0.163134 0.165899 0.168664 0.171428 0.174286 0.177143 0.18 +0.182857 0.185714 0.188571 0.191429 0.194286 0.197143 0.2 0.202857 +0.205714 0.208571 0.211429 0.214286 0.216527 0.218768 0.221008 0.223249 +0.22549 0.227731 0.229972 0.232213 0.234454 0.236695 0.238936 0.241176 +0.243417 0.245658 0.247899 0.25014 0.252381 0.254622 0.256863 0.259104 +0.261345 0.263585 0.265826 0.268067 0.270308 0.272549 0.27479 0.277031 +0.279272 0.281513 0.283754 0.285994 0.288235 0.290476 0.292717 0.294958 +0.297199 0.29944 0.301681 0.303922 0.306162 0.308403 0.310644 0.312885 +0.315126 0.317367 0.319608 0.321849 0.32409 0.326331 0.328571 0.330952 +0.333333 0.335714 0.338095 0.340476 0.342857 0.345238 0.347619 0.35 +0.352381 0.354762 0.357143 0.359523 0.361904 0.364285 0.366666 0.369047 +0.371428 0.373809 0.37619 0.378571 0.380952 0.383333 0.385714 0.388095 +0.390476 0.392857 0.395238 0.397619 0.4 0.402381 0.404762 0.407143 +0.409524 0.411905 0.414286 0.416484 0.418681 0.420879 0.423077 0.425275 +0.427473 0.42967 0.431868 0.434066 0.436264 0.438462 0.440659 0.442857 +0.445055 0.447253 0.449451 0.451648 0.453846 0.456044 0.458242 0.46044 +0.462637 0.464835 0.467033 0.469231 0.471429 0.472 0.472571 0.473143 +0.473714 0.474286 0.474857 0.475429 0.476 0.476571 0.477143 0.477714 +0.478286 0.478857 0.479429 0.48 0.480571 0.481143 0.481714 0.482286 +0.482857 0.483429 0.484 0.484571 0.485143 0.485715 0.486412 0.487108 +0.487805 0.488502 0.489199 0.489896 0.490593 0.49129 0.491987 0.492683 +0.49338 0.494077 0.494774 0.495471 0.496168 0.496865 0.497562 0.498258 +0.498955 0.499652 0.500349 0.501046 0.501743 0.502439 0.503136 0.503833 +0.50453 0.505227 0.505924 0.506621 0.507317 0.508014 0.508711 0.509408 +0.510105 0.510802 0.511498 0.512195 0.512892 0.513589 0.514287 0.515385 +0.516484 0.517583 0.518682 0.519781 0.52088 0.521979 0.523077 0.524176 +0.525275 0.526374 0.527473 0.528572 0.529671 0.53077 0.531868 0.532967 +0.534066 0.535165 0.536264 0.537363 0.538462 0.539561 0.540659 0.541758 +0.542857 0.544 0.545143 0.546286 0.547429 0.548571 0.549714 0.550857 +0.552 0.553143 0.554286 0.555429 0.556571 0.557714 0.558857 0.56 0.561143 +0.562286 0.563429 0.564571 0.565714 0.566857 0.568 0.569143 0.570286 +0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 +0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 +0.571428 0.570476 0.569524 0.568571 0.567619 0.566666 0.565714 0.564762 +0.563809 0.562857 0.561905 0.560952 0.56 0.559048 0.558095 0.557143 +0.555714 0.554286 0.552857 0.551429 0.55 0.548571 0.547143 0.545714 +0.544286 0.542857 0.54 0.537143 0.534286 0.531429 0.528571 0.525714 +0.522857 0.52 0.517143 0.514286 0.511429 0.508571 0.505714 0.502857 +0.5 0.498701 0.497403 0.496104 0.494805 0.493506 0.492208 0.490909 +0.48961 0.488312 0.487013 0.485714 0.483429 0.481143 0.478857 0.476572 +0.474286 0.472 0.469714 0.467429 0.465143 0.462857 0.460571 0.458286 +0.456 0.453714 0.451429 0.449143 0.446857 0.444571 0.442286 0.44 0.437714 +0.435429 0.433143 0.430857 0.428571 0.425893 0.423214 0.420536 0.417857 +0.415179 0.4125 0.409821 0.407143 0.404464 0.401786 0.399107 0.396429 +0.39375 0.391071 0.388393 0.385714 0.382143 0.378571 0.375 0.371428 +0.367857 0.364286 0.360714 0.357143 0.353571 0.35 0.346428 0.342857 +0.339286 0.335714 0.332143 0.328571 0.325 0.321429 0.317857 0.314286 +0.31 0.305714 0.301429 0.297143 0.292857 0.288571 0.284286 0.28 0.275714 +0.271429 0.270046 0.268664 0.267281 0.265899 0.264516 0.263134 0.261751 +0.260369 0.258986 0.257604 0.256221 0.254839 0.253456 0.252074 0.250691 +0.249309 0.247926 0.246544 0.245161 0.243779 0.242396 0.241014 0.239631 +0.238249 0.236866 0.235484 0.234101 0.232719 0.231336 0.229954 0.228572 +0.225714 0.222857 0.22 0.217143 0.214286 0.211429 0.208571 0.205714 +0.202857 0.2 0.197143 0.194286 0.191429 0.188571 0.185714 0.177143 +0.168571 0.16 0.151429 0.142857 0.141558 0.14026 0.138961 0.137662 +0.136364 0.135065 0.133766 0.132468 0.131169 0.12987 0.128571 0.128571 +0.128571 0.128571 0.128571 0.128571 0.125714 0.122857 0.12 0.117143 +0.1 0.1 0.1 0.1 0.1 0.1 0.0914286 0.0828571 0.0742857 0.0657143 0.0571428 +0.0542857 0.0514286 0.0485714 0.0457143 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0257143 0.0228571 0.02 0.0171429 0.0142857 +0.0114286 0.00857142 0.00571428 0.00285714 -5.58794e-09 -5.58794e-09 +-5.58794e-09 -5.58794e-09 -5.58794e-09 -5.58794e-09 -5.58794e-09 -5.58794e-09 +-5.58794e-09 -5.58794e-09 -5.58794e-09 -5.58794e-09 -5.58794e-09 -5.58794e-09 +-5.58794e-09 -5.58794e-09 0.563636 0.562338 0.561039 0.55974 0.558442 +0.557143 0.555429 0.553714 0.552 0.550286 0.548571 0.546857 0.545143 +0.543429 0.541714 0.54 0.538286 0.536571 0.534857 0.533143 0.531429 +0.529714 0.528 0.526286 0.524571 0.522857 0.521143 0.519429 0.517714 +0.516 0.514285 0.512857 0.511428 0.51 0.508571 0.507143 0.505714 0.504286 +0.502857 0.501429 0.5 0.497222 0.494445 0.491667 0.488889 0.486111 +0.483334 0.480556 0.477778 0.475 0.472222 0.469445 0.466667 0.463889 +0.461111 0.458333 0.455556 0.452778 0.45 0.447222 0.444445 0.441667 +0.438889 0.436111 0.433333 0.430556 0.427778 0.425 0.422222 0.419444 +0.416667 0.413889 0.411111 0.408333 0.405556 0.402778 0.4 0.398352 +0.396704 0.395055 0.393407 0.391759 0.39011 0.388462 0.386813 0.385165 +0.383517 0.381868 0.38022 0.378572 0.376923 0.375275 0.373626 0.371978 +0.37033 0.368681 0.367033 0.365385 0.363736 0.362088 0.36044 0.358791 +0.357143 0.354286 0.351429 0.348571 0.345714 0.342857 0.34 0.337143 +0.334286 0.331429 0.328571 0.325714 0.322857 0.32 0.317143 0.314286 +0.308571 0.302857 0.297143 0.291429 0.285714 0.282857 0.28 0.277143 +0.274286 0.271429 0.268571 0.265714 0.262857 0.26 0.242857 0.240476 +0.238095 0.235714 0.233333 0.230952 0.214286 0.214286 0.214286 0.214286 +0.214286 0.214286 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0; +#A 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; +#X coords 0 1 1023 -1 200 140 1; #X restore 335 23 graph; #N canvas 0 0 450 300 graph1 0; -#X array to 64 float 1; -#A 0 0 0 0 0 0 0 0.00682475 0.00853045 0.0102368 0.0388103 0.0639679 -0.0852809 0.10321 0.121109 0.128353 0.139015 0.149682 0.196567 0.205455 -0.225179 0.232002 0.253755 0.253755 0.253755 0.242854 0.0403107 0.047774 -0.0358276 0.0170609 0.0170609 4.44924e-10 -0.00341237 -0.00682475 0 -0 -0.35882 -0.478471 -0.521873 0 0 0 -0.00341233 -0.00682466 -0.0102368 --0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.0136493 -0.00170617 0.0170609 0.0341218 0.0580107 0.0750683 0.109195 0 0 0 0 -0 0 0; -#X coords 0 1 63 -1 200 140 1; +#X array to 1024 float 1; +#A 0 0 0 0 0 0 0 1.39698e-08 -1.33878e-09 -1.57743e-08 0.0285713 0.0571426 +0.0761908 0.095238 0.114286 0.12381 0.133332 0.142856 0.2 0.207142 +0.228571 0.228571 0.257142 0.257142 0.257142 0.242857 -0.0142856 -9.49949e-08 +3.05008e-08 -2.67755e-09 -2.67755e-09 -1.8735e-15 -6.98492e-09 -1.39698e-08 +0 0 -0.471429 -0.628572 -0.685714 0 0 0 -6.98492e-09 -1.39698e-08 1.57743e-08 +-4.42378e-08 -4.42378e-08 -4.42378e-08 -4.42378e-08 -4.42378e-08 -4.42378e-08 +-4.42378e-08 4.64206e-09 -2.67755e-09 -5.51809e-08 -2.07219e-07 2.25846e-07 +3.8743e-07 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -9.28412e-09 -1.87138e-08 -1.97324e-08 +-2.52039e-08 -1.04774e-08 -3.05008e-08 1.18162e-08 -2.88128e-08 3.52156e-08 +-4.79631e-08 5.58794e-08 -1.38534e-08 0.00428565 0.00857141 0.0128571 +0.0171429 0.0214285 0.0257142 0.03 0.0342858 0.0385715 0.0428572 0.0457143 +0.0485715 0.0514285 0.0542857 0.0571429 0.0600001 0.0628572 0.0657144 +0.0685714 0.0714285 0.0742857 0.0771428 0.08 0.0828572 0.0857145 0.0884794 +0.0912442 0.0940094 0.0967743 0.0995392 0.102304 0.105069 0.107834 +0.110599 0.113364 0.116129 0.118894 0.121659 0.124424 0.127189 0.129954 +0.132719 0.135484 0.138249 0.141014 0.143779 0.146544 0.149309 0.152074 +0.154839 0.157604 0.160369 0.163134 0.165898 0.168663 0.171428 0.174285 +0.177143 0.18 0.182857 0.185714 0.188571 0.191429 0.194286 0.197143 +0.2 0.202857 0.205714 0.208571 0.211429 0.214286 0.216527 0.218767 +0.221008 0.22325 0.22549 0.227731 0.229972 0.232213 0.234454 0.236695 +0.238935 0.241176 0.243417 0.245658 0.247899 0.25014 0.252381 0.254622 +0.256863 0.259104 0.261344 0.263586 0.265826 0.268068 0.270308 0.272549 +0.27479 0.277031 0.279272 0.281512 0.283754 0.285994 0.288236 0.290476 +0.292717 0.294958 0.297199 0.299439 0.301681 0.303921 0.306163 0.308403 +0.310644 0.312885 0.315126 0.317367 0.319608 0.321849 0.32409 0.32633 +0.328571 0.330952 0.333333 0.335714 0.338095 0.340476 0.342856 0.345238 +0.347618 0.35 0.352381 0.354761 0.357143 0.359523 0.361905 0.364286 +0.366666 0.369048 0.371428 0.373809 0.376191 0.378571 0.380952 0.383333 +0.385714 0.388095 0.390476 0.392857 0.395238 0.397619 0.4 0.40238 0.404762 +0.407142 0.409524 0.411905 0.414285 0.416484 0.418681 0.420879 0.423077 +0.425274 0.427472 0.429671 0.431868 0.434066 0.436263 0.438461 0.440659 +0.442857 0.445055 0.447253 0.44945 0.451648 0.453846 0.456044 0.458242 +0.46044 0.462637 0.464835 0.467033 0.469231 0.471429 0.472 0.472572 +0.473143 0.473715 0.474285 0.474858 0.475429 0.476 0.476571 0.477143 +0.477714 0.478286 0.478857 0.479429 0.48 0.480572 0.481143 0.481715 +0.482286 0.482857 0.483428 0.484001 0.484572 0.485143 0.485714 0.486412 +0.487109 0.487806 0.488502 0.489199 0.489896 0.490593 0.49129 0.491986 +0.492683 0.49338 0.494078 0.494774 0.495471 0.496167 0.496864 0.497562 +0.498259 0.498955 0.499652 0.500349 0.501046 0.501742 0.50244 0.503137 +0.503833 0.50453 0.505227 0.505924 0.506621 0.507317 0.508015 0.508712 +0.509407 0.510105 0.510801 0.511498 0.512196 0.512892 0.513588 0.514287 +0.515385 0.516484 0.517584 0.518682 0.519781 0.52088 0.521979 0.523078 +0.524176 0.525276 0.526374 0.527473 0.528571 0.529671 0.530769 0.531869 +0.532967 0.534066 0.535165 0.536263 0.537363 0.538462 0.539561 0.54066 +0.541759 0.542858 0.544 0.545143 0.546286 0.547428 0.548572 0.549715 +0.550857 0.552 0.553143 0.554286 0.555429 0.556571 0.557715 0.558857 +0.56 0.561143 0.562286 0.563429 0.564571 0.565715 0.566857 0.568 0.569144 +0.570285 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 +0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 0.571429 +0.571429 0.571428 0.570476 0.569524 0.568571 0.567619 0.566667 0.565714 +0.564761 0.563809 0.562857 0.561905 0.560952 0.56 0.559047 0.558095 +0.557143 0.555714 0.554286 0.552857 0.551429 0.55 0.548572 0.547143 +0.545715 0.544285 0.542857 0.54 0.537143 0.534286 0.531428 0.528572 +0.525714 0.522857 0.519999 0.517143 0.514286 0.511428 0.508572 0.505714 +0.502858 0.5 0.498701 0.497403 0.496104 0.494805 0.493507 0.492207 +0.490908 0.489611 0.488311 0.487013 0.485715 0.483429 0.481143 0.478857 +0.476571 0.474286 0.472 0.469715 0.467429 0.465142 0.462857 0.460571 +0.458286 0.456001 0.453714 0.451428 0.449143 0.446857 0.444572 0.442286 +0.44 0.437714 0.435428 0.433143 0.430858 0.428572 0.425893 0.423214 +0.420535 0.417857 0.415179 0.4125 0.409822 0.407143 0.404464 0.401785 +0.399107 0.396429 0.39375 0.391071 0.388392 0.385715 0.382142 0.378571 +0.375 0.371428 0.367857 0.364285 0.360714 0.357143 0.353572 0.35 0.346429 +0.342857 0.339286 0.335714 0.332143 0.328571 0.325 0.321428 0.317857 +0.314286 0.31 0.305714 0.301429 0.297143 0.292857 0.288572 0.284286 +0.28 0.275715 0.271428 0.270046 0.268664 0.267281 0.265899 0.264516 +0.263133 0.261751 0.260369 0.258986 0.257604 0.256221 0.254838 0.253456 +0.252074 0.250691 0.249308 0.247926 0.246544 0.245161 0.243779 0.242396 +0.241013 0.239632 0.238249 0.236866 0.235484 0.234101 0.232719 0.231337 +0.229954 0.228571 0.225714 0.222857 0.22 0.217143 0.214286 0.211429 +0.208572 0.205714 0.202857 0.2 0.197143 0.194286 0.191428 0.188571 +0.185714 0.177143 0.168571 0.16 0.151428 0.142857 0.141558 0.14026 +0.138961 0.137662 0.136364 0.135065 0.133766 0.132467 0.131169 0.12987 +0.128571 0.128571 0.128571 0.128571 0.128571 0.128571 0.125714 0.122857 +0.12 0.117143 0.1 0.1 0.1 0.1 0.1 0.1 0.0914285 0.0828572 0.0742856 +0.0657142 0.0571428 0.0542856 0.0514286 0.0485714 0.0457143 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 +0.0285714 0.0285714 0.0285714 0.0285714 0.0285714 0.0257143 0.0228571 +0.02 0.0171428 0.0142857 0.0114286 0.00857142 0.00571428 0.00285713 +-5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 +-5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 +-5.58793e-09 -5.58793e-09 -5.58793e-09 -5.58793e-09 0.563637 0.562338 +0.561039 0.559741 0.558441 0.557143 0.555429 0.553714 0.552 0.550286 +0.548572 0.546857 0.545143 0.543428 0.541715 0.54 0.538286 0.536572 +0.534857 0.533143 0.531428 0.529714 0.528001 0.526286 0.524572 0.522857 +0.521143 0.519428 0.517714 0.516 0.514285 0.512857 0.511428 0.51 0.508572 +0.507142 0.505714 0.504286 0.502858 0.501428 0.5 0.497223 0.494444 +0.491667 0.488889 0.486112 0.483333 0.480556 0.477778 0.475001 0.472222 +0.469445 0.466667 0.463889 0.461111 0.458334 0.455555 0.452778 0.45 +0.447223 0.444444 0.441667 0.438889 0.436112 0.433333 0.430556 0.427778 +0.425001 0.422222 0.419445 0.416667 0.413888 0.411111 0.408333 0.405556 +0.402777 0.4 0.398352 0.396703 0.395056 0.393407 0.391759 0.39011 0.388462 +0.386814 0.385165 0.383517 0.381868 0.38022 0.378572 0.376923 0.375275 +0.373626 0.371978 0.370329 0.368682 0.367033 0.365385 0.363736 0.362088 +0.36044 0.358792 0.357143 0.354286 0.351428 0.348572 0.345714 0.342857 +0.34 0.337143 0.334286 0.331429 0.328571 0.325714 0.322857 0.32 0.317143 +0.314286 0.308571 0.302857 0.297143 0.291429 0.285714 0.282857 0.28 +0.277143 0.274286 0.271428 0.268571 0.265714 0.262857 0.26 0.242857 +0.240476 0.238095 0.235715 0.233333 0.230953 0.214286 0.214286 0.214286 +0.214286 0.214286 0.214286 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0; +#A 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; +#X coords 0 1 1023 -1 200 140 1; #X restore 456 301 graph; #X obj 144 412 tabwrite~ to; #X obj 208 373 metro 50; @@ -42,15 +301,23 @@ #X obj 63 385 print~; #X obj 26 332 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X obj 88 321 bufline~ 128; #X msg 119 239 line 400; +#X obj 88 321 bufline~ 1024; +#X obj 607 14 block~ 2048; +#X obj 341 332 delay; +#X obj 341 355 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X msg 338 287 5000; +#X connect 4 0 3 0; #X connect 5 0 4 0; -#X connect 6 0 5 0; +#X connect 6 0 13 0; +#X connect 6 0 17 0; #X connect 7 0 13 0; #X connect 8 0 13 0; #X connect 9 0 13 0; -#X connect 10 0 13 0; -#X connect 12 0 11 0; -#X connect 13 0 11 0; -#X connect 13 0 4 0; -#X connect 14 0 13 0; +#X connect 11 0 10 0; +#X connect 12 0 13 0; +#X connect 13 0 10 0; +#X connect 13 0 3 0; +#X connect 15 0 16 0; +#X connect 17 0 15 0; diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt index 7c9fbde..b1479f8 100755 --- a/tbext/config-pd-linux.txt +++ b/tbext/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for tbext, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) -# CXX=icc + CXX=icc # where does the PD installation reside? @@ -10,7 +10,8 @@ PD=/usr/lib/pd # where are the PD header files? # leave it blank if it is a system directory (like /usr/local/include), # since gcc 3.2 complains about it -PDINC=/home/tim/pd/pd-0.37-0/src +PDINC=/home/tim/pd/pd/src +#PDINC=/home/tim/pd/devel_0_36/pd/src # where do the flext libraries reside? FLEXTPATH=/usr/lib/flext @@ -28,9 +29,9 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) -#UFLAGS=-xW -tpp7 -ip -ipo_obj -g # icc +UFLAGS=-g -xW -tpp7 -ip -ipo_obj # icc # UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) -#FLEXT_SHARED=1 +FLEXT_SHARED=1 diff --git a/tbext/make-files.txt b/tbext/make-files.txt index b3a83b5..559a851 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -3,7 +3,7 @@ SRCDIR = source SRCS= \ main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp \ tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp \ - fftgrshuf.cpp fftgrrev.cpp # tbg7xx.cpp tbstrg.cpp + fftgrshuf.cpp fftgrrev.cpp #HDRS= \ diff --git a/tbext/makefile.pd-linux b/tbext/makefile.pd-linux index 56fbc17..7948a19 100644 --- a/tbext/makefile.pd-linux +++ b/tbext/makefile.pd-linux @@ -17,11 +17,11 @@ FLEXTLIB=$(FLEXTPATH)/flext.a # compiler stuff INCLUDES=$(PDINC) FLAGS=-DFLEXT_SYS=2 -CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions -DFLEXT_THREADS +CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions LIBS=m ifdef FLEXT_SHARED -CFLAGS+=-DFLEXT_SHARED +CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS LDFLAGS+=-Bdynamic LINKFLEXT=-lflext #-L/usr/lib/flext/libflext.so else diff --git a/tbext/source/fftbuf.cpp b/tbext/source/fftbuf.cpp index eff81e3..13f0b9e 100644 --- a/tbext/source/fftbuf.cpp +++ b/tbext/source/fftbuf.cpp @@ -121,27 +121,36 @@ fftbuf::~fftbuf() void fftbuf::m_signal(int n, t_float *const *in, t_float *const *out) { - outs = out[0]; - - if (counter!=0) + if (check(buf)) { - n=n/2+1; + outs = out[0]; + + if (counter!=0) + { + n=n/2+1; while (--n) data[n] = data[n] - offset[n]; /* for(int i=0;i!=bs;++i) - { + { data[i] = data[i] - offset[i]; - } + } */ - + --counter; + } + + CopySamples(out[0],data,bs); } - - CopySamples(out[0],data,bs); + else + CopySamples(out[0],data,bs); + } +//perform und dsp gleichzeitig?!? + + void fftbuf::perform() { counter=blknumber(); @@ -196,7 +205,7 @@ void fftbuf::set_buf(int argc, t_atom *argv) } template -/*inline*/ void fftbuf::clear(T* buf) +inline void fftbuf::clear(T* buf) { if (buf) { @@ -207,6 +216,8 @@ template inline bool fftbuf::check(buffer * buf) { + if (buf==NULL) + return false; //code taken from the flext tutorial (buffer 1) by thomas grill if(buf->Update()) @@ -241,7 +252,8 @@ void fftbuf::set_line(int argc, t_atom *argv) inline int fftbuf::blknumber() { - // post("%i %i %i",delay,bs,sr); - // post("computer counter: %i",delay*bs/sr*1000); - return delay*bs/sr*1000; //ms/sample + post("%i %i %i",delay,bs,sr); + post("blknumber: %i",delay*bs/sr); + + return delay*bs/sr; //ms/sample } diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index dd007df..5a3bb14 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -51,10 +51,10 @@ void ttbext_setup() post("TBEXT: by tim blechmann"); post("version "TBEXT_VERSION); post("compiled on "__DATE__); - post(""); + post("contains: tbroute(~), tbsig~, tbpow~, tbfft1~, tbfft2~, bufline~, fftgrrev~"); + post(" fftgrsort~, fftgrshuf~"); FLEXT_SETUP(tbroute); - //FLEXT_SETUP(tbstrg); FLEXT_DSP_SETUP(tbsroute); // FLEXT_DSP_SETUP(tbssel); FLEXT_DSP_SETUP(tbsig); @@ -66,6 +66,7 @@ void ttbext_setup() FLEXT_DSP_SETUP(fftgrsort); FLEXT_DSP_SETUP(fftgrshuf); FLEXT_DSP_SETUP(fftgrrev); + FLEXT_DSP_SETUP(spigot_tilde); } FLEXT_LIB_SETUP(tbext,ttbext_setup) diff --git a/tbext/source/tbfft2.cpp b/tbext/source/tbfft2.cpp index 6ed71d9..99d16fe 100644 --- a/tbext/source/tbfft2.cpp +++ b/tbext/source/tbfft2.cpp @@ -72,7 +72,7 @@ private: float *ins; float *outs; float *tmps; - t_float tmp[2049]; + t_float tmp[17000]; t_float s; t_float b; -- cgit v1.2.1 From b37d7f4d59d1ec038f6920e7a44436558d84befe Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 29 Feb 2004 13:57:19 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1364 --- tbext/config-pd-linux.txt | 4 ++ tbext/make-files.txt | 5 +- tbext/makefile.pd-linux | 8 ++- tbext/source/main.cpp | 15 +++-- tbext/source/rfftw~.cpp | 138 +++++++++++++++++++++++++++++++++++++++ tbext/source/rifftw~.cpp | 161 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 324 insertions(+), 7 deletions(-) create mode 100644 tbext/source/rfftw~.cpp create mode 100644 tbext/source/rifftw~.cpp diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt index b1479f8..b1acfa1 100755 --- a/tbext/config-pd-linux.txt +++ b/tbext/config-pd-linux.txt @@ -32,6 +32,10 @@ HELPDIR=${PD}/doc/5.reference UFLAGS=-g -xW -tpp7 -ip -ipo_obj # icc # UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 +#compile support for the fftw3 library +#make sure that you compiled fftw3 for single precision floats!!! +FFTW=1 + # define to link against shared flext library (flext version >= 0.5.0) FLEXT_SHARED=1 diff --git a/tbext/make-files.txt b/tbext/make-files.txt index 559a851..cf7bc8e 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -4,7 +4,10 @@ SRCS= \ main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp \ tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp \ fftgrshuf.cpp fftgrrev.cpp - + +ifdef FFTW +SRCS+=fftw~.cpp ifftw~.cpp rfftw~.cpp rifftw~.cpp +endif #HDRS= \ main.h diff --git a/tbext/makefile.pd-linux b/tbext/makefile.pd-linux index 7948a19..3546d99 100644 --- a/tbext/makefile.pd-linux +++ b/tbext/makefile.pd-linux @@ -1,5 +1,4 @@ -# xsample - extended sample objects for Max/MSP and pd (pure data) -# Copyright (c) 2001-2003 Thomas Grill (xovo@gmx.net) +# makefile adapted from thomas grill's xsample makefile # # Makefile for gcc @ linux # @@ -28,6 +27,11 @@ else LINKFLEXT=$(FLEXTLIB) endif +ifdef FFTW +LDFLAGS+=-lfftw3f +CFLAGS+=-DFFTW +endif + # ---------------------------------------------- # the rest can stay untouched # ---------------------------------------------- diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index 5a3bb14..07a0713 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 Tim Blechmann. */ +/* Copyright (c) 2003-2004 Tim Blechmann. */ /* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ /* WARRANTIES, see the file, "COPYING" in this distribution. */ /* */ @@ -40,7 +40,7 @@ #include -#define TBEXT_VERSION "0.03" +#define TBEXT_VERSION "0.04" #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) #error upgrade your flext version!!!!!! @@ -52,7 +52,7 @@ void ttbext_setup() post("version "TBEXT_VERSION); post("compiled on "__DATE__); post("contains: tbroute(~), tbsig~, tbpow~, tbfft1~, tbfft2~, bufline~, fftgrrev~"); - post(" fftgrsort~, fftgrshuf~"); + post(" fftgrsort~, fftgrshuf~, rfftw~, rifftw~"); FLEXT_SETUP(tbroute); FLEXT_DSP_SETUP(tbsroute); @@ -66,7 +66,14 @@ void ttbext_setup() FLEXT_DSP_SETUP(fftgrsort); FLEXT_DSP_SETUP(fftgrshuf); FLEXT_DSP_SETUP(fftgrrev); - FLEXT_DSP_SETUP(spigot_tilde); + + +#if (FFTW == 1) + FLEXT_DSP_SETUP(rfftw); + FLEXT_DSP_SETUP(rifftw); +#endif + + } FLEXT_LIB_SETUP(tbext,ttbext_setup) diff --git a/tbext/source/rfftw~.cpp b/tbext/source/rfftw~.cpp new file mode 100644 index 0000000..dd10517 --- /dev/null +++ b/tbext/source/rfftw~.cpp @@ -0,0 +1,138 @@ +/* Copyright (c) 2004 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* rfftw~ is doing the same as rfft~, but it's based on the fftw library, */ +/* that is much faster that pd's internal fft ... */ +/* */ +/* */ +/* rfftw~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Wolfgang Mitterer: Radiofractal & Beat Music */ +/* Sun Ra: Reflections In Blue */ +/* */ +/* */ + + + +#include + +#include "fftw3.h" +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class rfftw: public flext_dsp +{ + FLEXT_HEADER(rfftw,flext_dsp); + +public: // constructor + rfftw(); + ~rfftw(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + + fftwf_plan p; //fftw plan + int bins; //number of bins + float * outreal; //pointer to real output + float * outimag; //pointer to imaginary output + + float * infft; //array fftw is working on + float * outfft; //array fftw uses to output it's values + + + private: +}; + + +FLEXT_LIB_DSP("rfftw~",rfftw); + +rfftw::rfftw() + :bins(64) +{ + //get ready for the default blocksize + infft = fftwf_malloc(sizeof(float) * bins); + outfft = fftwf_malloc(sizeof(float) * bins); + p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_FORWARD,FFTW_MEASURE); + + AddInSignal(); + AddOutSignal(); + AddOutSignal(); +} + +rfftw::~rfftw() +{ + fftwf_free(infft); + fftwf_free(outfft); + fftwf_destroy_plan(p); +} + + +void rfftw::m_signal(int n, float *const *in, float *const *out) +{ + //set output pointers + outreal = out[0]; + outimag = out[1]; + + //if blocksize changed, we have to set a new plan for the fft + if (n!=bins) + { + bins=n; + + //re-allocate fft buffers + fftwf_free(infft); + infft = fftwf_malloc(sizeof(float) * bins); + fftwf_free(outfft); + outfft = fftwf_malloc(sizeof(float) * bins); + + //set plan, this might take a few seconds + //but you don't have to do that on the fly... + fftwf_destroy_plan(p); + p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_FORWARD,FFTW_MEASURE); + } + + CopySamples(infft,in[0],n); + + //execute + fftwf_execute(p); + + //Copy samples to outlets + CopySamples(outreal,outfft,n/2); + std::reverse_copy(outfft+n/2+1,outfft+n,outimag+1); + + //why do we have to invert the samples??? + for (int i = n/2+1; i!=0;--i) + { + *(outimag+i)=-*(outimag+i); + } + +} + diff --git a/tbext/source/rifftw~.cpp b/tbext/source/rifftw~.cpp new file mode 100644 index 0000000..ee6f126 --- /dev/null +++ b/tbext/source/rifftw~.cpp @@ -0,0 +1,161 @@ +/* Copyright (c) 2004 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* rifftw~ is doing the same as rifft~, but it's based on the fftw library, */ +/* that is much faster that pd's internal fft ... */ +/* */ +/* */ +/* rifftw~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Caged/Uncaged */ +/* Sunny Murray: Hommage To Africa */ +/* */ +/* */ + + + +#include + +#include "fftw3.h" +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +class rifftw: public flext_dsp +{ + FLEXT_HEADER(rifftw,flext_dsp); + +public: // constructor + rifftw(); + ~rifftw(); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + + fftwf_plan p; //fftw plan + int bins; //number of bins + float * inreal; //pointer to real input + float * inimag; //pointer to imaginary input + + fftwf_complex * incomplex; + + //float * infft; //array fftw is working on + float * outfft; //array fftw uses to output it's values + + + private: +}; + + +FLEXT_LIB_DSP("rifftw~",rifftw); + +rifftw::rifftw() + :bins(64) +{ + //get ready for the default blocksize + // infft = fftwf_malloc(sizeof(float) * bins); + outfft = fftwf_malloc(sizeof(float) * bins); + + + incomplex = fftwf_malloc(sizeof(fftwf_complex) * bins); + + + // p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_BACKWARD,FFTW_MEASURE); + p=fftwf_plan_dft_c2r_1d(bins,incomplex,outfft,FFTW_BACKWARD,FFTW_MEASURE); + + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +rifftw::~rifftw() +{ + // fftwf_free(infft); + fftwf_free(outfft); + fftwf_free(incomplex); + fftwf_destroy_plan(p); +} + + +void rifftw::m_signal(int n, float *const *in, float *const *out) +{ + //set output pointers + inreal = in[0]; + inimag = in[1]; + + //if blocksize changed, we have to set a new plan for the fft + if (n!=bins) + { + bins=n; + + //re-allocate fft buffers + // fftwf_free(infft); + // infft = fftwf_malloc(sizeof(float) * bins); + fftwf_free(outfft); + outfft = fftwf_malloc(sizeof(float) * bins); + + fftwf_free(incomplex); + incomplex = fftwf_malloc(sizeof(fftwf_complex) * bins); + + //set plan, this might take a few seconds + //but you don't have to do that on the fly... + fftwf_destroy_plan(p); + //p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_BACKWARD,FFTW_MEASURE); + p=fftwf_plan_dft_c2r_1d(bins,incomplex,outfft,FFTW_BACKWARD,FFTW_MEASURE); + + } + + //Copy samples to the fft + // CopySamples(infft,inreal,n/2); + // std::reverse_copy(inimag,inimag+n/2,infft+n/2); + + + /* + //why do we have to invert the samples??? + for (int i = n/2+1; i!=n;++i) + { + *(infft+i)=-*(infft+i); + } + */ + + for (int i=0;i!=n/2;++i) + { + incomplex[i][0]=inreal[i]; + incomplex[i][1]=-inimag[i]; + } + + //execute + fftwf_execute(p); + + CopySamples(out[0],outfft,n); + +} + -- cgit v1.2.1 From fc4811ceddd4d2138d01e78b1c002a1582f9ee69 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 30 Mar 2004 18:49:02 +0000 Subject: added him~ object svn path=/trunk/externals/tb/; revision=1525 --- tbext/config-pd-linux.txt | 8 +- tbext/him.pd | 42 +++++ tbext/make-files.txt | 6 +- tbext/source/him.cpp | 389 ++++++++++++++++++++++++++++++++++++++++++++++ tbext/source/main.cpp | 11 +- 5 files changed, 437 insertions(+), 19 deletions(-) create mode 100644 tbext/him.pd create mode 100644 tbext/source/him.cpp diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt index b1acfa1..a3697ef 100755 --- a/tbext/config-pd-linux.txt +++ b/tbext/config-pd-linux.txt @@ -10,7 +10,7 @@ PD=/usr/lib/pd # where are the PD header files? # leave it blank if it is a system directory (like /usr/local/include), # since gcc 3.2 complains about it -PDINC=/home/tim/pd/pd/src +PDINC=/home/tim/pd/pd-0.37-1test3/src #PDINC=/home/tim/pd/devel_0_36/pd/src # where do the flext libraries reside? @@ -29,13 +29,9 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) -UFLAGS=-g -xW -tpp7 -ip -ipo_obj # icc +UFLAGS=-xN -tpp7 -ip -ipo_obj # icc # UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 -#compile support for the fftw3 library -#make sure that you compiled fftw3 for single precision floats!!! -FFTW=1 - # define to link against shared flext library (flext version >= 0.5.0) FLEXT_SHARED=1 diff --git a/tbext/him.pd b/tbext/him.pd new file mode 100644 index 0000000..847f8ad --- /dev/null +++ b/tbext/him.pd @@ -0,0 +1,42 @@ +#N canvas 0 0 680 378 10; +#X obj 48 338 dac~; +#X msg 117 142 output \$1; +#X obj 117 120 hradio 15 1 0 6 empty empty empty 0 -6 0 8 -262144 -1 +-1 0; +#X msg 125 191 regtime \$1; +#X obj 125 169 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +1; +#X obj 51 15 hsl 128 15 1e-04 1 1 0 empty empty dt -2 -6 0 8 -262144 +-1 -1 0 0; +#X msg 48 37 dt \$1; +#X msg 80 84 e \$1; +#X obj 83 65 hsl 128 15 -1 0 0 0 empty empty etilde -2 -6 0 8 -262144 +-1 -1 0 0; +#X floatatom 122 85 5 0 0 0 - - -; +#X floatatom 106 40 5 0 0 0 - - -; +#X msg 158 224 reset; +#X msg 179 258 state; +#X obj 48 309 him~ -0.3; +#X text 216 123 switch beween mu \, muv \, nu \, nuv \, x and y; +#X text 224 66 set the etilde of the system if it's positive \, the +electron will leave the atom; +#X text 194 13 set the timesteps for the 4th order runge-kutta approximation +; +#X text 215 190 use the real or the regulated time; +#X text 218 223 randomize new values (warning! this may click!!!); +#X text 231 257 returns the state of the system; +#X text 128 308 the optional argument is the etilde of the system; +#X connect 1 0 13 0; +#X connect 2 0 1 0; +#X connect 3 0 13 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 5 0 10 0; +#X connect 6 0 13 0; +#X connect 7 0 13 0; +#X connect 8 0 7 0; +#X connect 8 0 9 0; +#X connect 11 0 13 0; +#X connect 12 0 13 0; +#X connect 13 0 0 0; +#X connect 13 0 0 1; diff --git a/tbext/make-files.txt b/tbext/make-files.txt index cf7bc8e..6140f01 100755 --- a/tbext/make-files.txt +++ b/tbext/make-files.txt @@ -3,11 +3,7 @@ SRCDIR = source SRCS= \ main.cpp tbroute.cpp tbsig~.cpp tbsroute~.cpp \ tbpow~.cpp tbfft1.cpp tbfft2.cpp fftbuf.cpp fftgrsort.cpp \ - fftgrshuf.cpp fftgrrev.cpp + fftgrshuf.cpp fftgrrev.cpp him.cpp -ifdef FFTW -SRCS+=fftw~.cpp ifftw~.cpp rfftw~.cpp rifftw~.cpp -endif - #HDRS= \ main.h diff --git a/tbext/source/him.cpp b/tbext/source/him.cpp new file mode 100644 index 0000000..5d1c029 --- /dev/null +++ b/tbext/source/him.cpp @@ -0,0 +1,389 @@ +/* Copyright (c) 2004 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* */ +/* him~ is a semi-classicical simulation of an hydrogen atom in a magnetic field*/ +/* */ +/* him~ uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* him~ is based on code provided in the lecture "physik auf dem computer 1" */ +/* held by joerg main during the winter semester 2003/04 at the university */ +/* stuttgart ... many thanks to him and his assistant ralf habel */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Elliott Sharp: The Velocity Of Hue */ +/* Fred Frith: Traffic Continues */ +/* Nmperign: Twisted Village */ +/* Frank Lowe: Black Beings */ +/* */ + + + +#include +#include +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) +#error upgrade your flext version!!!!!! +#endif + +#define NUMB_EQ 4 + +class him: public flext_dsp +{ + FLEXT_HEADER(him,flext_dsp); + +public: + him(int argc, t_atom *argv); + +protected: + virtual void m_signal (int n, float *const *in, float *const *out); + t_float *outs; + + void set_mu(t_float); + void set_muv(t_float); + void set_nu(t_float); + void set_nuv(t_float); + void set_etilde(t_float); + void set_dt(t_float); + void set_regtime(bool); + void set_output(t_int); + void state(); + void reset(); + +private: + // contains DGL-System + t_float deriv(t_float x[],int eq); + t_float result; + + // 4th order Runge Kutta update of the dynamical variables + void runge_kutta_4(t_float dt); + int i; + t_float k1[NUMB_EQ],k2[NUMB_EQ],k3[NUMB_EQ],k4[NUMB_EQ]; + t_float temp1[NUMB_EQ], temp2[NUMB_EQ], temp3[NUMB_EQ]; + + //these are our data + t_float data[4]; //mu, muv, nu, nuv (semi-parabolische koordinaten) + t_float E; + + //and these our settings + t_float dt; + t_int output; //mu, muv, nu, nuv, x, y + bool regtime; //if true "regularisierte zeit" + + //Callbacks + FLEXT_CALLBACK_1(set_mu,t_float); + FLEXT_CALLBACK_1(set_muv,t_float); + FLEXT_CALLBACK_1(set_nu,t_float); + FLEXT_CALLBACK_1(set_nuv,t_float); + FLEXT_CALLBACK_1(set_etilde,t_float); + FLEXT_CALLBACK_1(set_dt,t_float); + FLEXT_CALLBACK_1(set_regtime,bool); + FLEXT_CALLBACK_1(set_output,t_int); + FLEXT_CALLBACK(state); + FLEXT_CALLBACK(reset); + + //reset mus / nus + void reset_nuv() + { + data[3]= 0.5*sqrt( - (4*data[1]*data[1]) - + ( data[0]*data[0]*data[1]*data[1]*data[1]*data[1]) + + (8*E*data[0]) - (8*E*data[2]) - + (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + + 16); + } + + void reset_muv() + { + data[1]= 0.5*sqrt( - (4*data[3]*data[3]) - + ( data[0]*data[0]*data[1]*data[1]*data[1]*data[1]) + + (8*E*data[0]) - (8*E*data[2]) - + (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + + 16); + } + +}; + + +FLEXT_LIB_DSP_V("him~",him) + +him::him(int argc, t_atom *argv) +{ + AddInAnything(); + AddOutSignal(); + FLEXT_ADDMETHOD_F(0,"mu",set_mu); + FLEXT_ADDMETHOD_F(0,"muv",set_muv); + FLEXT_ADDMETHOD_F(0,"nu",set_nu); + FLEXT_ADDMETHOD_F(0,"nuv",set_nuv); + FLEXT_ADDMETHOD_F(0,"e",set_etilde); + FLEXT_ADDMETHOD_F(0,"dt",set_dt); + FLEXT_ADDMETHOD_B(0,"regtime",set_regtime); + FLEXT_ADDMETHOD_I(0,"output",set_output); + FLEXT_ADDMETHOD_(0,"state",state); + FLEXT_ADDMETHOD_(0,"reset",reset); + + + //beginning values + if (argc==1) + E=atom_getfloat(argv); + else + E= -float(rand())/float(RAND_MAX); + + reset(); + + state(); + + //default mode + regtime=true; + output=0; + dt=0.01; +} + +t_float him::deriv(t_float x[], int eq) +{ + // set DGL-System here + if (eq == 0) result = x[1]; + if (eq == 1) result = 2*E*x[0]-0.25*x[0]*x[2]*x[2]*(2*x[0]*x[0]+x[2]*x[2]); + if (eq == 2) result = x[3]; + if (eq == 3) result = 2*E*x[2]-0.25*x[2]*x[0]*x[0]*(2*x[2]*x[2]+x[0]*x[0]); + + return result; +} + +void him::runge_kutta_4(t_float dt) +{ + for(i=0;i<=NUMB_EQ-1;i++) // iterate over equations + { + k1[i] = dt * deriv(data,i); + temp1[i] = data[i] + 0.5*k1[i]; + } + + for(i=0;i<=NUMB_EQ-1;i++) + { + k2[i] = dt * deriv(temp1,i); + temp2[i] = data[i] + 0.5*k2[i]; + } + + for(i=0;i<=NUMB_EQ-1;i++) + { + k3[i] = dt * deriv(temp2,i); + temp3[i] = data[i] + k3[i]; + } + + for(i=0;i<=NUMB_EQ-1;i++) + { + k4[i] = dt * deriv(temp3,i); + data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; + } + + reset_muv; + +} + + + +void him::m_signal(int n, t_float *const *in, t_float *const *out) +{ + outs = out[0]; + + if (regtime) + { + switch (output) + { + case 0: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt); + *(outs+j)=data[0]; + } + break; + + case 1: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt); + *(outs+j)=data[1]; + } + break; + + case 2: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt); + *(outs+j)=data[2]; + } + break; + + case 3: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt); + *(outs+j)=data[3]; + } + break; + + case 4: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt); + *(outs+j)=data[0]*data[2]; + } + break; + + case 5: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt); + *(outs+j)=(data[0]*data[0]-data[2]*data[2])*0.5; + } + break; + } + } + else + { + switch (output) + { + case 0: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(outs+j)=data[0]; + } + break; + + case 1: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(outs+j)=data[1]; + } + break; + + case 2: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(outs+j)=data[2]; + } + break; + + case 3: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(outs+j)=data[3]; + } + break; + + case 4: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(outs+j)=data[0]*data[2]; + } + break; + + case 5: + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(outs+j)=(data[0]*data[0]-data[2]*data[2])*0.5; + } + break; + } + } +} + +void him::set_mu(t_float f) +{ + data[0]=f; + reset_nuv; +} + +void him::set_muv(t_float f) +{ + data[1]=f; + reset_nuv; +} + +void him::set_nu(t_float f) +{ + data[3]=f; + reset_nuv; +} + +void him::set_nuv(t_float f) +{ + data[3]=f; + reset_muv; + post("resetting muv!!!"); +} + +void him::set_etilde(t_float f) +{ + E=f; + reset_nuv; +} + +void him::set_dt(t_float f) +{ + dt=f; +} + +void him::set_regtime(bool b) +{ + regtime=b; +} + +void him::set_output(t_int i) +{ + output=i; +} + +void him::state() +{ + post("mu %f",data[0]); + post("mus %f",data[1]); + post("nu %f",data[2]); + post("nus %f",data[3]); + post("etilde %f",E); +} + +void him::reset() +{ + data[0]=float(rand())/float(RAND_MAX); + data[1]=float(rand())/float(RAND_MAX); + data[2]=float(rand())/float(RAND_MAX); + reset_muv; + post("randomizing values"); +} diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index 07a0713..bb7c517 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -40,7 +40,7 @@ #include -#define TBEXT_VERSION "0.04" +#define TBEXT_VERSION "0.05" #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) #error upgrade your flext version!!!!!! @@ -52,11 +52,10 @@ void ttbext_setup() post("version "TBEXT_VERSION); post("compiled on "__DATE__); post("contains: tbroute(~), tbsig~, tbpow~, tbfft1~, tbfft2~, bufline~, fftgrrev~"); - post(" fftgrsort~, fftgrshuf~, rfftw~, rifftw~"); + post(" fftgrsort~, fftgrshuf~, him~"); FLEXT_SETUP(tbroute); FLEXT_DSP_SETUP(tbsroute); - // FLEXT_DSP_SETUP(tbssel); FLEXT_DSP_SETUP(tbsig); FLEXT_DSP_SETUP(tbpow); // FLEXT_DSP_SETUP(tbg7xx); @@ -66,13 +65,9 @@ void ttbext_setup() FLEXT_DSP_SETUP(fftgrsort); FLEXT_DSP_SETUP(fftgrshuf); FLEXT_DSP_SETUP(fftgrrev); + FLEXT_DSP_SETUP(him); -#if (FFTW == 1) - FLEXT_DSP_SETUP(rfftw); - FLEXT_DSP_SETUP(rifftw); -#endif - } -- cgit v1.2.1 From 092e3f239e8108d161ad03fb7047d51853dd0008 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 31 Mar 2004 11:44:38 +0000 Subject: bug fixed ... now it compiles with gcc, too svn path=/trunk/externals/tb/; revision=1527 --- tbext/source/him.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tbext/source/him.cpp b/tbext/source/him.cpp index 5d1c029..169e4ad 100644 --- a/tbext/source/him.cpp +++ b/tbext/source/him.cpp @@ -200,7 +200,7 @@ void him::runge_kutta_4(t_float dt) data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; } - reset_muv; + reset_muv(); } @@ -327,32 +327,32 @@ void him::m_signal(int n, t_float *const *in, t_float *const *out) void him::set_mu(t_float f) { data[0]=f; - reset_nuv; + reset_nuv(); } void him::set_muv(t_float f) { data[1]=f; - reset_nuv; + reset_nuv(); } void him::set_nu(t_float f) { data[3]=f; - reset_nuv; + reset_nuv(); } void him::set_nuv(t_float f) { data[3]=f; - reset_muv; + reset_muv(); post("resetting muv!!!"); } void him::set_etilde(t_float f) { E=f; - reset_nuv; + reset_nuv(); } void him::set_dt(t_float f) @@ -384,6 +384,6 @@ void him::reset() data[0]=float(rand())/float(RAND_MAX); data[1]=float(rand())/float(RAND_MAX); data[2]=float(rand())/float(RAND_MAX); - reset_muv; + reset_muv(); post("randomizing values"); } -- cgit v1.2.1 From 604a3ed6ad86c5e25f1a904c012639f821c4d999 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 9 Apr 2004 13:42:58 +0000 Subject: some updates svn path=/trunk/externals/tb/; revision=1589 --- tbext/him.pd | 73 ++++++++++++++---------- tbext/source/him.cpp | 153 ++++++++++++--------------------------------------- 2 files changed, 80 insertions(+), 146 deletions(-) diff --git a/tbext/him.pd b/tbext/him.pd index 847f8ad..7e15881 100644 --- a/tbext/him.pd +++ b/tbext/him.pd @@ -1,42 +1,57 @@ #N canvas 0 0 680 378 10; #X obj 48 338 dac~; -#X msg 117 142 output \$1; -#X obj 117 120 hradio 15 1 0 6 empty empty empty 0 -6 0 8 -262144 -1 --1 0; -#X msg 125 191 regtime \$1; -#X obj 125 169 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 +#X msg 125 144 regtime \$1; +#X obj 125 122 tgl 15 1 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1; #X obj 51 15 hsl 128 15 1e-04 1 1 0 empty empty dt -2 -6 0 8 -262144 --1 -1 0 0; +-1 -1 10400 0; #X msg 48 37 dt \$1; #X msg 80 84 e \$1; #X obj 83 65 hsl 128 15 -1 0 0 0 empty empty etilde -2 -6 0 8 -262144 --1 -1 0 0; +-1 -1 6000 0; #X floatatom 122 85 5 0 0 0 - - -; #X floatatom 106 40 5 0 0 0 - - -; -#X msg 158 224 reset; -#X msg 179 258 state; +#X msg 158 177 reset; +#X msg 179 211 state; #X obj 48 309 him~ -0.3; -#X text 216 123 switch beween mu \, muv \, nu \, nuv \, x and y; -#X text 224 66 set the etilde of the system if it's positive \, the -electron will leave the atom; #X text 194 13 set the timesteps for the 4th order runge-kutta approximation ; -#X text 215 190 use the real or the regulated time; -#X text 218 223 randomize new values (warning! this may click!!!); -#X text 231 257 returns the state of the system; -#X text 128 308 the optional argument is the etilde of the system; -#X connect 1 0 13 0; +#X text 215 143 use the real or the regulated time; +#X text 218 176 randomize new values (warning! this may click!!!); +#X text 231 210 returns the state of the system; +#X text 224 66 set the etilde of the system if it's positive \, the +electron will leave the atom (if you change it during dsp computation +\, it will click); +#X text 128 308 the optional argument is the etilde of the system returns +mu \, mu velocity \, nu \, nu velocity \, x and y. Based on physical +models of an atom in a magnetic field...; +#X obj 608 207 loadbang; +#X msg 608 271 muv 1.22293; +#X msg 608 292 nu -0.065661 \;; +#X msg 607 252 mu -1.43572 \;; +#X obj 608 228 t b b; +#X msg 608 318 \; pd dsp 1; +#X connect 1 0 11 0; #X connect 2 0 1 0; -#X connect 3 0 13 0; -#X connect 4 0 3 0; -#X connect 5 0 6 0; -#X connect 5 0 10 0; -#X connect 6 0 13 0; -#X connect 7 0 13 0; -#X connect 8 0 7 0; -#X connect 8 0 9 0; -#X connect 11 0 13 0; -#X connect 12 0 13 0; -#X connect 13 0 0 0; -#X connect 13 0 0 1; +#X connect 3 0 4 0; +#X connect 3 0 8 0; +#X connect 4 0 11 0; +#X connect 5 0 11 0; +#X connect 6 0 5 0; +#X connect 6 0 7 0; +#X connect 9 0 11 0; +#X connect 10 0 11 0; +#X connect 11 0 0 0; +#X connect 11 1 0 1; +#X connect 11 2 0 0; +#X connect 11 3 0 1; +#X connect 11 4 0 0; +#X connect 11 5 0 1; +#X connect 18 0 22 0; +#X connect 19 0 11 0; +#X connect 20 0 11 0; +#X connect 21 0 11 0; +#X connect 22 0 23 0; +#X connect 22 1 21 0; +#X connect 22 1 19 0; +#X connect 22 1 20 0; diff --git a/tbext/source/him.cpp b/tbext/source/him.cpp index 169e4ad..4c6c62e 100644 --- a/tbext/source/him.cpp +++ b/tbext/source/him.cpp @@ -71,7 +71,6 @@ protected: void set_etilde(t_float); void set_dt(t_float); void set_regtime(bool); - void set_output(t_int); void state(); void reset(); @@ -92,7 +91,6 @@ private: //and these our settings t_float dt; - t_int output; //mu, muv, nu, nuv, x, y bool regtime; //if true "regularisierte zeit" //Callbacks @@ -103,7 +101,6 @@ private: FLEXT_CALLBACK_1(set_etilde,t_float); FLEXT_CALLBACK_1(set_dt,t_float); FLEXT_CALLBACK_1(set_regtime,bool); - FLEXT_CALLBACK_1(set_output,t_int); FLEXT_CALLBACK(state); FLEXT_CALLBACK(reset); @@ -135,6 +132,11 @@ him::him(int argc, t_atom *argv) { AddInAnything(); AddOutSignal(); + AddOutSignal(); + AddOutSignal(); + AddOutSignal(); + AddOutSignal(); + AddOutSignal(); FLEXT_ADDMETHOD_F(0,"mu",set_mu); FLEXT_ADDMETHOD_F(0,"muv",set_muv); FLEXT_ADDMETHOD_F(0,"nu",set_nu); @@ -142,7 +144,6 @@ him::him(int argc, t_atom *argv) FLEXT_ADDMETHOD_F(0,"e",set_etilde); FLEXT_ADDMETHOD_F(0,"dt",set_dt); FLEXT_ADDMETHOD_B(0,"regtime",set_regtime); - FLEXT_ADDMETHOD_I(0,"output",set_output); FLEXT_ADDMETHOD_(0,"state",state); FLEXT_ADDMETHOD_(0,"reset",reset); @@ -159,7 +160,6 @@ him::him(int argc, t_atom *argv) //default mode regtime=true; - output=0; dt=0.01; } @@ -199,8 +199,18 @@ void him::runge_kutta_4(t_float dt) k4[i] = dt * deriv(temp3,i); data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; } - - reset_muv(); + + + /* + the system might become unstable ... in this case, we'll reset the system + */ + + for(i=0;i<=NUMB_EQ-1;i++) + if(data[i]>2) + reset(); + else + if(PD_BADFLOAT(data[i])) //not that we get some troubles with denormals + data[i]=0; } @@ -208,118 +218,31 @@ void him::runge_kutta_4(t_float dt) void him::m_signal(int n, t_float *const *in, t_float *const *out) { - outs = out[0]; - if (regtime) { - switch (output) + for (int j=0;j!=n;++j) { - case 0: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(outs+j)=data[0]; - } - break; - - case 1: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(outs+j)=data[1]; - } - break; - - case 2: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(outs+j)=data[2]; - } - break; - - case 3: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(outs+j)=data[3]; - } - break; - - case 4: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(outs+j)=data[0]*data[2]; - } - break; - - case 5: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(outs+j)=(data[0]*data[0]-data[2]*data[2])*0.5; - } - break; + runge_kutta_4(dt); + *(out[0]+j)=data[0]; + *(out[1]+j)=data[1]; + *(out[2]+j)=data[2]; + *(out[3]+j)=data[3]; + *(out[4]+j)=data[0]*data[2]; + *(out[5]+j)=(data[0]*data[0]-data[2]*data[2])*0.5; } } else { - switch (output) - { - case 0: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(outs+j)=data[0]; - } - break; - - case 1: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(outs+j)=data[1]; - } - break; - - case 2: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(outs+j)=data[2]; - } - break; - - case 3: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(outs+j)=data[3]; - } - break; - - case 4: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(outs+j)=data[0]*data[2]; - } - break; - - case 5: - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(outs+j)=(data[0]*data[0]-data[2]*data[2])*0.5; - } - break; + for (int j=0;j!=n;++j) + { + runge_kutta_4(dt/ + (2*sqrt(data[0]*data[0]+data[2]*data[2]))); + *(out[0]+j)=data[0]; + *(out[1]+j)=data[1]; + *(out[2]+j)=data[2]; + *(out[3]+j)=data[3]; + *(out[4]+j)=data[0]*data[2]; + *(out[5]+j)=(data[0]*data[0]-data[2]*data[2])*0.5; } } } @@ -365,10 +288,6 @@ void him::set_regtime(bool b) regtime=b; } -void him::set_output(t_int i) -{ - output=i; -} void him::state() { @@ -384,6 +303,6 @@ void him::reset() data[0]=float(rand())/float(RAND_MAX); data[1]=float(rand())/float(RAND_MAX); data[2]=float(rand())/float(RAND_MAX); - reset_muv(); + reset_nuv(); post("randomizing values"); } -- cgit v1.2.1 From b02a1e9aee38e588e6d4430d0e84a9e736c2b0f0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 13 Jul 2004 20:00:39 +0000 Subject: minor changes svn path=/trunk/externals/tb/; revision=1852 --- tbext/config-pd-linux.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt index a3697ef..48f327a 100755 --- a/tbext/config-pd-linux.txt +++ b/tbext/config-pd-linux.txt @@ -16,14 +16,14 @@ PDINC=/home/tim/pd/pd-0.37-1test3/src # where do the flext libraries reside? FLEXTPATH=/usr/lib/flext -# where should xsample objects be built? +# where should tbext objects be built? TARGDIR=./pd-linux -# where should xsample be installed? +# where should tbext be installed? # (leave blank to omit installation) INSTDIR=${PD}/externs -# where should the xsample help be installed? +# where should the tbext help be installed? # (leave blank to omit installation) HELPDIR=${PD}/doc/5.reference -- cgit v1.2.1 From 5e7742116ef3b268823d43d26dab3239e4472dcf Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 13 Jul 2004 20:01:49 +0000 Subject: adapted thomas' build system svn path=/trunk/externals/tb/; revision=1853 --- tbext/build-max-msvc.bat | 4 +++ tbext/build-pd-bcc.bat | 3 ++ tbext/build-pd-cygwin.sh | 15 ++++++++ tbext/build-pd-darwin.sh | 17 +++++++++ tbext/build-pd-linux.sh | 17 +++++++++ tbext/build-pd-mingw.bat | 3 ++ tbext/build-pd-msvc.bat | 4 +++ tbext/config-max-msvc.txt | 27 +++++++++++++++ tbext/config-pd-bcc.txt | 23 +++++++++++++ tbext/config-pd-cygwin.txt | 35 +++++++++++++++++++ tbext/config-pd-darwin.txt | 35 +++++++++++++++++++ tbext/config-pd-mingw.txt | 35 +++++++++++++++++++ tbext/config-pd-msvc.txt | 19 ++++++++++ tbext/makefile.pd-cygwin | 86 ++++++++++++++++++++++++++++++++++++++++++++++ tbext/makefile.pd-darwin | 77 +++++++++++++++++++++++++++++++++++++++++ tbext/makefile.pd-mingw | 85 +++++++++++++++++++++++++++++++++++++++++++++ tbext/makefile.pd-msvc | 53 ++++++++++++++++++++++++++++ 17 files changed, 538 insertions(+) create mode 100644 tbext/build-max-msvc.bat create mode 100644 tbext/build-pd-bcc.bat create mode 100644 tbext/build-pd-cygwin.sh create mode 100755 tbext/build-pd-darwin.sh create mode 100755 tbext/build-pd-linux.sh create mode 100644 tbext/build-pd-mingw.bat create mode 100644 tbext/build-pd-msvc.bat create mode 100644 tbext/config-max-msvc.txt create mode 100644 tbext/config-pd-bcc.txt create mode 100644 tbext/config-pd-cygwin.txt create mode 100755 tbext/config-pd-darwin.txt create mode 100644 tbext/config-pd-mingw.txt create mode 100644 tbext/config-pd-msvc.txt create mode 100644 tbext/makefile.pd-cygwin create mode 100755 tbext/makefile.pd-darwin create mode 100644 tbext/makefile.pd-mingw create mode 100644 tbext/makefile.pd-msvc diff --git a/tbext/build-max-msvc.bat b/tbext/build-max-msvc.bat new file mode 100644 index 0000000..130a3bc --- /dev/null +++ b/tbext/build-max-msvc.bat @@ -0,0 +1,4 @@ +@echo --- Building with MS Visual C++ --- + +nmake -f makefile.max-msvc clean +nmake -f makefile.max-msvc diff --git a/tbext/build-pd-bcc.bat b/tbext/build-pd-bcc.bat new file mode 100644 index 0000000..3dd2132 --- /dev/null +++ b/tbext/build-pd-bcc.bat @@ -0,0 +1,3 @@ +@echo --- Building with BorlandC++ --- + +make -f makefile.pd-bcc diff --git a/tbext/build-pd-cygwin.sh b/tbext/build-pd-cygwin.sh new file mode 100644 index 0000000..9477844 --- /dev/null +++ b/tbext/build-pd-cygwin.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +SYS=pd-cygwin + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + make -f makefile.${SYS} install + fi + if [ $HELPDIR != "" ]; then + make -f makefile.${SYS} install-help + fi +} diff --git a/tbext/build-pd-darwin.sh b/tbext/build-pd-darwin.sh new file mode 100755 index 0000000..38814a9 --- /dev/null +++ b/tbext/build-pd-darwin.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +SYS=pd-darwin + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + echo Now install as root + sudo make -f makefile.${SYS} install + fi + if [ $HELPDIR != "" ]; then + echo Now install help as root + sudo make -f makefile.${SYS} install-help + fi +} diff --git a/tbext/build-pd-linux.sh b/tbext/build-pd-linux.sh new file mode 100755 index 0000000..77c6e3f --- /dev/null +++ b/tbext/build-pd-linux.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +SYS=pd-linux + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + echo Now install as root + su -c "make -f makefile.${SYS} install" + fi + if [ $HELPDIR != "" ]; then + echo Now install help as root + su -c "make -f makefile.${SYS} install-help" + fi +} diff --git a/tbext/build-pd-mingw.bat b/tbext/build-pd-mingw.bat new file mode 100644 index 0000000..fa8919a --- /dev/null +++ b/tbext/build-pd-mingw.bat @@ -0,0 +1,3 @@ +mingw32-make -f makefile.pd-mingw +mingw32-make -f makefile.pd-mingw install +mingw32-make -f makefile.pd-mingw install-help diff --git a/tbext/build-pd-msvc.bat b/tbext/build-pd-msvc.bat new file mode 100644 index 0000000..d6187f0 --- /dev/null +++ b/tbext/build-pd-msvc.bat @@ -0,0 +1,4 @@ +@echo --- Building with MS Visual C++ --- + +nmake -f makefile.pd-msvc clean +nmake -f makefile.pd-msvc diff --git a/tbext/config-max-msvc.txt b/tbext/config-max-msvc.txt new file mode 100644 index 0000000..e2a0477 --- /dev/null +++ b/tbext/config-max-msvc.txt @@ -0,0 +1,27 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile +# + +# where is the Max SDK? +# you should have the latest version! +MAXSDKPATH="F:\prog\audio\MaxWinSDK\c74support" + +# where do the flext libraries reside? +FLEXTPATH="%CommonProgramFiles%\Cycling '74\flext" + +# where is MS VC++? +# (need not be defined if the build is started with the compiler environment set) +# MSVCPATH="c:\programme\prog\microsoft visual studio\VC98" + + +# where should the external be built? +# (path for temporary files) +OUTPATH=max-msvc + +# where should the external be installed? +# (leave blank to omit installation) +INSTPATH="%CommonProgramFiles%\Cycling '74\externals\flext" + + +# some user-definable flags +# (check if they match your system!) +UFLAGS=/G6 /arch:SSE diff --git a/tbext/config-pd-bcc.txt b/tbext/config-pd-bcc.txt new file mode 100644 index 0000000..3b9eb52 --- /dev/null +++ b/tbext/config-pd-bcc.txt @@ -0,0 +1,23 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile +# + +# where is PD? +PDPATH=c:\programme\audio\pd + +# where do the flext libraries reside? +FLEXTPATH=$(PDPATH)\flext + +# where is BorlandC++? +BCCPATH=c:\programme\prog\bcc55 + +# where should the external(s) be built? +OUTPATH=.\pd-bcc + +# should the external be installed? (yes/no) +INSTALL=yes + +# where should the external be installed? +INSTDIR=$(PDPATH)\extra + +# additional compiler flags +UFLAGS=-6 -O2 -OS -ff diff --git a/tbext/config-pd-cygwin.txt b/tbext/config-pd-cygwin.txt new file mode 100644 index 0000000..17af1b9 --- /dev/null +++ b/tbext/config-pd-cygwin.txt @@ -0,0 +1,35 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (define only if it's different than g++) +# CXX=g++ + +# where does the PD installation reside? +PD=/cygdrive/c/programme/audio/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should tbext objects be built? +TARGDIR=./pd-cygwin + +# where should tbext be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the tbext help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-mcpu=pentium4 -msse -mfpmath=sse # gcc 3.2 +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 + +# define to build with shared flext library +#FLEXT_SHARED=1 diff --git a/tbext/config-pd-darwin.txt b/tbext/config-pd-darwin.txt new file mode 100755 index 0000000..2a5441f --- /dev/null +++ b/tbext/config-pd-darwin.txt @@ -0,0 +1,35 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (if not g++) +#CXX=g++-3.3 + +# where does the PD installation reside? +PD=/usr/local/lib/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where is the PD executable? +PDBIN=/usr/local/bin/pd + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should the tbext objects be built? +TARGDIR=./pd-darwin + +# where should tbext be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the tbext help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit your system!) +UFLAGS=-malign-power -maltivec -faltivec + diff --git a/tbext/config-pd-mingw.txt b/tbext/config-pd-mingw.txt new file mode 100644 index 0000000..cbe445c --- /dev/null +++ b/tbext/config-pd-mingw.txt @@ -0,0 +1,35 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (define only if it's different than g++) +# CXX=g++ + +# where does the PD installation reside? +PD=c:/programme/audio/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should tbext objects be built? +TARGDIR=./pd-mingw + +# where should tbext be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the tbext help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-mcpu=pentium4 -msse -mfpmath=sse # gcc 3.2 +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 + +# define to build with shared flext library +# FLEXT_SHARED=1 \ No newline at end of file diff --git a/tbext/config-pd-msvc.txt b/tbext/config-pd-msvc.txt new file mode 100644 index 0000000..fb48585 --- /dev/null +++ b/tbext/config-pd-msvc.txt @@ -0,0 +1,19 @@ +# config file for tbext, adapted from Thomas Grill's xsample makefile +# + +# where is PD? +PDPATH=c:\programme\audio\pd + +# where do the flext libraries reside? +FLEXTPATH=$(PDPATH)\flext + +# where is MS VC++? +# (not necessary if the build started with the compiler environment) +# MSVCPATH=c:\programme\prog\microsoft visual studio\VC98 + +# where should the external be built? +OUTPATH=pd-msvc + +# where should the external be installed? +# (leave blank to omit installation) +INSTDIR=$(PDPATH)\extra diff --git a/tbext/makefile.pd-cygwin b/tbext/makefile.pd-cygwin new file mode 100644 index 0000000..9b8a9f8 --- /dev/null +++ b/tbext/makefile.pd-cygwin @@ -0,0 +1,86 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ cygwin +# +# usage: +# to build run "make -f makefile.pd-cygwin" +# to install (as root), do "make -f makefile.pd-cygwin install" +# + +CONFIG=config-pd-cygwin.txt +MAKEFILE=makefile.pd-cygwin + +include ${CONFIG} + + +# compiler stuff +# /usr/include holds the cygwin pthread headers and must be first! +INCLUDES=/usr/include $(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang + +FLAGS=-DFLEXT_SYS=2 +CFLAGS=-O2 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions ${UFLAGS} + +PDLIBS=$(PD)/bin/pd.dll $(PD)/bin/pthreadVC.dll + + +ifdef FLEXT_SHARED + +CFLAGS+=-DFLEXT_SHARED +FLEXTLIB=$(FLEXTPATH)/flext.dll + +else + +FLEXTLIB=$(FLEXTPATH)/flext-pdwin.lib + +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=tbext + +include make-files.txt + +TARGET=$(TARGDIR)/$(NAME).dll + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) -shared $(LDFLAGS) $^ ${PDLIBS} $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) +# chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) diff --git a/tbext/makefile.pd-darwin b/tbext/makefile.pd-darwin new file mode 100755 index 0000000..9b6af4e --- /dev/null +++ b/tbext/makefile.pd-darwin @@ -0,0 +1,77 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ OSX (darwin) +# +# usage: +# to build run "make -f makefile.pd-darwin" +# to install (as root), do "make -f makefile.pd-darwin install" +# to install help, do "make -f makefile.pd-darwin install-help" +# + +CONFIG=config-pd-darwin.txt + +include ${CONFIG} + +FLEXTLIB=$(FLEXTPATH)/libflext.a + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang +FLAGS=-DFLEXT_SYS=2 +CFLAGS=${UFLAGS} -dynamic -O2 -Wno-unused -Wno-parentheses -Wno-switch -Wstrict-prototypes -funroll-loops -fmove-all-movables -frerun-loop-opt -fno-rtti -fno-exceptions +LIBS=m gcc +LDFLAGS=$(FLEXTLIB) -bundle -bundle_loader $(PDBIN) +FRAMEWORKS=Carbon veclib + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=tbext + +include make-files.txt + +MAKEFILE=makefile.pd-darwin +TARGET=$(TARGDIR)/$(NAME).pd_darwin + + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) + $(CXX) $(LDFLAGS) $^ $(patsubst %,-framework %,$(FRAMEWORKS)) $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(LIBS)) -o $@ + chmod 755 $@ + + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp -R $^ $(INSTDIR) +# chown -R root.root $(INSTDIR) + + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + cp $^/*.* $(HELPDIR) +# chown -R root.root $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) + diff --git a/tbext/makefile.pd-mingw b/tbext/makefile.pd-mingw new file mode 100644 index 0000000..065930e --- /dev/null +++ b/tbext/makefile.pd-mingw @@ -0,0 +1,85 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ minGW +# +# usage: +# to build run "make -f makefile.pd-mingw" +# to install (as root), do "make -f makefile.pd-mingw install" +# + +CONFIG=config-pd-mingw.txt +MAKEFILE=makefile.pd-mingw + +include ${CONFIG} + + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang + +FLAGS=-DFLEXT_SYS=2 +CFLAGS=-O2 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions ${UFLAGS} + +PDLIBS=$(PD)/bin/pd.dll $(PD)/bin/pthreadVC.dll + + +ifdef FLEXT_SHARED + +CFLAGS+=-DFLEXT_SHARED +FLEXTLIB=$(FLEXTPATH)/flext.dll + +else + +FLEXTLIB=$(FLEXTPATH)/flext-pdwin.lib + +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=tbext + +include make-files.txt + +TARGET=$(TARGDIR)/$(NAME).dll + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) +# echo touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) # minGW has no touch + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) -shared $(LDFLAGS) $^ ${PDLIBS} $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) +# chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) diff --git a/tbext/makefile.pd-msvc b/tbext/makefile.pd-msvc new file mode 100644 index 0000000..776ab09 --- /dev/null +++ b/tbext/makefile.pd-msvc @@ -0,0 +1,53 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for MSVC++ 6 +# +# usage: +# to build run "make -f makefile.pd-msvc" +# + +!include config-pd-msvc.txt + +# includes +INCPATH=/I"$(MSVCPATH)\include" /I"$(PDPATH)\src" /I"$(FLEXTPATH)" /I"./headers/plugin_interface" /I"./headers/common" /I"/headers/server" /I"./headers/app" /I"./headers/lang +LIBPATH=/LIBPATH:"$(MSVCPATH)\lib" /LIBPATH:"$(PDPATH)\bin" /LIBPATH:"$(FLEXTPATH)" +LIBS=pd.lib pthreadVC.lib flext-pdwin.lib + +# compiler definitions and flags +DEFS=/DFLEXT_SYS=2 + +CFLAGS=/GR- /GX- /GD /G6 /Ox /EHsc /ML + +# the rest can stay untouched +# ---------------------------------------------- + +NAME=tbext + +!include make-files.txt + + +all: $(OUTPATH) $(OUTPATH)\$(NAME).dll + +# remove build +clean: + -del /q $(OUTPATH) > nul + -rmdir $(OUTPATH) > nul + +OBJS= $(SRCS:.cpp=.obj) + +$(OUTPATH): + -mkdir $(OUTPATH) > nul + +{$(SRCDIR)}.cpp{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)\$@ + +$(OUTPATH)\$(NAME).dll: $(OBJS) + cd $(OUTPATH) + link /DLL /out:$(NAME).dll /INCREMENTAL:NO $** $(LIBS) $(LIBPATH) + @-del *.exp + @-del *.lib + cd .. +!ifdef INSTPATH + @-if not exist $(INSTPATH) mkdir $(INSTPATH) + copy $@ $(INSTPATH) > nul +!endif -- cgit v1.2.1 From d25a145c5e18d32a43e60ea7be9c621bac83badf Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 13 Jul 2004 20:04:52 +0000 Subject: hopefully a speedup svn path=/trunk/externals/tb/; revision=1854 --- tbext/source/him.cpp | 124 ++++++++++++++++++++++++++++----------------------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/tbext/source/him.cpp b/tbext/source/him.cpp index 4c6c62e..c6b1593 100644 --- a/tbext/source/him.cpp +++ b/tbext/source/him.cpp @@ -62,7 +62,6 @@ public: protected: virtual void m_signal (int n, float *const *in, float *const *out); - t_float *outs; void set_mu(t_float); void set_muv(t_float); @@ -77,13 +76,9 @@ protected: private: // contains DGL-System t_float deriv(t_float x[],int eq); - t_float result; // 4th order Runge Kutta update of the dynamical variables void runge_kutta_4(t_float dt); - int i; - t_float k1[NUMB_EQ],k2[NUMB_EQ],k3[NUMB_EQ],k4[NUMB_EQ]; - t_float temp1[NUMB_EQ], temp2[NUMB_EQ], temp3[NUMB_EQ]; //these are our data t_float data[4]; //mu, muv, nu, nuv (semi-parabolische koordinaten) @@ -112,8 +107,10 @@ private: + (8*E*data[0]) - (8*E*data[2]) - (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + 16); + if (fabs((data[3]))<1e-5) + data[3]=0; } - + void reset_muv() { data[1]= 0.5*sqrt( - (4*data[3]*data[3]) - @@ -121,6 +118,8 @@ private: + (8*E*data[0]) - (8*E*data[2]) - (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + 16); + if (fabs((data[1]))<1e-5) + data[1]=0; } }; @@ -163,9 +162,10 @@ him::him(int argc, t_atom *argv) dt=0.01; } -t_float him::deriv(t_float x[], int eq) +inline t_float him::deriv(t_float * x, int eq) { - // set DGL-System here + t_float result; + // set DGL-System here if (eq == 0) result = x[1]; if (eq == 1) result = 2*E*x[0]-0.25*x[0]*x[2]*x[2]*(2*x[0]*x[0]+x[2]*x[2]); if (eq == 2) result = x[3]; @@ -174,77 +174,89 @@ t_float him::deriv(t_float x[], int eq) return result; } -void him::runge_kutta_4(t_float dt) +inline void him::runge_kutta_4(t_float dt) { - for(i=0;i<=NUMB_EQ-1;i++) // iterate over equations - { - k1[i] = dt * deriv(data,i); - temp1[i] = data[i] + 0.5*k1[i]; - } + t_float k1[NUMB_EQ],k2[NUMB_EQ],k3[NUMB_EQ],k4[NUMB_EQ]; + t_float temp1[NUMB_EQ], temp2[NUMB_EQ], temp3[NUMB_EQ]; - for(i=0;i<=NUMB_EQ-1;i++) - { - k2[i] = dt * deriv(temp1,i); - temp2[i] = data[i] + 0.5*k2[i]; - } + for(int i=0;i<=NUMB_EQ-1;i++) // iterate over equations + { + k1[i] = dt * deriv(data,i); + temp1[i] = data[i] + 0.5*k1[i]; + } - for(i=0;i<=NUMB_EQ-1;i++) - { - k3[i] = dt * deriv(temp2,i); - temp3[i] = data[i] + k3[i]; - } + for(int i=0;i<=NUMB_EQ-1;i++) + { + k2[i] = dt * deriv(temp1,i); + temp2[i] = data[i] + 0.5*k2[i]; + } - for(i=0;i<=NUMB_EQ-1;i++) - { - k4[i] = dt * deriv(temp3,i); - data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; - } + for(int i=0;i<=NUMB_EQ-1;i++) + { + k3[i] = dt * deriv(temp2,i); + temp3[i] = data[i] + k3[i]; + } + + for(int i=0;i<=NUMB_EQ-1;i++) + { + k4[i] = dt * deriv(temp3,i); + data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; + + // we don't want to experience denormals in the next step */ + if(fabs((data[i]))<1e-5) + data[i]=0; + } - + /* the system might become unstable ... in this case, we'll reset the system */ - for(i=0;i<=NUMB_EQ-1;i++) + for(int i=0;i<=NUMB_EQ-1;i++) + { if(data[i]>2) reset(); - else - if(PD_BADFLOAT(data[i])) //not that we get some troubles with denormals - data[i]=0; - + } } void him::m_signal(int n, t_float *const *in, t_float *const *out) { + t_float * out0 = out[0]; + t_float * out1 = out[1]; + t_float * out2 = out[2]; + t_float * out3 = out[3]; + t_float * out4 = out[4]; + t_float * out5 = out[5]; + + if (regtime) + { + for (int j=0;j!=n;++j) { - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt); - *(out[0]+j)=data[0]; - *(out[1]+j)=data[1]; - *(out[2]+j)=data[2]; - *(out[3]+j)=data[3]; - *(out[4]+j)=data[0]*data[2]; - *(out[5]+j)=(data[0]*data[0]-data[2]*data[2])*0.5; - } + runge_kutta_4(dt); + (*(out0)++)=data[0]; + (*(out1)++)=data[1]; + (*(out2)++)=data[2]; + (*(out3)++)=data[3]; + (*(out4)++)=data[0]*data[2]; + (*(out5)++)=(data[0]*data[0]-data[2]*data[2])*0.5; } + } else + { + for (int j=0;j!=n;++j) { - for (int j=0;j!=n;++j) - { - runge_kutta_4(dt/ - (2*sqrt(data[0]*data[0]+data[2]*data[2]))); - *(out[0]+j)=data[0]; - *(out[1]+j)=data[1]; - *(out[2]+j)=data[2]; - *(out[3]+j)=data[3]; - *(out[4]+j)=data[0]*data[2]; - *(out[5]+j)=(data[0]*data[0]-data[2]*data[2])*0.5; - } + runge_kutta_4(dt/(2*sqrt(data[0]*data[0]+data[2]*data[2]))); + (*(out0)++)=data[0]; + (*(out1)++)=data[1]; + (*(out2)++)=data[2]; + (*(out3)++)=data[3]; + (*(out4)++)=data[0]*data[2]; + (*(out5)++)=(data[0]*data[0]-data[2]*data[2])*0.5; } + } } void him::set_mu(t_float f) -- cgit v1.2.1 From 07468876d7ad699977fd3f67d708dfe90a9d1626 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 13 Jul 2004 20:06:10 +0000 Subject: cleanup svn path=/trunk/externals/tb/; revision=1855 --- tbext/source/tbfft2.cpp | 93 ++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/tbext/source/tbfft2.cpp b/tbext/source/tbfft2.cpp index 99d16fe..1ab08db 100644 --- a/tbext/source/tbfft2.cpp +++ b/tbext/source/tbfft2.cpp @@ -49,35 +49,28 @@ class tbfft2: public flext_dsp { - FLEXT_HEADER(tbfft2,flext_dsp); - + FLEXT_HEADER(tbfft2,flext_dsp); + public: // constructor - tbfft2(); + tbfft2(); + ~tbfft2(); protected: - virtual void m_signal (int n, float *const *in, float *const *out); - void set_freq(t_float); - void set_width(t_float); - + virtual void m_signal (int n, float *const *in, float *const *out); + virtual void m_dsp (int n, float *const *in, float *const *out); + void set_freq(t_float); + void set_width(t_float); + private: - FLEXT_CALLBACK_1(set_freq,t_float) - FLEXT_CALLBACK_1(set_width,t_float) - - t_int center; - t_int width; - - t_float pos; - t_int posi; - - float *ins; - float *outs; - float *tmps; - t_float tmp[17000]; + FLEXT_CALLBACK_1(set_freq,t_float); + FLEXT_CALLBACK_1(set_width,t_float); - t_float s; - t_float b; - - t_int n0; + t_int center; + t_int width; + + t_float * tmp; + + t_int n0; }; @@ -91,40 +84,52 @@ tbfft2::tbfft2() FLEXT_ADDMETHOD_F(0,"width",set_width); } +tbfft2::~tbfft2() +{ + free(tmp); +} -void tbfft2::m_signal(int n, t_float *const *in, t_float *const *out) +void tbfft2::m_dsp(int n, t_float *const *in, t_float *const *out) { - ins = in[0]; - outs = out[0]; + free(tmp); + tmp=(t_float*)malloc(n*sizeof(t_float)); +} - CopySamples(tmp,ins,n); - - n0=n/2; - if (center-width>0) + +void tbfft2::m_signal(int n, t_float *const *in, t_float *const *out) +{ + t_float * ins = in[0]; + t_float * outs = out[0]; + + CopySamples(tmp,ins,n); + + n0=n/2; + + if (center-width>0) { - n=center-width; + n=center-width; } - else - n=0; - - while (n Date: Tue, 13 Jul 2004 20:11:34 +0000 Subject: obsolete ... part of pd now... svn path=/trunk/externals/tb/; revision=1856 --- tbext/source/rfftw~.cpp | 138 ---------------------------------------- tbext/source/rifftw~.cpp | 161 ----------------------------------------------- 2 files changed, 299 deletions(-) delete mode 100644 tbext/source/rfftw~.cpp delete mode 100644 tbext/source/rifftw~.cpp diff --git a/tbext/source/rfftw~.cpp b/tbext/source/rfftw~.cpp deleted file mode 100644 index dd10517..0000000 --- a/tbext/source/rfftw~.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (c) 2004 Tim Blechmann. */ -/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ -/* WARRANTIES, see the file, "COPYING" in this distribution. */ -/* */ -/* */ -/* rfftw~ is doing the same as rfft~, but it's based on the fftw library, */ -/* that is much faster that pd's internal fft ... */ -/* */ -/* */ -/* rfftw~ uses the flext C++ layer for Max/MSP and PD externals. */ -/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ -/* thanks to Thomas Grill */ -/* */ -/* */ -/* */ -/* This program is free software; you can redistribute it and/or */ -/* modify it under the terms of the GNU General Public License */ -/* as published by the Free Software Foundation; either version 2 */ -/* of the License, or (at your option) any later version. */ -/* */ -/* See file LICENSE for further informations on licensing terms. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* */ -/* Based on PureData by Miller Puckette and others. */ -/* */ -/* */ -/* */ -/* coded while listening to: Wolfgang Mitterer: Radiofractal & Beat Music */ -/* Sun Ra: Reflections In Blue */ -/* */ -/* */ - - - -#include - -#include "fftw3.h" -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) -#error upgrade your flext version!!!!!! -#endif - -class rfftw: public flext_dsp -{ - FLEXT_HEADER(rfftw,flext_dsp); - -public: // constructor - rfftw(); - ~rfftw(); - -protected: - virtual void m_signal (int n, float *const *in, float *const *out); - - fftwf_plan p; //fftw plan - int bins; //number of bins - float * outreal; //pointer to real output - float * outimag; //pointer to imaginary output - - float * infft; //array fftw is working on - float * outfft; //array fftw uses to output it's values - - - private: -}; - - -FLEXT_LIB_DSP("rfftw~",rfftw); - -rfftw::rfftw() - :bins(64) -{ - //get ready for the default blocksize - infft = fftwf_malloc(sizeof(float) * bins); - outfft = fftwf_malloc(sizeof(float) * bins); - p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_FORWARD,FFTW_MEASURE); - - AddInSignal(); - AddOutSignal(); - AddOutSignal(); -} - -rfftw::~rfftw() -{ - fftwf_free(infft); - fftwf_free(outfft); - fftwf_destroy_plan(p); -} - - -void rfftw::m_signal(int n, float *const *in, float *const *out) -{ - //set output pointers - outreal = out[0]; - outimag = out[1]; - - //if blocksize changed, we have to set a new plan for the fft - if (n!=bins) - { - bins=n; - - //re-allocate fft buffers - fftwf_free(infft); - infft = fftwf_malloc(sizeof(float) * bins); - fftwf_free(outfft); - outfft = fftwf_malloc(sizeof(float) * bins); - - //set plan, this might take a few seconds - //but you don't have to do that on the fly... - fftwf_destroy_plan(p); - p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_FORWARD,FFTW_MEASURE); - } - - CopySamples(infft,in[0],n); - - //execute - fftwf_execute(p); - - //Copy samples to outlets - CopySamples(outreal,outfft,n/2); - std::reverse_copy(outfft+n/2+1,outfft+n,outimag+1); - - //why do we have to invert the samples??? - for (int i = n/2+1; i!=0;--i) - { - *(outimag+i)=-*(outimag+i); - } - -} - diff --git a/tbext/source/rifftw~.cpp b/tbext/source/rifftw~.cpp deleted file mode 100644 index ee6f126..0000000 --- a/tbext/source/rifftw~.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* Copyright (c) 2004 Tim Blechmann. */ -/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ -/* WARRANTIES, see the file, "COPYING" in this distribution. */ -/* */ -/* */ -/* rifftw~ is doing the same as rifft~, but it's based on the fftw library, */ -/* that is much faster that pd's internal fft ... */ -/* */ -/* */ -/* rifftw~ uses the flext C++ layer for Max/MSP and PD externals. */ -/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ -/* thanks to Thomas Grill */ -/* */ -/* */ -/* */ -/* This program is free software; you can redistribute it and/or */ -/* modify it under the terms of the GNU General Public License */ -/* as published by the Free Software Foundation; either version 2 */ -/* of the License, or (at your option) any later version. */ -/* */ -/* See file LICENSE for further informations on licensing terms. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* */ -/* Based on PureData by Miller Puckette and others. */ -/* */ -/* */ -/* */ -/* coded while listening to: Caged/Uncaged */ -/* Sunny Murray: Hommage To Africa */ -/* */ -/* */ - - - -#include - -#include "fftw3.h" -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) -#error upgrade your flext version!!!!!! -#endif - -class rifftw: public flext_dsp -{ - FLEXT_HEADER(rifftw,flext_dsp); - -public: // constructor - rifftw(); - ~rifftw(); - -protected: - virtual void m_signal (int n, float *const *in, float *const *out); - - fftwf_plan p; //fftw plan - int bins; //number of bins - float * inreal; //pointer to real input - float * inimag; //pointer to imaginary input - - fftwf_complex * incomplex; - - //float * infft; //array fftw is working on - float * outfft; //array fftw uses to output it's values - - - private: -}; - - -FLEXT_LIB_DSP("rifftw~",rifftw); - -rifftw::rifftw() - :bins(64) -{ - //get ready for the default blocksize - // infft = fftwf_malloc(sizeof(float) * bins); - outfft = fftwf_malloc(sizeof(float) * bins); - - - incomplex = fftwf_malloc(sizeof(fftwf_complex) * bins); - - - // p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_BACKWARD,FFTW_MEASURE); - p=fftwf_plan_dft_c2r_1d(bins,incomplex,outfft,FFTW_BACKWARD,FFTW_MEASURE); - - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -rifftw::~rifftw() -{ - // fftwf_free(infft); - fftwf_free(outfft); - fftwf_free(incomplex); - fftwf_destroy_plan(p); -} - - -void rifftw::m_signal(int n, float *const *in, float *const *out) -{ - //set output pointers - inreal = in[0]; - inimag = in[1]; - - //if blocksize changed, we have to set a new plan for the fft - if (n!=bins) - { - bins=n; - - //re-allocate fft buffers - // fftwf_free(infft); - // infft = fftwf_malloc(sizeof(float) * bins); - fftwf_free(outfft); - outfft = fftwf_malloc(sizeof(float) * bins); - - fftwf_free(incomplex); - incomplex = fftwf_malloc(sizeof(fftwf_complex) * bins); - - //set plan, this might take a few seconds - //but you don't have to do that on the fly... - fftwf_destroy_plan(p); - //p=fftwf_plan_r2r_1d(bins,infft,outfft,FFTW_BACKWARD,FFTW_MEASURE); - p=fftwf_plan_dft_c2r_1d(bins,incomplex,outfft,FFTW_BACKWARD,FFTW_MEASURE); - - } - - //Copy samples to the fft - // CopySamples(infft,inreal,n/2); - // std::reverse_copy(inimag,inimag+n/2,infft+n/2); - - - /* - //why do we have to invert the samples??? - for (int i = n/2+1; i!=n;++i) - { - *(infft+i)=-*(infft+i); - } - */ - - for (int i=0;i!=n/2;++i) - { - incomplex[i][0]=inreal[i]; - incomplex[i][1]=-inimag[i]; - } - - //execute - fftwf_execute(p); - - CopySamples(out[0],outfft,n); - -} - -- cgit v1.2.1 From d0ae3caca5828675335d3b19ab5dd987e7369b23 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 16:21:44 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r1857, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=1858 --- sc4pd/build-max-msvc.bat | 4 + sc4pd/build-pd-bcc.bat | 3 + sc4pd/build-pd-cygwin.sh | 15 + sc4pd/build-pd-darwin.sh | 17 + sc4pd/build-pd-linux.sh | 17 + sc4pd/build-pd-mingw.bat | 3 + sc4pd/build-pd-msvc.bat | 4 + sc4pd/config-max-msvc.txt | 27 + sc4pd/config-pd-bcc.txt | 23 + sc4pd/config-pd-cygwin.txt | 35 + sc4pd/config-pd-darwin.txt | 35 + sc4pd/config-pd-linux.txt | 37 + sc4pd/config-pd-mingw.txt | 35 + sc4pd/config-pd-msvc.txt | 19 + sc4pd/headers/app/AIAttributedStringAdditions.h | 39 + sc4pd/headers/app/AIColorAdditions.h | 39 + sc4pd/headers/app/AIHTMLDecoder.h | 28 + sc4pd/headers/app/AIStringAdditions.h | 25 + sc4pd/headers/app/AITextAttributes.h | 44 ++ sc4pd/headers/app/ChangeCounter.h | 30 + sc4pd/headers/app/ControlSpec.h | 36 + sc4pd/headers/app/DrawBackground.h | 83 +++ sc4pd/headers/app/GetStringFromUser.h | 46 ++ sc4pd/headers/app/GoToPanel.h | 52 ++ sc4pd/headers/app/MyDocument.h | 107 +++ sc4pd/headers/app/RendezvousClient.h | 39 + sc4pd/headers/app/SCDialog.h | 41 ++ sc4pd/headers/app/SCGeom.h | 90 +++ sc4pd/headers/app/SCGraphView.h | 55 ++ sc4pd/headers/app/SCService.h | 16 + sc4pd/headers/app/SCTextView.h | 33 + sc4pd/headers/app/SCView.h | 784 +++++++++++++++++++++ sc4pd/headers/app/SCVirtualMachine.h | 65 ++ sc4pd/headers/app/TabletEvents.h | 75 ++ sc4pd/headers/app/TextFinder.h | 64 ++ sc4pd/headers/app/UserPanel.h | 40 ++ sc4pd/headers/common/SC_AllocPool.h | 278 ++++++++ sc4pd/headers/common/SC_Altivec.h | 118 ++++ sc4pd/headers/common/SC_Endian.h | 64 ++ sc4pd/headers/common/SC_Sem.h | 43 ++ sc4pd/headers/common/SC_StringBuffer.h | 67 ++ sc4pd/headers/common/SC_StringParser.h | 40 ++ sc4pd/headers/common/dfftlib.h | 62 ++ sc4pd/headers/common/dlfcn.h | 44 ++ sc4pd/headers/common/fftlib.h | 62 ++ sc4pd/headers/common/scsynthsend.h | 191 +++++ sc4pd/headers/lang/AdvancingAllocPool.h | 82 +++ sc4pd/headers/lang/AllocPools.h | 34 + sc4pd/headers/lang/ByteCodeArray.h | 50 ++ sc4pd/headers/lang/FIFOT.h | 75 ++ sc4pd/headers/lang/GC.h | 263 +++++++ sc4pd/headers/lang/HashTable.h | 274 +++++++ sc4pd/headers/lang/InitAlloc.h | 32 + sc4pd/headers/lang/MiscInlineMath.h | 54 ++ sc4pd/headers/lang/OSCData.h | 1 + sc4pd/headers/lang/Opcodes.h | 426 +++++++++++ sc4pd/headers/lang/PowerOfTwoAllocPool.h | 154 ++++ sc4pd/headers/lang/PredefinedSymbols.h | 29 + sc4pd/headers/lang/PriorityQueue.h | 90 +++ sc4pd/headers/lang/PyrArchiverT.h | 619 ++++++++++++++++ sc4pd/headers/lang/PyrDeepCopier.h | 221 ++++++ sc4pd/headers/lang/PyrDeepFreezer.h | 178 +++++ sc4pd/headers/lang/PyrErrors.h | 49 ++ sc4pd/headers/lang/PyrFilePrim.h | 62 ++ sc4pd/headers/lang/PyrFileUtils.h | 50 ++ sc4pd/headers/lang/PyrInterpreter.h | 47 ++ sc4pd/headers/lang/PyrKernel.h | 256 +++++++ sc4pd/headers/lang/PyrKernelProto.h | 62 ++ sc4pd/headers/lang/PyrLexer.h | 136 ++++ sc4pd/headers/lang/PyrListPrim.h | 34 + sc4pd/headers/lang/PyrMathPrim.h | 51 ++ sc4pd/headers/lang/PyrMessage.h | 55 ++ sc4pd/headers/lang/PyrObject.h | 288 ++++++++ sc4pd/headers/lang/PyrObjectProto.h | 44 ++ sc4pd/headers/lang/PyrParseNode.h | 456 ++++++++++++ sc4pd/headers/lang/PyrPrimitive.h | 42 ++ sc4pd/headers/lang/PyrPrimitiveProto.h | 81 +++ sc4pd/headers/lang/PyrSched.h | 58 ++ sc4pd/headers/lang/PyrSignal.h | 417 +++++++++++ sc4pd/headers/lang/PyrSignalPrim.h | 56 ++ sc4pd/headers/lang/PyrSlot.h | 286 ++++++++ sc4pd/headers/lang/PyrSymbol.h | 59 ++ sc4pd/headers/lang/PyrSymbolTable.h | 78 ++ sc4pd/headers/lang/ReadWriteMacros.h | 336 +++++++++ sc4pd/headers/lang/SCBase.h | 68 ++ sc4pd/headers/lang/SC_ComPort.h | 118 ++++ sc4pd/headers/lang/SC_LanguageClient.h | 164 +++++ sc4pd/headers/lang/SC_LibraryConfig.h | 108 +++ sc4pd/headers/lang/SC_List.h | 229 ++++++ sc4pd/headers/lang/SC_LogFile.h | 29 + sc4pd/headers/lang/SC_Msg.h | 70 ++ sc4pd/headers/lang/SC_SynthImpl.h | 42 ++ sc4pd/headers/lang/SC_TerminalClient.h | 92 +++ sc4pd/headers/lang/SC_UnorderedList.h | 60 ++ sc4pd/headers/lang/SFHeaders.h | 1 + sc4pd/headers/lang/Samp.h | 46 ++ sc4pd/headers/lang/SimpleStack.h | 32 + sc4pd/headers/lang/VMGlobals.h | 94 +++ sc4pd/headers/lang/bullet.h | 7 + sc4pd/headers/lang/libraryConfig.h | 31 + sc4pd/headers/lang/readSamples.h | 1 + sc4pd/headers/plugin_interface/Hash.h | 152 ++++ sc4pd/headers/plugin_interface/SC_BoundsMacros.h | 29 + sc4pd/headers/plugin_interface/SC_BufGen.h | 40 ++ sc4pd/headers/plugin_interface/SC_Constants.h | 46 ++ sc4pd/headers/plugin_interface/SC_DemandUnit.h | 54 ++ sc4pd/headers/plugin_interface/SC_Dimension.h | 31 + sc4pd/headers/plugin_interface/SC_FifoMsg.h | 59 ++ sc4pd/headers/plugin_interface/SC_Graph.h | 53 ++ sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h | 574 +++++++++++++++ sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h | 448 ++++++++++++ sc4pd/headers/plugin_interface/SC_InterfaceTable.h | 175 +++++ sc4pd/headers/plugin_interface/SC_Node.h | 48 ++ sc4pd/headers/plugin_interface/SC_PlugIn.h | 53 ++ sc4pd/headers/plugin_interface/SC_RGen.h | 288 ++++++++ sc4pd/headers/plugin_interface/SC_Rate.h | 42 ++ sc4pd/headers/plugin_interface/SC_SndBuf.h | 109 +++ sc4pd/headers/plugin_interface/SC_Types.h | 67 ++ sc4pd/headers/plugin_interface/SC_Unit.h | 101 +++ sc4pd/headers/plugin_interface/SC_Wire.h | 36 + sc4pd/headers/plugin_interface/SC_World.h | 105 +++ sc4pd/headers/plugin_interface/SC_WorldOptions.h | 91 +++ sc4pd/headers/plugin_interface/Unroll.h | 249 +++++++ sc4pd/headers/plugin_interface/clz.h | 195 +++++ sc4pd/headers/plugin_interface/sc_msg_iter.h | 264 +++++++ sc4pd/headers/server/HashTable.h | 356 ++++++++++ sc4pd/headers/server/IntFifo.h | 87 +++ sc4pd/headers/server/MsgFifo.h | 169 +++++ sc4pd/headers/server/OSC_Packet.h | 43 ++ sc4pd/headers/server/PriorityQueue.h | 123 ++++ sc4pd/headers/server/ReadWriteMacros.h | 430 +++++++++++ sc4pd/headers/server/Rendezvous.h | 41 ++ sc4pd/headers/server/SC_ComPort.h | 144 ++++ sc4pd/headers/server/SC_Complex.h | 142 ++++ sc4pd/headers/server/SC_CoreAudio.h | 263 +++++++ sc4pd/headers/server/SC_Errors.h | 58 ++ sc4pd/headers/server/SC_GraphDef.h | 75 ++ sc4pd/headers/server/SC_Group.h | 34 + sc4pd/headers/server/SC_HiddenWorld.h | 113 +++ sc4pd/headers/server/SC_Lib.h | 62 ++ sc4pd/headers/server/SC_Lib_Cintf.h | 124 ++++ sc4pd/headers/server/SC_List.h | 229 ++++++ sc4pd/headers/server/SC_Lock.h | 38 + sc4pd/headers/server/SC_Prototypes.h | 213 ++++++ sc4pd/headers/server/SC_Reply.h | 55 ++ sc4pd/headers/server/SC_Samp.h | 38 + sc4pd/headers/server/SC_SequencedCommand.h | 481 +++++++++++++ sc4pd/headers/server/SC_Str4.h | 103 +++ sc4pd/headers/server/SC_SyncCondition.h | 45 ++ sc4pd/headers/server/SC_SynthDef.h | 43 ++ sc4pd/headers/server/SC_UnitDef.h | 69 ++ sc4pd/headers/server/SC_UnitSpec.h | 41 ++ sc4pd/headers/server/SC_WireSpec.h | 47 ++ sc4pd/make-files.txt | 6 + sc4pd/makefile.max-msvc | 77 ++ sc4pd/makefile.pd-bcc | 73 ++ sc4pd/makefile.pd-cygwin | 86 +++ sc4pd/makefile.pd-darwin | 77 ++ sc4pd/makefile.pd-linux | 94 +++ sc4pd/makefile.pd-mingw | 85 +++ sc4pd/makefile.pd-msvc | 53 ++ sc4pd/pd/crackle.pd | 10 + sc4pd/pd/dust.pd | 11 + sc4pd/pd/hasher.pd | 17 + sc4pd/pd/mantissamask.pd | 21 + sc4pd/readme.txt | 23 + sc4pd/source/BrownNoise.cpp | 150 ++++ sc4pd/source/ClipNoise.cpp | 130 ++++ sc4pd/source/Crackle.cpp | 161 +++++ sc4pd/source/Dust.cpp | 179 +++++ sc4pd/source/Dust2.cpp | 180 +++++ sc4pd/source/GrayNoise.cpp | 137 ++++ sc4pd/source/Hasher.cpp | 122 ++++ sc4pd/source/MantissaMask.cpp | 160 +++++ sc4pd/source/Median.cpp | 220 ++++++ sc4pd/source/PinkNoise.cpp | 168 +++++ sc4pd/source/WhiteNoise.cpp | 130 ++++ sc4pd/source/main.cpp | 91 +++ sc4pd/source/support.hpp | 80 +++ sc4pd/source/template.cpp | 43 ++ 180 files changed, 19410 insertions(+) create mode 100644 sc4pd/build-max-msvc.bat create mode 100644 sc4pd/build-pd-bcc.bat create mode 100644 sc4pd/build-pd-cygwin.sh create mode 100755 sc4pd/build-pd-darwin.sh create mode 100755 sc4pd/build-pd-linux.sh create mode 100644 sc4pd/build-pd-mingw.bat create mode 100644 sc4pd/build-pd-msvc.bat create mode 100644 sc4pd/config-max-msvc.txt create mode 100644 sc4pd/config-pd-bcc.txt create mode 100644 sc4pd/config-pd-cygwin.txt create mode 100755 sc4pd/config-pd-darwin.txt create mode 100755 sc4pd/config-pd-linux.txt create mode 100644 sc4pd/config-pd-mingw.txt create mode 100644 sc4pd/config-pd-msvc.txt create mode 100644 sc4pd/headers/app/AIAttributedStringAdditions.h create mode 100644 sc4pd/headers/app/AIColorAdditions.h create mode 100644 sc4pd/headers/app/AIHTMLDecoder.h create mode 100644 sc4pd/headers/app/AIStringAdditions.h create mode 100644 sc4pd/headers/app/AITextAttributes.h create mode 100644 sc4pd/headers/app/ChangeCounter.h create mode 100644 sc4pd/headers/app/ControlSpec.h create mode 100644 sc4pd/headers/app/DrawBackground.h create mode 100644 sc4pd/headers/app/GetStringFromUser.h create mode 100644 sc4pd/headers/app/GoToPanel.h create mode 100644 sc4pd/headers/app/MyDocument.h create mode 100644 sc4pd/headers/app/RendezvousClient.h create mode 100644 sc4pd/headers/app/SCDialog.h create mode 100644 sc4pd/headers/app/SCGeom.h create mode 100644 sc4pd/headers/app/SCGraphView.h create mode 100644 sc4pd/headers/app/SCService.h create mode 100644 sc4pd/headers/app/SCTextView.h create mode 100644 sc4pd/headers/app/SCView.h create mode 100644 sc4pd/headers/app/SCVirtualMachine.h create mode 100755 sc4pd/headers/app/TabletEvents.h create mode 100644 sc4pd/headers/app/TextFinder.h create mode 100644 sc4pd/headers/app/UserPanel.h create mode 100755 sc4pd/headers/common/SC_AllocPool.h create mode 100644 sc4pd/headers/common/SC_Altivec.h create mode 100644 sc4pd/headers/common/SC_Endian.h create mode 100755 sc4pd/headers/common/SC_Sem.h create mode 100644 sc4pd/headers/common/SC_StringBuffer.h create mode 100644 sc4pd/headers/common/SC_StringParser.h create mode 100755 sc4pd/headers/common/dfftlib.h create mode 100755 sc4pd/headers/common/dlfcn.h create mode 100755 sc4pd/headers/common/fftlib.h create mode 100644 sc4pd/headers/common/scsynthsend.h create mode 100755 sc4pd/headers/lang/AdvancingAllocPool.h create mode 100755 sc4pd/headers/lang/AllocPools.h create mode 100755 sc4pd/headers/lang/ByteCodeArray.h create mode 100755 sc4pd/headers/lang/FIFOT.h create mode 100755 sc4pd/headers/lang/GC.h create mode 100755 sc4pd/headers/lang/HashTable.h create mode 100755 sc4pd/headers/lang/InitAlloc.h create mode 100755 sc4pd/headers/lang/MiscInlineMath.h create mode 100755 sc4pd/headers/lang/OSCData.h create mode 100755 sc4pd/headers/lang/Opcodes.h create mode 100755 sc4pd/headers/lang/PowerOfTwoAllocPool.h create mode 100755 sc4pd/headers/lang/PredefinedSymbols.h create mode 100755 sc4pd/headers/lang/PriorityQueue.h create mode 100755 sc4pd/headers/lang/PyrArchiverT.h create mode 100755 sc4pd/headers/lang/PyrDeepCopier.h create mode 100755 sc4pd/headers/lang/PyrDeepFreezer.h create mode 100755 sc4pd/headers/lang/PyrErrors.h create mode 100755 sc4pd/headers/lang/PyrFilePrim.h create mode 100755 sc4pd/headers/lang/PyrFileUtils.h create mode 100755 sc4pd/headers/lang/PyrInterpreter.h create mode 100755 sc4pd/headers/lang/PyrKernel.h create mode 100755 sc4pd/headers/lang/PyrKernelProto.h create mode 100755 sc4pd/headers/lang/PyrLexer.h create mode 100755 sc4pd/headers/lang/PyrListPrim.h create mode 100755 sc4pd/headers/lang/PyrMathPrim.h create mode 100755 sc4pd/headers/lang/PyrMessage.h create mode 100755 sc4pd/headers/lang/PyrObject.h create mode 100755 sc4pd/headers/lang/PyrObjectProto.h create mode 100755 sc4pd/headers/lang/PyrParseNode.h create mode 100755 sc4pd/headers/lang/PyrPrimitive.h create mode 100755 sc4pd/headers/lang/PyrPrimitiveProto.h create mode 100755 sc4pd/headers/lang/PyrSched.h create mode 100755 sc4pd/headers/lang/PyrSignal.h create mode 100755 sc4pd/headers/lang/PyrSignalPrim.h create mode 100755 sc4pd/headers/lang/PyrSlot.h create mode 100755 sc4pd/headers/lang/PyrSymbol.h create mode 100755 sc4pd/headers/lang/PyrSymbolTable.h create mode 100755 sc4pd/headers/lang/ReadWriteMacros.h create mode 100755 sc4pd/headers/lang/SCBase.h create mode 100755 sc4pd/headers/lang/SC_ComPort.h create mode 100644 sc4pd/headers/lang/SC_LanguageClient.h create mode 100644 sc4pd/headers/lang/SC_LibraryConfig.h create mode 100755 sc4pd/headers/lang/SC_List.h create mode 100755 sc4pd/headers/lang/SC_LogFile.h create mode 100755 sc4pd/headers/lang/SC_Msg.h create mode 100755 sc4pd/headers/lang/SC_SynthImpl.h create mode 100644 sc4pd/headers/lang/SC_TerminalClient.h create mode 100755 sc4pd/headers/lang/SC_UnorderedList.h create mode 100755 sc4pd/headers/lang/SFHeaders.h create mode 100755 sc4pd/headers/lang/Samp.h create mode 100755 sc4pd/headers/lang/SimpleStack.h create mode 100755 sc4pd/headers/lang/VMGlobals.h create mode 100755 sc4pd/headers/lang/bullet.h create mode 100644 sc4pd/headers/lang/libraryConfig.h create mode 100755 sc4pd/headers/lang/readSamples.h create mode 100755 sc4pd/headers/plugin_interface/Hash.h create mode 100755 sc4pd/headers/plugin_interface/SC_BoundsMacros.h create mode 100644 sc4pd/headers/plugin_interface/SC_BufGen.h create mode 100755 sc4pd/headers/plugin_interface/SC_Constants.h create mode 100644 sc4pd/headers/plugin_interface/SC_DemandUnit.h create mode 100644 sc4pd/headers/plugin_interface/SC_Dimension.h create mode 100644 sc4pd/headers/plugin_interface/SC_FifoMsg.h create mode 100644 sc4pd/headers/plugin_interface/SC_Graph.h create mode 100755 sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h create mode 100755 sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h create mode 100644 sc4pd/headers/plugin_interface/SC_InterfaceTable.h create mode 100644 sc4pd/headers/plugin_interface/SC_Node.h create mode 100644 sc4pd/headers/plugin_interface/SC_PlugIn.h create mode 100755 sc4pd/headers/plugin_interface/SC_RGen.h create mode 100644 sc4pd/headers/plugin_interface/SC_Rate.h create mode 100644 sc4pd/headers/plugin_interface/SC_SndBuf.h create mode 100755 sc4pd/headers/plugin_interface/SC_Types.h create mode 100644 sc4pd/headers/plugin_interface/SC_Unit.h create mode 100644 sc4pd/headers/plugin_interface/SC_Wire.h create mode 100644 sc4pd/headers/plugin_interface/SC_World.h create mode 100644 sc4pd/headers/plugin_interface/SC_WorldOptions.h create mode 100644 sc4pd/headers/plugin_interface/Unroll.h create mode 100755 sc4pd/headers/plugin_interface/clz.h create mode 100644 sc4pd/headers/plugin_interface/sc_msg_iter.h create mode 100755 sc4pd/headers/server/HashTable.h create mode 100644 sc4pd/headers/server/IntFifo.h create mode 100755 sc4pd/headers/server/MsgFifo.h create mode 100644 sc4pd/headers/server/OSC_Packet.h create mode 100755 sc4pd/headers/server/PriorityQueue.h create mode 100644 sc4pd/headers/server/ReadWriteMacros.h create mode 100644 sc4pd/headers/server/Rendezvous.h create mode 100755 sc4pd/headers/server/SC_ComPort.h create mode 100644 sc4pd/headers/server/SC_Complex.h create mode 100755 sc4pd/headers/server/SC_CoreAudio.h create mode 100755 sc4pd/headers/server/SC_Errors.h create mode 100644 sc4pd/headers/server/SC_GraphDef.h create mode 100644 sc4pd/headers/server/SC_Group.h create mode 100644 sc4pd/headers/server/SC_HiddenWorld.h create mode 100755 sc4pd/headers/server/SC_Lib.h create mode 100755 sc4pd/headers/server/SC_Lib_Cintf.h create mode 100755 sc4pd/headers/server/SC_List.h create mode 100755 sc4pd/headers/server/SC_Lock.h create mode 100644 sc4pd/headers/server/SC_Prototypes.h create mode 100755 sc4pd/headers/server/SC_Reply.h create mode 100644 sc4pd/headers/server/SC_Samp.h create mode 100644 sc4pd/headers/server/SC_SequencedCommand.h create mode 100644 sc4pd/headers/server/SC_Str4.h create mode 100755 sc4pd/headers/server/SC_SyncCondition.h create mode 100644 sc4pd/headers/server/SC_SynthDef.h create mode 100644 sc4pd/headers/server/SC_UnitDef.h create mode 100644 sc4pd/headers/server/SC_UnitSpec.h create mode 100644 sc4pd/headers/server/SC_WireSpec.h create mode 100755 sc4pd/make-files.txt create mode 100644 sc4pd/makefile.max-msvc create mode 100644 sc4pd/makefile.pd-bcc create mode 100644 sc4pd/makefile.pd-cygwin create mode 100755 sc4pd/makefile.pd-darwin create mode 100644 sc4pd/makefile.pd-linux create mode 100644 sc4pd/makefile.pd-mingw create mode 100644 sc4pd/makefile.pd-msvc create mode 100644 sc4pd/pd/crackle.pd create mode 100644 sc4pd/pd/dust.pd create mode 100644 sc4pd/pd/hasher.pd create mode 100644 sc4pd/pd/mantissamask.pd create mode 100644 sc4pd/readme.txt create mode 100644 sc4pd/source/BrownNoise.cpp create mode 100644 sc4pd/source/ClipNoise.cpp create mode 100644 sc4pd/source/Crackle.cpp create mode 100644 sc4pd/source/Dust.cpp create mode 100644 sc4pd/source/Dust2.cpp create mode 100644 sc4pd/source/GrayNoise.cpp create mode 100644 sc4pd/source/Hasher.cpp create mode 100644 sc4pd/source/MantissaMask.cpp create mode 100644 sc4pd/source/Median.cpp create mode 100644 sc4pd/source/PinkNoise.cpp create mode 100644 sc4pd/source/WhiteNoise.cpp create mode 100644 sc4pd/source/main.cpp create mode 100644 sc4pd/source/support.hpp create mode 100644 sc4pd/source/template.cpp diff --git a/sc4pd/build-max-msvc.bat b/sc4pd/build-max-msvc.bat new file mode 100644 index 0000000..130a3bc --- /dev/null +++ b/sc4pd/build-max-msvc.bat @@ -0,0 +1,4 @@ +@echo --- Building with MS Visual C++ --- + +nmake -f makefile.max-msvc clean +nmake -f makefile.max-msvc diff --git a/sc4pd/build-pd-bcc.bat b/sc4pd/build-pd-bcc.bat new file mode 100644 index 0000000..3dd2132 --- /dev/null +++ b/sc4pd/build-pd-bcc.bat @@ -0,0 +1,3 @@ +@echo --- Building with BorlandC++ --- + +make -f makefile.pd-bcc diff --git a/sc4pd/build-pd-cygwin.sh b/sc4pd/build-pd-cygwin.sh new file mode 100644 index 0000000..9477844 --- /dev/null +++ b/sc4pd/build-pd-cygwin.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +SYS=pd-cygwin + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + make -f makefile.${SYS} install + fi + if [ $HELPDIR != "" ]; then + make -f makefile.${SYS} install-help + fi +} diff --git a/sc4pd/build-pd-darwin.sh b/sc4pd/build-pd-darwin.sh new file mode 100755 index 0000000..38814a9 --- /dev/null +++ b/sc4pd/build-pd-darwin.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +SYS=pd-darwin + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + echo Now install as root + sudo make -f makefile.${SYS} install + fi + if [ $HELPDIR != "" ]; then + echo Now install help as root + sudo make -f makefile.${SYS} install-help + fi +} diff --git a/sc4pd/build-pd-linux.sh b/sc4pd/build-pd-linux.sh new file mode 100755 index 0000000..77c6e3f --- /dev/null +++ b/sc4pd/build-pd-linux.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +SYS=pd-linux + +. config-${SYS}.txt + +make -f makefile.${SYS} && +{ + if [ $INSTDIR != "" ]; then + echo Now install as root + su -c "make -f makefile.${SYS} install" + fi + if [ $HELPDIR != "" ]; then + echo Now install help as root + su -c "make -f makefile.${SYS} install-help" + fi +} diff --git a/sc4pd/build-pd-mingw.bat b/sc4pd/build-pd-mingw.bat new file mode 100644 index 0000000..fa8919a --- /dev/null +++ b/sc4pd/build-pd-mingw.bat @@ -0,0 +1,3 @@ +mingw32-make -f makefile.pd-mingw +mingw32-make -f makefile.pd-mingw install +mingw32-make -f makefile.pd-mingw install-help diff --git a/sc4pd/build-pd-msvc.bat b/sc4pd/build-pd-msvc.bat new file mode 100644 index 0000000..d6187f0 --- /dev/null +++ b/sc4pd/build-pd-msvc.bat @@ -0,0 +1,4 @@ +@echo --- Building with MS Visual C++ --- + +nmake -f makefile.pd-msvc clean +nmake -f makefile.pd-msvc diff --git a/sc4pd/config-max-msvc.txt b/sc4pd/config-max-msvc.txt new file mode 100644 index 0000000..95dfe38 --- /dev/null +++ b/sc4pd/config-max-msvc.txt @@ -0,0 +1,27 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# where is the Max SDK? +# you should have the latest version! +MAXSDKPATH="F:\prog\audio\MaxWinSDK\c74support" + +# where do the flext libraries reside? +FLEXTPATH="%CommonProgramFiles%\Cycling '74\flext" + +# where is MS VC++? +# (need not be defined if the build is started with the compiler environment set) +# MSVCPATH="c:\programme\prog\microsoft visual studio\VC98" + + +# where should the external be built? +# (path for temporary files) +OUTPATH=max-msvc + +# where should the external be installed? +# (leave blank to omit installation) +INSTPATH="%CommonProgramFiles%\Cycling '74\externals\flext" + + +# some user-definable flags +# (check if they match your system!) +UFLAGS=/G6 /arch:SSE diff --git a/sc4pd/config-pd-bcc.txt b/sc4pd/config-pd-bcc.txt new file mode 100644 index 0000000..8f8ba75 --- /dev/null +++ b/sc4pd/config-pd-bcc.txt @@ -0,0 +1,23 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# where is PD? +PDPATH=c:\programme\audio\pd + +# where do the flext libraries reside? +FLEXTPATH=$(PDPATH)\flext + +# where is BorlandC++? +BCCPATH=c:\programme\prog\bcc55 + +# where should the external(s) be built? +OUTPATH=.\pd-bcc + +# should the external be installed? (yes/no) +INSTALL=yes + +# where should the external be installed? +INSTDIR=$(PDPATH)\extra + +# additional compiler flags +UFLAGS=-6 -O2 -OS -ff diff --git a/sc4pd/config-pd-cygwin.txt b/sc4pd/config-pd-cygwin.txt new file mode 100644 index 0000000..feb8d31 --- /dev/null +++ b/sc4pd/config-pd-cygwin.txt @@ -0,0 +1,35 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (define only if it's different than g++) +# CXX=g++ + +# where does the PD installation reside? +PD=/cygdrive/c/programme/audio/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should sc4pd objects be built? +TARGDIR=./pd-cygwin + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-mcpu=pentium4 -msse -mfpmath=sse # gcc 3.2 +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 + +# define to build with shared flext library +#FLEXT_SHARED=1 diff --git a/sc4pd/config-pd-darwin.txt b/sc4pd/config-pd-darwin.txt new file mode 100755 index 0000000..82c5b70 --- /dev/null +++ b/sc4pd/config-pd-darwin.txt @@ -0,0 +1,35 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (if not g++) +#CXX=g++-3.3 + +# where does the PD installation reside? +PD=/usr/local/lib/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where is the PD executable? +PDBIN=/usr/local/bin/pd + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should the sc4pd objects be built? +TARGDIR=./pd-darwin + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit your system!) +UFLAGS=-malign-power -maltivec -faltivec + diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt new file mode 100755 index 0000000..e3d8dc1 --- /dev/null +++ b/sc4pd/config-pd-linux.txt @@ -0,0 +1,37 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile + +# your c++ compiler (if not g++) + CXX=icc + + +# where does the PD installation reside? +PD=/usr/lib/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=/home/tim/pd/pd/src + +# where do the flext libraries reside? +FLEXTPATH=/usr/lib/flext + +# where should sc4pd objects be built? +TARGDIR=./pd-linux + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/externs + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +#UFLAGS=-xN -tpp7 -ip -ipo_obj # icc +# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 + + +# define to link against shared flext library (flext version >= 0.5.0) +FLEXT_SHARED=1 + diff --git a/sc4pd/config-pd-mingw.txt b/sc4pd/config-pd-mingw.txt new file mode 100644 index 0000000..d5352b7 --- /dev/null +++ b/sc4pd/config-pd-mingw.txt @@ -0,0 +1,35 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# your c++ compiler (define only if it's different than g++) +# CXX=g++ + +# where does the PD installation reside? +PD=c:/programme/audio/pd + +# where are the PD header files? +# leave it blank if it is a system directory (like /usr/local/include), +# since gcc 3.2 complains about it +PDINC=${PD}/src + +# where do the flext libraries reside? +FLEXTPATH=${PD}/flext + +# where should sc4pd objects be built? +TARGDIR=./pd-mingw + +# where should sc4pd be installed? +# (leave blank to omit installation) +INSTDIR=${PD}/extra + +# where should the sc4pd help be installed? +# (leave blank to omit installation) +HELPDIR=${PD}/doc/5.reference + +# additional compiler flags +# (check whether they fit to your system!) +UFLAGS=-mcpu=pentium4 -msse -mfpmath=sse # gcc 3.2 +# UFLAGS=-mcpu=pentiumpro # gcc 2.95 + +# define to build with shared flext library +# FLEXT_SHARED=1 \ No newline at end of file diff --git a/sc4pd/config-pd-msvc.txt b/sc4pd/config-pd-msvc.txt new file mode 100644 index 0000000..9ba68f2 --- /dev/null +++ b/sc4pd/config-pd-msvc.txt @@ -0,0 +1,19 @@ +# config file for sc4pd, adapted from Thomas Grill's xsample makefile +# + +# where is PD? +PDPATH=c:\programme\audio\pd + +# where do the flext libraries reside? +FLEXTPATH=$(PDPATH)\flext + +# where is MS VC++? +# (not necessary if the build started with the compiler environment) +# MSVCPATH=c:\programme\prog\microsoft visual studio\VC98 + +# where should the external be built? +OUTPATH=pd-msvc + +# where should the external be installed? +# (leave blank to omit installation) +INSTDIR=$(PDPATH)\extra diff --git a/sc4pd/headers/app/AIAttributedStringAdditions.h b/sc4pd/headers/app/AIAttributedStringAdditions.h new file mode 100644 index 0000000..ae81326 --- /dev/null +++ b/sc4pd/headers/app/AIAttributedStringAdditions.h @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +@interface NSMutableAttributedString (AIAttributedStringAdditions) + +- (void)appendString:(NSString *)aString withAttributes:(NSDictionary *)attrs; +- (NSData *)dataRepresentation; +- (NSAttributedString *)safeString; +- (unsigned int)replaceOccurrencesOfString:(NSString *)target withString:(NSString*)replacement options:(unsigned)opts range:(NSRange)searchRange; +- (unsigned int)replaceOccurrencesOfString:(NSString *)target withString:(NSString*)replacement attributes:(NSDictionary*)attributes options:(unsigned)opts range:(NSRange)searchRange; +- (void)adjustColorsToShowOnBackground:(NSColor *)backgroundColor; +- (void)adjustColorsToShowOnBackgroundRelativeToOriginalBackground:(NSColor *)backgroundColor; +@end + +@interface NSAttributedString (AIAttributedStringAdditions) + +- (float)heightWithWidth:(float)width; +- (NSData *)dataRepresentation; ++ (NSAttributedString *)stringWithData:(NSData *)inData; +- (NSAttributedString *)safeString; + +@end + + diff --git a/sc4pd/headers/app/AIColorAdditions.h b/sc4pd/headers/app/AIColorAdditions.h new file mode 100644 index 0000000..6af9dc8 --- /dev/null +++ b/sc4pd/headers/app/AIColorAdditions.h @@ -0,0 +1,39 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +@interface NSString (AIColorAdditions) + +- (NSColor *)hexColor; +- (NSColor *)representedColor; +- (NSColor *)representedColorWithAlpha:(float)alpha; + +@end + +@interface NSColor (AIColorAdditions) + +- (BOOL)equalToRGBColor:(NSColor *)inColor; +- (BOOL)colorIsDark; +- (NSColor *)darkenBy:(float)amount; +- (NSString *)hexString; +- (NSString *)stringRepresentation; +- (void)getHue:(float *)hue luminance:(float *)luminance saturation:(float *)saturation; ++ (NSColor *)colorWithCalibratedHue:(float)hue luminance:(float)luminance saturation:(float)saturation alpha:(float)alpha; +- (NSColor *)colorWithInvertedLuminance; +- (NSColor *)adjustHue:(float)dHue saturation:(float)dSat brightness:(float)dBrit; + +@end diff --git a/sc4pd/headers/app/AIHTMLDecoder.h b/sc4pd/headers/app/AIHTMLDecoder.h new file mode 100644 index 0000000..492d663 --- /dev/null +++ b/sc4pd/headers/app/AIHTMLDecoder.h @@ -0,0 +1,28 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import +#import "AIStringAdditions.h" + +@interface AIHTMLDecoder : NSObject { + +} + ++ (NSAttributedString *)decodeHTML:(NSString *)inMessage; ++ (NSString *)encodeHTML:(NSAttributedString *)inMessage encodeFullString:(BOOL)encodeFullString; ++ (NSString *)encodeHTML:(NSAttributedString *)inMessage headers:(BOOL)includeHeaders fontTags:(BOOL)includeFontTags closeFontTags:(BOOL)closeFontTags styleTags:(BOOL)includeStyleTags closeStyleTagsOnFontChange:(BOOL)closeStyleTagsOnFontChange encodeNonASCII:(BOOL)encodeNonASCII; + +@end diff --git a/sc4pd/headers/app/AIStringAdditions.h b/sc4pd/headers/app/AIStringAdditions.h new file mode 100644 index 0000000..b0a5a64 --- /dev/null +++ b/sc4pd/headers/app/AIStringAdditions.h @@ -0,0 +1,25 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +@interface NSString (AIStringAdditions) +- (NSString *)compactedString; +- (int)intValueFromHex; +- (NSString *)stringByExpandingBundlePath; +- (NSString *)stringByCollapsingBundlePath; +- (NSString *)stringByTruncatingTailToWidth:(float)inWidth; +@end diff --git a/sc4pd/headers/app/AITextAttributes.h b/sc4pd/headers/app/AITextAttributes.h new file mode 100644 index 0000000..02b0754 --- /dev/null +++ b/sc4pd/headers/app/AITextAttributes.h @@ -0,0 +1,44 @@ +/*-------------------------------------------------------------------------------------------------------*\ +| Adium, Copyright (C) 2001-2003, Adam Iser (adamiser@mac.com | http://www.adiumx.com) | +\---------------------------------------------------------------------------------------------------------/ + | This program is free software; you can redistribute it and/or modify it under the terms of the GNU + | General Public License as published by the Free Software Foundation; either version 2 of the License, + | or (at your option) any later version. + | + | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + | Public License for more details. + | + | You should have received a copy of the GNU General Public License along with this program; if not, + | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + \------------------------------------------------------------------------------------------------------ */ + +#import +#import + +#define AIBodyColorAttributeName @"AIBodyColor" + +@interface AITextAttributes : NSObject { + + NSMutableDictionary *dictionary; + + NSString *fontFamilyName; + NSFontTraitMask fontTraitsMask; + int fontSize; + +} + ++ (id)textAttributesWithFontFamily:(NSString *)inFamilyName traits:(NSFontTraitMask)inTraits size:(int)inSize; +- (void)dealloc; +- (void)setFontFamily:(NSString *)inName; +- (void)setFontSize:(int)inSize; +- (void)enableTrait:(NSFontTraitMask)inTrait; +- (void)disableTrait:(NSFontTraitMask)inTrait; +- (NSDictionary *)dictionary; +- (void)setUnderline:(BOOL)inUnderline; +- (void)setTextColor:(NSColor *)inColor; +- (void)setTextBackgroundColor:(NSColor *)inColor; +- (void)setBackgroundColor:(NSColor *)inColor; +- (void)setLinkURL:(NSString *)inURL; + +@end diff --git a/sc4pd/headers/app/ChangeCounter.h b/sc4pd/headers/app/ChangeCounter.h new file mode 100644 index 0000000..db74fe5 --- /dev/null +++ b/sc4pd/headers/app/ChangeCounter.h @@ -0,0 +1,30 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +class ChangeCounter +{ + int changes, updates; +public: + ChangeCounter() { changes = updates = 0; } + bool NeedsUpdate() { return changes != updates; } + void Update() { updates = changes; } + void Change() { changes++; } +}; + diff --git a/sc4pd/headers/app/ControlSpec.h b/sc4pd/headers/app/ControlSpec.h new file mode 100644 index 0000000..7446759 --- /dev/null +++ b/sc4pd/headers/app/ControlSpec.h @@ -0,0 +1,36 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* +struct ControlSpec { + float minval, maxval, initial; + int numticks; + bool constrained; + + ControlSpec(); +}; + +inline ControlSpec() + : minval(0.), maxval(1.), initial(0.), numticks(11), constrained(false) +{ +} + + +*/ \ No newline at end of file diff --git a/sc4pd/headers/app/DrawBackground.h b/sc4pd/headers/app/DrawBackground.h new file mode 100644 index 0000000..e5fe040 --- /dev/null +++ b/sc4pd/headers/app/DrawBackground.h @@ -0,0 +1,83 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import "SCGeom.h" + +class DrawBackground +{ +public: + DrawBackground(); + virtual void draw(CGContextRef cgc, CGRect rect); + virtual void drawSelf(CGContextRef cgc, CGRect rect); +}; + + +class SolidColorBackground : public DrawBackground +{ +public: + SolidColorBackground(SCColor inColor); + virtual void drawSelf(CGContextRef cgc, CGRect rect); +private: + SCColor mColor; +}; + +enum { + grad_Horizontal, + grad_Vertical, + grad_Narrow, + grad_Wide +}; + +class GradientBackground : public DrawBackground +{ +public: + GradientBackground(SCColor inStartColor, SCColor inEndColor, int inDirection, int inSteps); + virtual void drawSelf(CGContextRef cgc, CGRect rect); + +protected: + SCColor mStartColor, mEndColor; + int mDirection, mSteps; +}; + +class HiliteGradientBackground : public GradientBackground +{ +public: + HiliteGradientBackground(SCColor inStartColor, SCColor inEndColor, int inDirection, int inSteps, float inFrac = .33); + + virtual void drawSelf(CGContextRef cgc, CGRect rect); + +protected: + float mFrac, mFrac1; +}; + +/* +class TiledBackground : public DrawBackground +{ +public: + TiledBackground(NSImage* inTile); + + virtual void drawSelf(CGContextRef cgc, CGRect rect); + +protected: + NSImage* mTile; + CGRect mTiledBounds; +}; + +*/ diff --git a/sc4pd/headers/app/GetStringFromUser.h b/sc4pd/headers/app/GetStringFromUser.h new file mode 100644 index 0000000..0e13d71 --- /dev/null +++ b/sc4pd/headers/app/GetStringFromUser.h @@ -0,0 +1,46 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#import + +@interface GetStringFromUser : NSObject { + NSString *string; + id textField; + id promptField; + id okButton; + id cancelButton; +} + ++ (id)sharedInstance; + +/* Loads UI lazily */ +- (NSPanel *)getStringPanel; + +- (NSString *)string; +- (void)setString:(NSString *)string; + +- (void)setPrompt:(NSString *)string; + +/* Action methods, sent from the find panel UI; can also be connected to menu items */ +- (void)ok:(id)sender; +- (void)cancel:(id)sender; + +@end diff --git a/sc4pd/headers/app/GoToPanel.h b/sc4pd/headers/app/GoToPanel.h new file mode 100644 index 0000000..6808884 --- /dev/null +++ b/sc4pd/headers/app/GoToPanel.h @@ -0,0 +1,52 @@ +/* + * GoToPanel.M + * SC3lang + * + * Created by j. trutzschler on 02 sept 2003. + derived from TextFinder.m by Ali Ozer + + a panel that searches and selects a line + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#import + +@interface GoToPanel : NSObject { + id findTextField; + id okButton; +} + +/* Common way to get a text finder. One instance of TextFinder per app is good enough. */ ++ (id)sharedInstance; + +/* Main method for external users; does a find in the first responder. Selects found range or beeps. */ +- (void)selectLine:(id)sender; +- (void) getAndDisplayCurrentLine; +- (void)prselectLine:(int)linenum; + +/* Loads UI lazily */ +- (NSPanel *)gotoLinePanel; + +/* Gets the first responder and returns it if it's an NSTextView */ +- (NSTextView *)textObjectToSelectIn; + +- (void)orderFrontGotoLinePanel:(id)sender; + +/* Misc internal methods */ +- (void)appDidActivate:(NSNotification *)notification; + + +@end diff --git a/sc4pd/headers/app/MyDocument.h b/sc4pd/headers/app/MyDocument.h new file mode 100644 index 0000000..d52eabc --- /dev/null +++ b/sc4pd/headers/app/MyDocument.h @@ -0,0 +1,107 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import +#import "UserPanel.h" +#include "PyrObject.h" +#include "PyrKernel.h" +#include "GC.h" +#include "VMGlobals.h" + +extern pthread_mutex_t gLangMutex; +extern PyrSymbol *s_closed; + +@interface MyDocument : NSDocument +{ + IBOutlet NSTextView* initTextView; + IBOutlet NSTextView* textView; + IBOutlet NSScrollView* scrollView; + Boolean isRichText; + struct PyrObject *mWindowObj; +} + + +- (NSTextView*)makeTextView; +- (NSTextView*) textView; + +- (void)windowControllerDidLoadNib:(NSWindowController*) aController; + +- (void)addDocument; + +- (IBAction)openCode:(id)sender; +- (IBAction)methodTemplates: (id)sender; +- (IBAction)methodReferences: (id)sender; + +- (IBAction)balanceParens: (id)sender; + +- (IBAction)syntaxColorize: (id)sender; +- (void) insertText: (char*) text length: (int)length; +- (IBAction)shiftLeft: (id)sender; +- (IBAction)shiftRight: (id)sender; +- (IBAction)commentCode: (id)sender; +- (IBAction)uncommentCode:(id)sender; + +- (IBAction) executeSelection: (id) sender; +- (NSString*)currentlySelectedTextOrLine: (NSRange*) outRange; +-(void)selectRangeStart:(int)rangeStart size:(int)rangeSize; + +- (IBAction) showHelp: (id) sender; + +- (BOOL) textView: (NSTextView *) textView + clickedOnLink: (id) link + atIndex: (unsigned) charIndex; +- (IBAction) createLink: (id) sender; + +- (void)sendSelection: (char*) methodName; + +- (NSString *)windowNibName; + +- (BOOL)writeToFile:(NSString*) path ofType:(NSString *)aType; +- (BOOL)readFromFile:(NSString *)path ofType:(NSString *)aType; + +- (BOOL) shouldRunSavePanelWithAccessoryView; + +- (BOOL)windowShouldClose:(id)sender; +- (void)windowWillClose:(NSNotification *)aNotification; +- (IBAction) becomePostWindow: (id) sender; +- (BOOL) isDocumentEdited; + +- (void)doToggleRich; +// toggleRich: puts up an alert before ultimately calling doToggleRich +- (IBAction)toggleRich:(id)sender; +- (void)setRichText:(BOOL)flag; + +- (BOOL)validateMenuItem:(NSMenuItem *)aCell; + +- (void)setSCObject: (struct PyrObject*)inObject; +- (struct PyrObject*)getSCObject; +- (void) closeWindow; +- (void)setBackgroundColor:(NSColor *)color; +- (NSScrollView*) scrollView; +- (NSTextView*) initTextView; +-(void)selectLine:(int)linenum; +- (IBAction)selectLineWindow: (id) sender; +- (void) callSCLangWithMethod: (PyrSymbol*) method; + +@end + +NSString* pathOfHelpFileFor(NSString* selection); +void showHelpFor(NSString* selection); + diff --git a/sc4pd/headers/app/RendezvousClient.h b/sc4pd/headers/app/RendezvousClient.h new file mode 100644 index 0000000..e66f518 --- /dev/null +++ b/sc4pd/headers/app/RendezvousClient.h @@ -0,0 +1,39 @@ +// +// RendezvousClient.h +// SC3lang +// +// Created by C. Ramakrishnan on Mon Feb 24 2003. +// Copyright (c) 2003 __MyCompanyName__. All rights reserved. +// + +#import + +@interface OSCService : NSObject { +// a glorified struct (declared as an Obj-C class so I can put it in NSArrays) +// stored in the oscServices ivar of RendezvousClient +@public + NSNetService* netService; + BOOL isResolved; + NSString* hostName; + const struct sockaddr_in* sockaddr; + unsigned hostAddress; + unsigned short port; + int refCount; +} + +@end + +@interface RendezvousClient : NSObject { + NSNetServiceBrowser* browser; + NSMutableArray* oscServices; +} + ++ (RendezvousClient*)sharedClient; + +// interface +- (void)findOSCServices; +- (OSCService*)oscServiceAtIndex:(unsigned)index; +- (unsigned)numberOfOSCServices; + +@end + diff --git a/sc4pd/headers/app/SCDialog.h b/sc4pd/headers/app/SCDialog.h new file mode 100644 index 0000000..fdebdbb --- /dev/null +++ b/sc4pd/headers/app/SCDialog.h @@ -0,0 +1,41 @@ +// +// SCDialogs.h +// SC3lang +// +// Created by cruxxial on Tue Dec 17 2002. +// Copyright (c) 2002 crucial-systems. All rights reserved. +// + +#import + +#include "PyrPrimitive.h" +#include "PyrObject.h" +#include "PyrKernel.h" +#include "VMGlobals.h" +#include "GC.h" +#include "PyrSched.h" +#import "SCVirtualMachine.h" + +@interface SCDialog : NSObject { + PyrObject *receiver; + PyrObject *result; + NSOpenPanel *openPanel; +} + ++(id)receiver:(PyrObject*)argReceiver result:(PyrObject*)argResult; +-(id)initWithReceiver:(PyrObject*)argReceiver result:(PyrObject*)argResult; + +-(void)ok; +-(void)cancel; +-(void)error; + +-(void)returnPaths:(NSArray*)urls; +-(void)getPaths; +-(void)returnPath:(NSString*)path; + + +// call method on self when SCVM is ready for sclang usage +-(void)scvmDeferWithSelector:(SEL)selector; + + +@end diff --git a/sc4pd/headers/app/SCGeom.h b/sc4pd/headers/app/SCGeom.h new file mode 100644 index 0000000..04904a4 --- /dev/null +++ b/sc4pd/headers/app/SCGeom.h @@ -0,0 +1,90 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import +#include "SC_BoundsMacros.h" + +struct SCColor { + float red, green, blue, alpha; +}; +typedef struct SCColor SCColor; + +inline SCColor SCMakeColor(float red, float green, float blue, float alpha) +{ + SCColor sccolor; + sccolor.red = red; + sccolor.green = green; + sccolor.blue = blue; + sccolor.alpha = alpha; + return sccolor; +} + +struct SCPoint { + float x, y; +}; + +inline SCPoint SCMakePoint(float x, float y) +{ + SCPoint p; + p.x = x; + p.y = y; + return p; +} + +struct SCRect { + float x, y, width, height; +}; + +inline SCRect SCRectUnion(SCRect a, SCRect b) +{ + if (a.height <= 0. && a.width <= 0.) return b; + if (b.height <= 0. && b.width <= 0.) return a; + + SCRect u; + u.x = sc_min(a.x, b.x); + u.y = sc_min(a.y, b.y); + u.width = sc_max(a.x + a.width, b.x + b.width) - u.x; + u.height = sc_max(a.y + a.height, b.y + b.height) - u.y; + return u; +} + +inline bool SCRectsDoIntersect(SCRect a, SCRect b) +{ + if (a.x + a.width < b.x) return false; + if (a.y + a.height < b.y) return false; + if (a.x > b.x + b.width) return false; + if (a.y > b.y + b.height) return false; + return true; +} + +inline SCRect SCMakeRect(float x, float y, float width, float height) +{ + SCRect r; + r.x = x; r.y = y; r.width = width; r.height = height; + return r; +} + +inline bool SCPointInRect(SCPoint p, SCRect r) +{ + return + p.x >= r.x && p.x <= r.x + r.width + && p.y >= r.y && p.y <= r.y + r.height; + +} diff --git a/sc4pd/headers/app/SCGraphView.h b/sc4pd/headers/app/SCGraphView.h new file mode 100644 index 0000000..84b259d --- /dev/null +++ b/sc4pd/headers/app/SCGraphView.h @@ -0,0 +1,55 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import +#import "SCView.h" + +@interface SCGraphView : NSView +{ + struct PyrObject *mWindowObj; + SCTopView *mTopView; + bool mDragStarted; + SCView* mMenuView; + bool windowShouldClose; +} + +- (void)drawRect: (NSRect)bounds; +- (void) keyDown: (NSEvent*) event; +- (void) keyUp: (NSEvent*) event; +- (void) mouseDown: (NSEvent*) event; +- (void)setSCObject: (struct PyrObject*)inObject; +- (struct PyrObject*)getSCObject; +- (BOOL)isFlipped; +- (BOOL)mouseDownCanMoveWindow; + +- (void)setSCTopView: (SCTopView*)inView; +//- (void)dealloc; +- (void)closeWindow; +- (void)willClose; +- (void)setWindowShouldClose:(BOOL)boo; +- (BOOL)windowShouldClose; +- (void) beginDragFrom: (NSPoint)where of: (PyrSlot*)slot; + +- (NSMenu*) menuForEvent:(NSEvent*)event; +- (void)startMenuTracking: (SCView*) inView; + +- (IBAction) toggleUIEditMode: (id) sender; + +@end diff --git a/sc4pd/headers/app/SCService.h b/sc4pd/headers/app/SCService.h new file mode 100644 index 0000000..64a78a0 --- /dev/null +++ b/sc4pd/headers/app/SCService.h @@ -0,0 +1,16 @@ +// +// SCService.h +// SC3lang +// +// Created by C. Ramakrishnan on Mon Oct 20 2003. +// Copyright (c) 2003 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface SCService : NSObject { + +} + +@end diff --git a/sc4pd/headers/app/SCTextView.h b/sc4pd/headers/app/SCTextView.h new file mode 100644 index 0000000..b1b721c --- /dev/null +++ b/sc4pd/headers/app/SCTextView.h @@ -0,0 +1,33 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import + +@interface SCTextView : NSTextView +{ + +} + + - (void) keyDown: (NSEvent*) event; + - (void) mouseDown: (NSEvent*) event; + - (void) autoIndent: (NSEvent*) event; + - (void) mouseDownAction; + +@end diff --git a/sc4pd/headers/app/SCView.h b/sc4pd/headers/app/SCView.h new file mode 100644 index 0000000..a752445 --- /dev/null +++ b/sc4pd/headers/app/SCView.h @@ -0,0 +1,784 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import "DrawBackground.h" +#include "PyrObject.h" + +enum { + layout_NoResize, + layout_Resize +}; + +enum { + // mHResize + layout_FixedLeft = -1, + layout_HElastic, + layout_FixedRight, +}; +enum { + // mVResize + layout_FixedTop = -1, + layout_VElastic, + layout_FixedBottom +}; + + +struct Layout +{ + Layout(); + + // layout params for dynamic layout views + float mMinWidth, mMaxWidth, mMinHeight, mMaxHeight; + float mWeight; + bool mShouldResize; + // layout params for composite views + char mHResize, mVResize; +}; + + + +class SCView; +class SCContainerView; +class SCTopView; + +typedef SCView* (*SCViewCtor)(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +struct SCViewMaker +{ + SCViewMaker(const char* inName, SCViewCtor inCtor); + static SCView* MakeSCView(PyrObject* inObj, SCContainerView *inParent, SCRect inBounds, const char* classname); + + SCViewMaker *mNext; + SCViewCtor mCtor; + const char* mName; +}; + +extern SCViewMaker *gSCViewMakers; +extern SCView *gAnimatedViews; + +class SCView +{ +public: + SCView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCView(); + + virtual void draw(SCRect inDamage); + virtual void drawFocus(SCRect inDamage); + virtual void drawDisabled(SCRect inDamage); + virtual void drawDragHilite(SCRect inDamage); + virtual void drawIfNecessary(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseOver(SCPoint where); + virtual void keyDown(int character, int modifiers, unsigned short keycode); + virtual void keyUp(int character, int modifiers, unsigned short keycode); + virtual bool shouldDim(); + void beginDrag(SCPoint where); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + + bool isFocus() const; + bool hit(SCPoint p) const; + void refresh(); + void refreshFocus(); + void setDragHilite(bool inFlag); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool isDragSource() const; + virtual SCView* findView(SCPoint where); + virtual SCView* findViewByID(int32 inID); + virtual void makeFocus(bool focus); + virtual SCView* nextFocus(bool *foundFocus, bool canFocus); + virtual SCView* prevFocus(SCView **prevView, bool canFocus); + virtual bool canFocus(); + + void sendMessage(PyrSymbol *method, int numargs, PyrSlot *args, PyrSlot *result); + + virtual void setBounds(SCRect inBounds); + virtual SCRect getBounds(); + virtual Layout getLayout(); + + SCView* next() { return mNext; } + SCContainerView* parent() { return mParent; } + + virtual NSMenu* contextMenu(SCPoint inPoint); + + virtual void setMenuItemChosen(int inItem) {} + + PyrObject* GetSCObj() { return mObj; } + SCView* NextAnimatedView() const { return mNextAnimatedView; } + + void startAnimation(); + void stopAnimation(); + virtual void animate() { refresh(); } + +protected: + friend class SCContainerView; + + SCView *mNext; + SCView *mNextAnimatedView; + SCView *mPrevAnimatedView; + SCContainerView *mParent; + SCTopView *mTop; + PyrObject* mObj; + SCRect mBounds; + Layout mLayout; + DrawBackground* mBackground; + bool mVisible; + bool mEnabled; + bool mCanFocus; + bool mDragHilite; + int32 mID; +}; + + +class SCContainerView : public SCView +{ +public: + SCContainerView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCContainerView(); + + virtual void drawIfNecessary(SCRect inDamage); + + virtual void add(SCView *inChild); + virtual void remove(SCView *inChild); + virtual SCView* findView(SCPoint where); + virtual SCView* findViewByID(int32 inID); + virtual void makeFocus(bool focus); + virtual SCView* nextFocus(bool *foundFocus, bool canFocus); + virtual SCView* prevFocus(SCView **prevView, bool canFocus); + virtual bool canFocus(); + +protected: + SCView *mChildren; + int mNumChildren; +}; + +class SCCompositeView : public SCContainerView +{ +public: + SCCompositeView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCCompositeView(); + + virtual void setBounds(SCRect inBounds); + +protected: +}; + +class SCLayoutView : public SCContainerView +{ +public: + SCLayoutView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCLayoutView(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + +protected: + float mSpacing; +}; + +class SCHLayoutView : public SCLayoutView +{ +public: + SCHLayoutView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCHLayoutView(); + + virtual void setBounds(SCRect inBounds); + +protected: +}; + +class SCVLayoutView : public SCLayoutView +{ +public: + SCVLayoutView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCVLayoutView(); + + virtual void setBounds(SCRect inBounds); + +protected: +}; + +// tell host to draw stuff. +typedef void (*DamageCallback)(SCRect inRect, void *inData); +typedef void (*DragCallback)(SCPoint where, PyrSlot* inSlot, void *inData); + +class SCTopView : public SCCompositeView +{ +public: + SCTopView(PyrObject* inObj, SCRect inBounds); + + SCView *focusView() { return mFocusView; } + + void resetFocus(); + void addDamage(SCRect inRect); + void beginDragCallback(SCPoint where, PyrSlot* slot); + + void setDamageCallback(DamageCallback inFunc, void *inHostData) + { mDamageCallback = inFunc; mHostData = inHostData; } + void setDragCallback(DragCallback inFunc) + { mDragCallback = inFunc; } + + void tabNextFocus(); + void tabPrevFocus(); + void setDragView(SCView *inView); + + NSView* GetNSView() { return mNSView; } + void SetNSView(NSView* inView) { mNSView = inView; } + + bool ConstructionMode() { return mConstructionMode; } + void SetConstructionMode(bool inFlag) { mConstructionMode = inFlag; } + + virtual void drawFocus(SCRect inDamage); + +protected: + friend class SCView; + void focusIs(SCView *inView) { mFocusView = inView; } + + DamageCallback mDamageCallback; + DragCallback mDragCallback; + void *mHostData; + SCView *mFocusView; + SCView *mDragView; + NSView *mNSView; + + bool mConstructionMode; +}; + +inline bool SCView::isFocus() const { return mTop->focusView() == this; } + +class SCSlider : public SCView +{ +public: + SCSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + double value() { return mValue; } + bool setValue(double inValue, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + virtual void setValueFromPoint(SCPoint point); + void calcThumbRect(); + + SCRect mThumbRect; + double mValue, mStepSize, mStepScale; + DrawBackground* mKnob; +}; +SCView* NewSCSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCRangeSlider : public SCView +{ +public: + SCRangeSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + bool setValue(double inLo, double inHi, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + virtual void setValueFromPoint(SCPoint point); + // sc.solar addition + void moveRangeFromPoint(SCPoint point); + void adjustLoFromPoint(SCPoint point); + void adjustHiFromPoint(SCPoint point); + // sc.solar addition end + void calcRangeRect(); + + SCRect mRangeRect; + double mLo, mHi, mStepSize, mStepScale; + SCPoint mAnchor; + DrawBackground* mKnob; +}; +SCView* NewSCRangeSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + + +class SC2DSlider : public SCView +{ +public: + SC2DSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + virtual bool setValue(double inLo, double inHi, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + virtual void setValueFromPoint(SCPoint point); + void calcThumbRect(); + + SCRect mThumbRect; + double mX, mY; + double mStepSize, mStepScale; + DrawBackground* mKnob; +}; +SCView* NewSC2DSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SC2DTabletSlider : public SC2DSlider +{ +public: + SC2DTabletSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool setValue(double inX, double inY,bool send); + +protected: + int mClipInBounds; + +}; +SCView* NewSC2DTabletSlider(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +#include "SC_SndBuf.h" + +const int kMaxScopeChannels = 16; +class SCScope : public SCView +{ +public: + SCScope(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCScope(); + + virtual void draw(SCRect inDamage); + virtual void draw0(CGContextRef cgc); + virtual void draw1(CGContextRef cgc); + virtual void draw2(CGContextRef cgc); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void animate(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + SCPoint pixelToUnits(SCPoint p, SCRect r) + { + return SCMakePoint( + (p.x - r.x) * mZoom.x + mScroll.x, + (p.y - r.y) * mZoom.y + mScroll.y); + } + SCPoint unitsToPixel(SCPoint u, SCRect r) + { + return SCMakePoint( + (u.x - mScroll.x) * mInvZoom.x + r.x, + (u.y - mScroll.y) * mInvZoom.y + r.y); + } + +protected: + + int mBufNum; + SndBuf mSndBuf; + SCPoint mZoom, mInvZoom, mScroll; + int mStyle; // 0 = separate, 1 = overlay, 2 = x,y. + SCColor mWaveColors[kMaxScopeChannels]; + SCColor mGridColor; + bool mGridOn; +}; +SCView* NewSCScope(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + + +const int kLabelSize = 64; +struct SCButtonState +{ + char mLabel[kLabelSize]; + SCColor mLabelColor; + SCColor mButtonColor; +}; + +const int kFontNameSize = 80; + +class SCButton : public SCView +{ +public: + SCButton(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCButton(); + + virtual void draw(SCRect inDamage); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + bool setValue(int inValue, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + + int mValue; + char mFontName[kFontNameSize]; + float mFontSize; + int mNumStates; + SCButtonState *mStates; + bool mPushed; +}; +SCView* NewSCButton(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCPopUpMenu : public SCView +{ +public: + SCPopUpMenu(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCPopUpMenu(); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + bool setValue(int inValue, bool send); + virtual void setMenuItemChosen(int inItem) { setValue(inItem, true); } + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + + int mValue; + MenuHandle mMenuH; + char mFontName[kFontNameSize]; + float mFontSize; + SCColor mStringColor; +}; +SCView* NewSCPopUpMenu(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCListView : public SCView +{ +public: + SCListView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCListView(); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers, NSEvent *theEvent); + + bool setValue(int inValue, bool send); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + + void scrollToValue(); + +protected: + + int mValue; + CFMutableArrayRef mArray; + char mFontName[kFontNameSize]; + float mFontSize; + float mScroll; + float mAnchorScroll; + SCPoint mAnchor; + SCColor mStringColor; + SCColor mSelectedStringColor; + SCColor mHiliteColor; + int mAlignment; + NSSize mStrSize; + bool mScrolling; +}; +SCView* NewSCListView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +//by jan trutzschler (jt@kandos.de) +class SCMultiSliderView : public SCView +{ +public: + SCMultiSliderView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCMultiSliderView(); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + void setSelection(SCPoint where); + bool setValue(int inX, double inY, bool send); + //virtual void setPoint(int x, double y, bool send); + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + void setVisibleSize(); + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + int indexFromPoint(SCPoint where); +// int getVisibleMax(); + + double valueFromPoint(SCPoint where); + void setValueFromPoint(SCPoint point); + SCRect calcThumbRect(int xIn, double valIn, double step); + int mThumbSize, mThumbSizeY; // size of the rect + int mTabSize, mVisibleSize; // size of the table + SCColor mFillColor; + SCColor mStrokeColor; + SCRect mThumbRect; + double mCurrentY, mCurrentX; + int mCurrentIndex, mStartIndex, mSelectionSize; + double mStepSize, mStepScale; + double * mYValues; + double * mSecYValues; + DrawBackground* mKnob; + float mXOffset ; //space between points + bool mReadOnly, mDrawLinesActive, mShowIndex, mDrawRectsActive, mIsHorizontal, mIsFilled; + SCPoint mPrevPoint; + int mElasticMode; + double mElasticIndexStep; + +}; +SCView* NewSCMultiSliderView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); +//// +//by jan truetzschler jt@kandos.de +struct SCEnvObject { + SCColor mColor; //changes between selected and mObjectColor + SCColor mObjectColor; //if its not selected + SCRect mRect; + int mNumConnection; + SCPoint mDrawPoint; + double * mConnections; //tells to where it is connected + int mNumInputs, mNumOutputs; + double x, y; + bool mIsSelected, mIsVisible, mIsStatic; + char *mString; +}; +typedef struct SCEnvObject SCEnvObject; + +class SCEnvelopeView : public SCView +{ +public: + SCEnvelopeView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCEnvelopeView(); + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + + void setSelection(SCPoint where, bool fixed, bool checkForConnection); + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + + void setValueFromPoint(SCPoint point); + bool setValue(SCEnvObject * envob, double x, double y, bool send); + int allocSlotEnvObjArray(PyrSlot *slot, SCEnvObject **arr); + bool setEnvRect(double valX, double valY, SCEnvObject * envobIn); + + int mThumbSize, mThumbSizeY; // size of the rect + int mTabSize, mVisibleSize, mActiveSize; // size of the table + SCColor mFillColor, mSelectedColor, mStrokeColor; + SCRect mThumbRect; + double mCurrentY, mCurrentX, mAbsoluteX; + int mCurrentIndex, mStartIndex, mSelectionSize, mLastIndex; + double mStepSize, mStepScale; + SCEnvObject * mEnvObj; + //DrawBackground* mKnob; + bool mDrawLinesActive, mShowIndex, mDrawRectsActive, mIsFilled, mIsFixedSelection, mIsEnvView; + int mSelectedIndex; + SCPoint mMousePoint; + + double xGridMultiplier; + + //draw string in box + char mFontName[kFontNameSize]; + float mFontSize; + SCColor mStringColor; + int mAlignment; + bool mDrawCenteredConnection; + + +}; +SCView* NewSCEnvelopeView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +// + +class SCUserView : public SCView +{ +public: + SCUserView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void keyDown(int character, int modifiers); + virtual void keyUp(int character, int modifiers); + +protected: + void mouseAction(PyrSymbol *method, SCPoint where, int modifiers); +}; +SCView* NewSCUserView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +enum { + kSCAlignLeft = -1, + kSCAlignCenter, + kSCAlignRight +}; + +class SCStaticText : public SCView +{ +public: + SCStaticText(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCStaticText(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + +protected: + virtual void drawString(SCRect bounds); + + char *mString; + char mFontName[kFontNameSize]; + float mFontSize; + SCColor mStringColor; + int mAlignment; + +}; +SCView* NewSCStaticText(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +class SCNumberBox : public SCStaticText +{ +public: + SCNumberBox(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCNumberBox(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + //virtual void mouseEndTrack(SCPoint where, int modifiers); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + virtual int getProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: + SCColor mBoxColor; +}; +SCView* NewSCNumberBox(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + +class SCDragSource : public SCStaticText +{ +public: + SCDragSource(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCDragSource(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + +protected: +}; +SCView* NewSCDragSource(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCDragSink : public SCStaticText +{ +public: + SCDragSink(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCDragSink(); + + virtual void draw(SCRect inDamage); + virtual bool shouldDim(); + + virtual bool canReceiveDrag(); + virtual void receiveDrag(); + +protected: +}; +SCView* NewSCDragSink(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +class SCDragBoth : public SCDragSink +{ +public: + SCDragBoth(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + virtual void draw(SCRect inDamage); + + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + +protected: +}; +SCView* NewSCDragBoth(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + + +//felix +class SCTabletView : public SCView +{ +public: + SCTabletView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + virtual ~SCTabletView(); + + virtual int setProperty(PyrSymbol *symbol, PyrSlot *slot); + + virtual void mouseBeginTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseTrack(SCPoint where, int modifiers,NSEvent *theEvent); + virtual void mouseEndTrack(SCPoint where, int modifiers,NSEvent *theEvent); +protected: + int mClipToBounds; +}; +SCView* NewSCTabletView(SCContainerView *inParent, PyrObject* inObj, SCRect inBounds); + diff --git a/sc4pd/headers/app/SCVirtualMachine.h b/sc4pd/headers/app/SCVirtualMachine.h new file mode 100644 index 0000000..354e8a5 --- /dev/null +++ b/sc4pd/headers/app/SCVirtualMachine.h @@ -0,0 +1,65 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import + + +@interface SCVirtualMachine : NSObject { + NSMutableArray *deferredOperations; + NSMutableArray *guiWindows; + NSTimer *deferredTaskTimer; + NSTimer *appClockTimer; +} + ++ (id)sharedInstance; + +- (id)init; +- (void)start; +- (void)doPeriodicTask: (NSTimer*) timer; +- (void)doClockTask: (NSTimer*) timer; +- (void)setCmdLine: (const char*) text length: (int)length; +- (void)sendMain: (char*) methodName; + +- (void)defer: (NSInvocation*) action; +- (void)performDeferredOperations; +- (void)doAnimatedViews; + +- (void)addWindow: (NSWindow*)window; +- (void)closeAllGUIWindows; + +- (IBAction) runMain: (id) sender; +- (IBAction) stopMain: (id) sender; +- (IBAction) compileLibrary: (id) sender; +- (IBAction) newSCWindow: (id) sender; +- (IBAction)clearPostWindow:(id)sender; +- (void)postWindowToFront:(id)sender; + +// deferred primitives + + +- (void)becomeFullScreen: (NSWindow*)window; +- (void)endFullScreen: (NSWindow*)window; +- (void)loadUserPanel:(NSString*)filename SCObject: (void*)scobj; + + +-(IBAction)showHelp:(id)sender; + + +@end diff --git a/sc4pd/headers/app/TabletEvents.h b/sc4pd/headers/app/TabletEvents.h new file mode 100755 index 0000000..3607ab9 --- /dev/null +++ b/sc4pd/headers/app/TabletEvents.h @@ -0,0 +1,75 @@ +/*---------------------------------------------------------------------------- + +FILE NAME + +TabletEvents.h - Header file for TabletEvent Category. + This is an extension to the NSEvent class. + +COPYRIGHT + +Copyright WACOM Technology, Inc. 2001. + +All rights reserved. + +----------------------------------------------------------------------------*/ + +#import +#import + +@interface NSEvent ( TabletEvents ) + +- (void *)eventRef; +- (BOOL) isTabletPointerEvent; +- (BOOL) isTabletProximityEvent; +- (void) setLocation:(NSPoint)loc; +- (TabletPointerRec) tabletRec; +- (SInt32) absoluteX; +- (SInt32) absoluteY; +- (SInt32) absoluteZ; +- (void) getAbsoluteX:(SInt32*)absX Y:(SInt32*)absY Z:(SInt32*)absZ; +- (NSPoint) tilt; +- (UInt16) rawTabletPressure; +- (float) scaledTabletPressure; +- (float) rotationInDegrees; /* 0¡ <-> +359.9999¡ */ +- (float) rotationInRadians; /* 0 <-> 2¹ */ +- (UInt16) deviceID; + +@end + +/////////////////////////////////////////////////////////////////////////// +/* This is the name of the Notification sent when a proximity event is + captured by the application */ +extern NSString *kProximityNotification; + +/* vendor-defined ID - typically will be USB vendor ID */ +extern NSString *kVendorID; + +/* vendor-defined tablet ID */ +extern NSString *kTabletID; + +/* vendor-defined ID of the specific pointing device */ +extern NSString *kPointerID; + +/* unique device ID - matches to deviceID field in tablet event */ +extern NSString *kDeviceID; + +/* unique tablet ID */ +extern NSString *kSystemTabletID; + +/* vendor-defined pointer type */ +extern NSString *kVendorPointerType; + + /* vendor-defined serial number of the specific pointing device */ +extern NSString *kPointerSerialNumber; + + /* vendor-defined unique ID for this pointer */ +extern NSString *kUniqueID; + +/* mask representing the capabilities of the device */ +extern NSString *kCapabilityMask; + + /* type of pointing device - enum to be defined */ +extern NSString *kPointerType; + + /* non-zero = entering; zero = leaving */ +extern NSString *kEnterProximity; diff --git a/sc4pd/headers/app/TextFinder.h b/sc4pd/headers/app/TextFinder.h new file mode 100644 index 0000000..66de160 --- /dev/null +++ b/sc4pd/headers/app/TextFinder.h @@ -0,0 +1,64 @@ +/* + Reusable find panel functionality (find, replace). + Need one shared instance of TextFinder to which the menu items and widgets in the find panel are connected. + Loads UI lazily. + Works on first responder, assumed to be an NSTextView. +*/ + +#import + +#define Forward YES +#define Backward NO + +@interface TextFinder : NSObject { + NSString *findString; + NSString *replaceString; + id findTextField; + id replaceTextField; + id ignoreCaseButton; + id findNextButton; + id replaceAllScopeMatrix; + id statusField; + BOOL lastFindWasSuccessful; +} + +/* Common way to get a text finder. One instance of TextFinder per app is good enough. */ ++ (id)sharedInstance; + +/* Main method for external users; does a find in the first responder. Selects found range or beeps. */ +- (BOOL)find:(BOOL)direction; + +/* Loads UI lazily */ +- (NSPanel *)findPanel; + +/* Gets the first responder and returns it if it's an NSTextView */ +- (NSTextView *)textObjectToSearchIn; + +/* Get/set the current find string. Will update UI if UI is loaded */ +- (NSString *)findString; +- (void)setFindString:(NSString *)string; +- (void)setFindString:(NSString *)string writeToPasteboard:(BOOL)flag; + +/* Get/set the current replace string. Will update UI if UI is loaded */ +- (NSString *)replaceString; +- (void)setReplaceString:(NSString *)string; + +/* Misc internal methods */ +- (void)appDidActivate:(NSNotification *)notification; +- (void)loadFindStringFromPasteboard; +- (void)loadStringToPasteboard:(NSString *)string; + +/* Action methods, sent from the find panel UI; can also be connected to menu items */ +- (void)findNext:(id)sender; +- (void)findPrevious:(id)sender; +- (void)findNextAndOrderFindPanelOut:(id)sender; +- (void)replace:(id)sender; +- (void)replaceAndFind:(id)sender; +- (void)replaceAll:(id)sender; +- (void)orderFrontFindPanel:(id)sender; +- (void)takeFindStringFromSelection:(id)sender; +- (void)takeReplaceStringFromSelection:(id)sender; +- (void)jumpToSelection:(id)sender; + +@end + diff --git a/sc4pd/headers/app/UserPanel.h b/sc4pd/headers/app/UserPanel.h new file mode 100644 index 0000000..4dd724b --- /dev/null +++ b/sc4pd/headers/app/UserPanel.h @@ -0,0 +1,40 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#import + +@interface UserPanel : NSObject +{ + IBOutlet id window; + void *scobject; +} + ++ (void)closeAll; + +- (id)init; +- (NSWindow*)window; +- (void)close; +- (void)windowWillClose:(NSNotification *)aNotification; +- (void)setSCObject: (void*)inObject; +- (void*) getSCObject; + +- (IBAction) panelAction: (id) sender; + +@end diff --git a/sc4pd/headers/common/SC_AllocPool.h b/sc4pd/headers/common/SC_AllocPool.h new file mode 100755 index 0000000..fc9d72a --- /dev/null +++ b/sc4pd/headers/common/SC_AllocPool.h @@ -0,0 +1,278 @@ + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* +This is based on Doug Lea's allocator but rewritten so I can read and understand it... +also features of free all-at-once pools are added. +Now uses 16 byte alignment, which does increase the minimum allocation size to 32 bytes +including the overhead. +Improved bit block scanning by using a count leading zeroes instruction. + +*/ + +#ifndef _AllocPool_ +#define _AllocPool_ + +#include "SC_List.h" +#include "clz.h" +#include + +const int kNumAllocBins = 128; +const int kNumSmallBins = 64; +const int kMaxSmallBin = kNumSmallBins - 1; +const int kBinWidth = 8; +const int kMaxSmallBinSize = kNumSmallBins * kBinWidth; +const int kBinBlockWidth = 4; +const int kBinBlockMask = kBinBlockWidth - 1; + +const size_t kAlign = 16; +const size_t kAlignMask = kAlign - 1; +const size_t kChunkFree = 0; +const size_t kChunkInUse = 1; +const size_t kSizeBits = ~kChunkInUse; + +class AllocChunk; +class AllocPool; +typedef AllocChunk *AllocChunkPtr; +typedef Link AllocBin; +typedef AllocBin* AllocBinPtr; + +class AllocChunk : public Link +{ + friend class AllocPool; + + size_t Size() + { return mSize & kSizeBits; } + + size_t PrevSize() + { return mPrevSize & kSizeBits; } + + AllocChunkPtr ChunkAtOffset(size_t inSize) + { return AllocChunkPtr((char*)this + inSize); } + + AllocChunkPtr NextChunk() + { return ChunkAtOffset(Size()); } + + AllocChunkPtr PrevChunk() + { return ChunkAtOffset(-PrevSize()); } + + bool InUse() + { return (bool)(mSize & kChunkInUse); } + + bool PrevInUse() + { return (bool)(mPrevSize & kChunkInUse); } + + void SetSizeFree(size_t inSize) + { mSize = ChunkAtOffset(inSize)->mPrevSize = inSize; } + + void SetSizeInUse(size_t inSize) + { mSize = ChunkAtOffset(inSize)->mPrevSize = inSize | kChunkInUse; } + + void SetNeighborsInUse(size_t inOffset) + { mPrevSize = ChunkAtOffset(inOffset)->mSize = kChunkInUse; } + + bool IsArea() + { return mPrevSize == kChunkInUse && NextChunk()->mSize == kChunkInUse; } + + void* ToPtr() + { return (void*)((char*)this + sizeof(AllocChunk)); } + + size_t mPrevSize; + size_t mSize; +}; + +class AllocArea; +typedef AllocArea* AllocAreaPtr; + +class AllocAreaHdr /* for size calculations */ +{ +protected: + friend class AllocPool; + + AllocAreaPtr mPrev, mNext; + size_t mSize; + void *mUnalignedPointerToThis; +}; + +class AllocArea : public AllocAreaHdr +{ +public: + void SanityCheck(); + +private: + friend class AllocPool; + + AllocChunk mChunk; +}; + +const size_t kMinAllocSize = 2 * kAlign; +// FIXME: add kAlign to overhead? +const size_t kAreaOverhead = sizeof(AllocAreaHdr) + 2 * sizeof(AllocChunk); + +typedef void* (*NewAreaFunc)(size_t size); +typedef void (*FreeAreaFunc)(void *); + +class AllocPool +{ +public: + AllocPool(NewAreaFunc allocArea, FreeAreaFunc freeArea, + size_t areaInitSize, size_t areaMoreSize); + ~AllocPool(); + + void Reinit(); + + void *Alloc(size_t inBytes); + void *Realloc(void* inPtr, size_t inBytes); + void Free(void* inPtr); + void FreeAll(); + void FreeAllInternal(); + + // debugging + size_t TotalFree(); + size_t LargestFreeChunk(); + + void DoCheckPool(); + void DoCheckInUseChunk(AllocChunkPtr p); + + static AllocChunkPtr MemToChunk(void *inPtr) + { return (AllocChunkPtr)((char*)(inPtr) - sizeof(AllocChunk)); } + +private: + void InitAlloc(); + void InitBins(); + AllocAreaPtr NewArea(size_t inAreaSize); + void FreeArea(AllocChunkPtr chunk); + + // debugging + void DoCheckArea(AllocAreaPtr area); + void DoCheckBin(AllocChunkPtr bin, long idx); + void DoCheckChunk(AllocChunkPtr p); + void DoCheckFreeChunk(AllocChunkPtr p); + void DoCheckAllocedChunk(AllocChunkPtr p, size_t s); + void DoGarbageFill(AllocChunkPtr p); + void DoGarbageFill(AllocChunkPtr p, long size); + + // inlines + + static size_t RequestToSize(size_t inReqSize) + { + size_t sizePlusOverhead = inReqSize + sizeof(AllocChunk); + if (sizePlusOverhead <= kMinAllocSize) return kMinAllocSize; + else return (sizePlusOverhead + kAlignMask) & ~kAlignMask; + } + + static int SmallBinIndex(size_t inSize) + { return inSize >> 4; } + + static int BinIndex2(size_t inSize) + { + return + ((inSize < 1024) ? (inSize>>4): + (inSize < 2048) ? 56 + (inSize>>7): + (inSize < 4096) ? 64 + (inSize>>8): + (inSize < 8192) ? 72 + (inSize>>9): + (inSize < 16384) ? 80 + (inSize>>10): + (inSize < 32768) ? 88 + (inSize>>11): + (inSize < 65536) ? 96 + (inSize>>12): + (inSize < 131072) ? 104 + (inSize>>13): + (inSize < 262144) ? 112 + (inSize>>14):127); + } + + static int BinIndex(size_t inSize) + { + if (inSize < 1024) return inSize >> 4; + if (inSize >= 262144) return 127; + int bits = 28 - CLZ(inSize); + return (bits << 3) + (inSize >> bits) ; + } + + void MarkBinBlock(int inIndex) + { + unsigned long word = inIndex >> 5; + unsigned long bitPosition = inIndex & 31; + unsigned long bitValue = 1L << bitPosition; + mBinBlocks[word] |= bitValue; + } + + void ClearBinBlock(int inIndex) + { + unsigned long word = inIndex >> 5; + unsigned long bitPosition = inIndex & 31; + unsigned long bitValue = 1L << bitPosition; + mBinBlocks[word] &= ~bitValue; + } + + int NextFullBin(int inStartingBinIndex) + { + if (inStartingBinIndex >= 128) return -1; + int word = inStartingBinIndex >> 5; + int bitPosition = inStartingBinIndex & 31; + unsigned long bitValue = 1L << bitPosition; + unsigned long binBits = mBinBlocks[word]; + + if (binBits >= bitValue) { + binBits = (~(bitValue - 1) & binBits); + } else { + for (++word; word<4 && !mBinBlocks[word]; ++word) {} + if (word==4) return -1; + binBits = mBinBlocks[word]; + } + bitPosition = CTZ((int32)binBits); + + return (word << 5) + bitPosition; + } + + void LinkFree(AllocChunkPtr inChunk); + /* + { + size_t size = inChunk->Size(); + int index = BinIndex(size); + + AllocChunkPtr bin = mBins + index; + + if (index < kNumSmallBins || bin->IsEmpty()) { + inChunk->InsertAfter(bin); + MarkBinBlock(index); + } else { + AllocChunkPtr link = bin->Next(); + while (link != bin && size < link->Size()) link = link->Next(); + inChunk->InsertBefore(link); + } + } + */ + + void UnlinkFree(AllocChunkPtr inChunk) + { + inChunk->RemoveLeaveDangling(); + size_t size = inChunk->Size(); + int index = BinIndex(size); + AllocChunkPtr bin = mBins + index; + if (bin->IsEmpty()) ClearBinBlock(index); + } + + AllocChunk mBins[kNumAllocBins]; + AllocAreaPtr mAreas; + NewAreaFunc mAllocArea; + FreeAreaFunc mFreeArea; + size_t mAreaInitSize, mAreaMoreSize; + unsigned long mBinBlocks[4]; +}; + +#endif diff --git a/sc4pd/headers/common/SC_Altivec.h b/sc4pd/headers/common/SC_Altivec.h new file mode 100644 index 0000000..8ae3f66 --- /dev/null +++ b/sc4pd/headers/common/SC_Altivec.h @@ -0,0 +1,118 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2003 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Altivec_ +#define _SC_Altivec_ + +#if defined(SC_LINUX) && defined(__ALTIVEC__) +# include +#endif + +#if __VEC__ + +typedef vector signed int vint32; +typedef vector unsigned int vuint32; +typedef vector float vfloat32; + +// Since gcc 3.3 vector initializers are surrounded by brackets. +#if defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 3) +# define vinit(x) { x, x, x, x } +#else +# define vinit(x) ( x ) +#endif + +//#define vload(x) (*vtempptr = (x), vec_splat(vtemp,0)) +#define define_vtemp vfloat32 vtemp; float *vtempptr = (float*)&vtemp; +#define define_vones vfloat32 vones = vec_ctf(vec_splat_s32(1),0); +#define define_vzero vfloat32 vzero = (vfloat32)vec_splat_s32(0); +#define vi0123 (vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0)))) +#define v0123 (vec_ctf(vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))), 0)) +#define v0123_4ths (vec_ctf(vec_unpackh(vec_unpackh((vector signed char)vec_lvsl(0,(int*)0))), 2)) +#define vstart(x, vslope) (vec_madd(vslope, v0123_4ths, vload(x))) + +#define vec_not(a) (vtemp = (a); vec_nor(vtemp, vtemp)) +#define vec_cmplt(a, b) (vec_cmpgt(b, a)) +#define vec_cmple(a, b) (vec_cmpge(b, a)) +#define vec_mul(a, b) (vec_madd(a, b, vzero)) +#define vec_2sComp(x) (vec_sub(vec_sub (x, x), x)) + +#define USEVEC (ft->mAltivecAvailable && !(BUFLENGTH & 3)) + +typedef union vec_union { + int32 i[4]; + float32 f[4]; + vint32 vi; + vfloat32 vf; +} vec_union; + +inline vfloat32 vload( float f ) +{ + vec_union temp; + temp.f[0] = f; + return vec_splat( vec_lde( 0, temp.f ), 0 ); +} + +inline vint32 vload( int32 i ) +{ + vec_union temp; + temp.i[0] = i; + return vec_splat( vec_lde( 0, temp.i ), 0 ); +} + +inline vint32 vload( int32 a, int32 b, int32 c, int32 d ) +{ + vec_union temp; + temp.i[0] = a; + temp.i[1] = b; + temp.i[2] = c; + temp.i[3] = d; + return temp.vi; +} + +inline vector float vec_float_1( void ) +{ + return vec_ctf( vec_splat_u32(1), 0); +} + +inline vector float vec_reciprocal( vector float v ) +{ + vector float reciprocal = vec_re( v ); + return vec_madd( reciprocal, vec_nmsub( reciprocal, v, vec_float_1()), reciprocal ); //Newton Rapheson refinement +} + +#define vec_div(a, b) vec_mul(a, vec_reciprocal(b)) + +// seed = ((seed & mask) << shift1) ^ (((seed << shift2) ^ seed) >> shift3); + +#define define_trshifts \ + vuint32 trmask = ((vuint32)(0xFFFFFFFE,0xFFFFFFF8,0xFFFFFFF0,0)); \ + vuint32 trshift1 = ((vuint32)(12, 14, 7, 0)); \ + vuint32 trshift2 = ((vuint32)(13, 2, 3, 0)); \ + vuint32 trshift3 = ((vuint32)(19, 25, 11, 0)); + +inline vuint32 trands(vuint32 seed, vuint32 trmask, vuint32 shift1, vuint32 shift2, vuint32 shift3) +{ + return vec_xor(vec_sl(vec_and(seed, trmask),shift1), vec_sr(vec_xor(vec_sl(seed,shift2),seed),shift3)); +} + +#endif +#endif + + diff --git a/sc4pd/headers/common/SC_Endian.h b/sc4pd/headers/common/SC_Endian.h new file mode 100644 index 0000000..ba127f5 --- /dev/null +++ b/sc4pd/headers/common/SC_Endian.h @@ -0,0 +1,64 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* NOTE: This file should declare/define the following functions/macros: + + htonl + htons + ntohl + ntohs + + either explicitly or implicitly by including system headers. +*/ + +#ifndef SC_ENDIAN_H_INCLUDED +#define SC_ENDIAN_H_INCLUDED + +#ifdef SC_DARWIN + +# include + +#elif defined(SC_WIN32) + +# define LITTLE_ENDIAN 1234 +# define BIG_ENDIAN 4321 +# define BYTE_ORDER LITTLE_ENDIAN +# include + +#else + +# include +# include + +#endif + +#ifndef BYTE_ORDER +# error BYTE_ORDER undefined, check __FILE__ +#endif // BYTE_ORDER + +#ifndef BIG_ENDIAN +# error BIG_ENDIAN undefined, check __FILE__ +#endif // BIG_ENDIAN + +#ifndef LITTLE_ENDIAN +# error LITTLE_ENDIAN undefined, check __FILE__ +#endif // LITTLE_ENDIAN + +#endif // SC_ENDIAN_H_INCLUDED diff --git a/sc4pd/headers/common/SC_Sem.h b/sc4pd/headers/common/SC_Sem.h new file mode 100755 index 0000000..22a2ffa --- /dev/null +++ b/sc4pd/headers/common/SC_Sem.h @@ -0,0 +1,43 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Semaphore_ +#define _SC_Semaphore_ + +#include + +class SC_Semaphore +{ +public: + SC_Semaphore(int initialCount); + ~SC_Semaphore(); + + void Acquire(); + void Release(); + +private: + pthread_cond_t available; + pthread_mutex_t mutex; + int count; +}; + +#endif + diff --git a/sc4pd/headers/common/SC_StringBuffer.h b/sc4pd/headers/common/SC_StringBuffer.h new file mode 100644 index 0000000..24bcd4d --- /dev/null +++ b/sc4pd/headers/common/SC_StringBuffer.h @@ -0,0 +1,67 @@ +// emacs: -*- c++ -*- +// file: SC_StringBuffer.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_StringBuffer.h,v 1.1.1.1 2004-07-14 16:21:36 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_STRINGBUFFER_H_INCLUDED +#define SC_STRINGBUFFER_H_INCLUDED + +#include +#include + +// ===================================================================== +// SC_StringBuffer - Autogrowing string buffer. +// ===================================================================== + +class SC_StringBuffer +{ +public: + SC_StringBuffer(size_t initialSize=0); + SC_StringBuffer(const SC_StringBuffer& other); + ~SC_StringBuffer(); + + size_t getCapacity() const { return mCapacity; } + size_t getSize() const { return mPtr - mData; } + size_t getRemaining() const { return mCapacity - getSize(); } + char* getData() const { return mData; } + + bool isEmpty() const { return getSize() == 0; } + + void finish() { append('\0'); } + void reset() { mPtr = mData; } + void append(const char* src, size_t len); + void append(char c); + void append(const char* str); + void vappendf(const char* fmt, va_list vargs); + void appendf(const char* fmt, ...); + +protected: + enum { + kGrowAlign = 256, + kGrowMask = kGrowAlign - 1 + }; + + void growBy(size_t request); + +private: + size_t mCapacity; + char* mPtr; + char* mData; +}; + +#endif // SC_STRINGBUFFER_H_INCLUDED diff --git a/sc4pd/headers/common/SC_StringParser.h b/sc4pd/headers/common/SC_StringParser.h new file mode 100644 index 0000000..f2d414e --- /dev/null +++ b/sc4pd/headers/common/SC_StringParser.h @@ -0,0 +1,40 @@ +// emacs: -*- c++ -*- +// file: SC_StringParser.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_StringParser.h,v 1.1.1.1 2004-07-14 16:21:37 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef _SC_StringParser_ +#define _SC_StringParser_ + +#define SC_MAX_TOKEN_LENGTH 256 + +class SC_StringParser +{ + char *mSpec, *mStart, *mEnd; + char mSep, mBuf[SC_MAX_TOKEN_LENGTH]; + +public: + SC_StringParser(); + SC_StringParser(char *spec, char sep); + + bool AtEnd() const; + const char *NextToken(); +}; + +#endif + diff --git a/sc4pd/headers/common/dfftlib.h b/sc4pd/headers/common/dfftlib.h new file mode 100755 index 0000000..409267e --- /dev/null +++ b/sc4pd/headers/common/dfftlib.h @@ -0,0 +1,62 @@ +long dFFTInit(long *fftMptr, long fftN, double *Utbl); +/* Compute cosine table and check size for complex ffts */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +long drFFTInit(long *fftMptr, long fftN, double *Utbl); +/* Compute cosine table and check size for a real input fft */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +void dffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void diffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place inverse complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void drffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place real fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = real input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ + + +void driffts(double *ioptr, long M, long Rows, double *Utbl); +/* Compute in-place real ifft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = real output data array */ diff --git a/sc4pd/headers/common/dlfcn.h b/sc4pd/headers/common/dlfcn.h new file mode 100755 index 0000000..62966d0 --- /dev/null +++ b/sc4pd/headers/common/dlfcn.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 1.1 (the "License"). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +#ifdef __cplusplus +extern "C" +{ +#endif + void * dlopen(const char *path, int mode); + void * dlsym(void * handle, const char *symbol); + const char * dlerror(void); + int dlclose(void * handle); +#ifdef __cplusplus +} +#endif + +#define RTLD_LAZY 0x1 +#define RTLD_NOW 0x2 +#define RTLD_LOCAL 0x4 +#define RTLD_GLOBAL 0x8 +#define RTLD_NOLOAD 0x10 +#define RTLD_SHARED 0x20 /* not used, the default */ +#define RTLD_UNSHARED 0x40 +#define RTLD_NODELETE 0x80 +#define RTLD_LAZY_UNDEF 0x100 diff --git a/sc4pd/headers/common/fftlib.h b/sc4pd/headers/common/fftlib.h new file mode 100755 index 0000000..b03317d --- /dev/null +++ b/sc4pd/headers/common/fftlib.h @@ -0,0 +1,62 @@ +long FFTInit(long *fftMptr, long fftN, float *Utbl); +/* Compute cosine table and check size for complex ffts */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +long rFFTInit(long *fftMptr, long fftN, float *Utbl); +/* Compute cosine table and check size for a real input fft */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +void ffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void iffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place inverse complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void rffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place real fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = real input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ + + +void riffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place real ifft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = real output data array */ diff --git a/sc4pd/headers/common/scsynthsend.h b/sc4pd/headers/common/scsynthsend.h new file mode 100644 index 0000000..97f345b --- /dev/null +++ b/sc4pd/headers/common/scsynthsend.h @@ -0,0 +1,191 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _scpacket_ +#define _scpacket_ + +#include "SC_Endian.h" +#include "SC_Types.h" +#include + +struct netaddr { + int socket; + int addr; + int port; +}; +typedef struct netaddr netaddr; + +#define kSCMaxPacketSize 8192 + +struct scpacket { + int32 *wrpos, *endpos, *msgsizepos; + char *tagwrpos; + int inbundle; + int32 buf[kSCMaxPacketSize]; + + scpacket(); + void reset(); + void addi(int i); + void addii(int64 ii); + void addf(float f); + void addd(double f); + void adds(char *cstr); + void adds(char *src, size_t len); + void addb(uint8 *src, size_t len); + void addtag(char c); + void skip(int n); + void maketags(int n); + int size() { return (char*)wrpos - (char*)buf; } + char* data() { return (char*)buf; } + + void sendudp(int socket, int addr, int port); + + void OpenBundle(int64 time); + void CloseBundle(); + + void BeginMsg(); + void EndMsg(); +}; + +inline scpacket::scpacket() { reset(); } + +// ways to fail +#define BUFFEROVERFLOW return +//#define BUFFEROVERFLOW throw std::runtime_error("buffer overflow") + +inline void scpacket::reset() +{ + wrpos = buf; + endpos = buf + kSCMaxPacketSize; + inbundle = 0; +} + +inline void scpacket::skip(int n) +{ + if (wrpos + n > endpos) BUFFEROVERFLOW; + wrpos += n; +} + +inline void scpacket::addtag(char c) +{ + *tagwrpos++ = c; +} + +inline void scpacket::maketags(int n) +{ + int size4 = (n + 4) >> 2; + tagwrpos = (char*)wrpos; + skip(size4); + wrpos[-1] = 0; +} + + +inline void scpacket::addi(int i) +{ + if (wrpos >= endpos) BUFFEROVERFLOW; + *wrpos++ = htonl(i); +} + +inline void scpacket::addii(int64 ii) +{ + int i; + i = (int)(ii >> 32); + addi(i); + i = (int)ii; + addi(i); +} + +inline void scpacket::addf(float f) +{ + if (wrpos >= endpos) BUFFEROVERFLOW; + elem32 slot; + slot.f = f; + *wrpos++ = htonl(slot.i); +} + +inline void scpacket::addd(double f) +{ + if (wrpos >= endpos) BUFFEROVERFLOW; + elem64 slot; + slot.f = f; + *wrpos++ = htonl(slot.i >> 32); + *wrpos++ = htonl(slot.i & 0x00000000FFFFFFFF); +} + +inline void scpacket::adds(char *src) +{ + size_t len = strlen(src); + size_t len4 = (len + 4) >> 2; + if (wrpos + len4 > endpos) BUFFEROVERFLOW; + wrpos[len4 - 1] = 0; + memcpy(wrpos, src, (size_t)len); + wrpos += len4; +} + +inline void scpacket::adds(char *src, size_t len) +{ + size_t len4 = (len + 4) >> 2; + if (wrpos + len4 > endpos) BUFFEROVERFLOW; + wrpos[len4 - 1] = 0; + memcpy(wrpos, src, (size_t)len); + wrpos += len4; +} + +// support binary objects +inline void scpacket::addb(uint8 *src, size_t len) +{ + size_t len4 = (len + 3) >> 2; + if (wrpos + (len4 + 1) > endpos) BUFFEROVERFLOW; + wrpos[len4 - 1] = 0; + int32 swaplen = len; + *wrpos++ = htonl(swaplen); + memcpy(wrpos, src, (size_t)len); + wrpos += len4; +} + +inline void scpacket::OpenBundle(int64 time) +{ + inbundle++; + adds("#bundle"); + addii(time); +} + +inline void scpacket::CloseBundle() +{ + if (inbundle) inbundle--; +} + +inline void scpacket::BeginMsg() +{ + if (inbundle) { + msgsizepos = wrpos; + addi(0); + } +} + +inline void scpacket::EndMsg() +{ + if (inbundle) { + *msgsizepos = htonl(((wrpos - msgsizepos) - 1) * sizeof(int32)); + } +} + +#endif + diff --git a/sc4pd/headers/lang/AdvancingAllocPool.h b/sc4pd/headers/lang/AdvancingAllocPool.h new file mode 100755 index 0000000..b89d69b --- /dev/null +++ b/sc4pd/headers/lang/AdvancingAllocPool.h @@ -0,0 +1,82 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +AdvancingAllocPool implements a simple advancing pointer allocation scheme. +There is no Free(). All objects in the pool are freed at once with FreeAll(). +Thus it is very fast. + +*/ + +#ifndef _AdvancingAllocPool_ +#define _AdvancingAllocPool_ + +#include +#include + +class AllocPool; + +struct AdvancingAllocPoolChunk; + +typedef int int32; + +inline void FailNil(void *ptr) { + if (!ptr) throw std::runtime_error("alloc failed"); +} + +struct AdvancingAllocPoolChunkHdr { + AdvancingAllocPoolChunk *mNext; + size_t mSize; + int32 mPad1, mPad2; +}; + +struct AdvancingAllocPoolChunk { + AdvancingAllocPoolChunk *mNext; + size_t mSize; + int32 mPad1, mPad2; + char mSpace[16]; +}; + +class AdvancingAllocPool +{ +public: + AdvancingAllocPool(); + ~AdvancingAllocPool() { FreeAll(); } + + void Init(AllocPool *inAllocPool, size_t initSize, size_t growSize, size_t tooBigSize); + + void *Alloc(size_t inBytes); + void FreeAll(); + + bool SanityCheck(); + +private: + void AddChunk(size_t inSize); + + AllocPool* mAllocPool; + size_t mInitSize; + size_t mGrowSize; + size_t mCurSize; + size_t mTooBig; + AdvancingAllocPoolChunk *mChunks; + AdvancingAllocPoolChunk *mFatties; +}; + +#endif diff --git a/sc4pd/headers/lang/AllocPools.h b/sc4pd/headers/lang/AllocPools.h new file mode 100755 index 0000000..111f7c3 --- /dev/null +++ b/sc4pd/headers/lang/AllocPools.h @@ -0,0 +1,34 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Pools for memory allocation. + +*/ + + +#ifndef _AllocPools_ +#define _AllocPools_ + +class AllocPool; +extern AllocPool *pyr_pool_compile; +extern AllocPool *pyr_pool_runtime; + +#endif diff --git a/sc4pd/headers/lang/ByteCodeArray.h b/sc4pd/headers/lang/ByteCodeArray.h new file mode 100755 index 0000000..5ec1520 --- /dev/null +++ b/sc4pd/headers/lang/ByteCodeArray.h @@ -0,0 +1,50 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +typedef unsigned char Byte; + +#define BYTE_CODE_CHUNK_SIZE 64 + +typedef struct { + Byte *bytes; + Byte *ptr; + long size; +} ByteCodeArray, *ByteCodes; + +extern ByteCodes gCompilingByteCodes; +extern long totalByteCodes; + +void initByteCodes(); +void compileByte(long byte); +void compileAndFreeByteCodes(ByteCodes byteCodes); +void copyByteCodes(Byte *dest, ByteCodes byteCodes); +ByteCodes getByteCodes(); +ByteCodes saveByteCodeArray(); +void restoreByteCodeArray(ByteCodes byteCodes); +int byteCodeLength(ByteCodes byteCodes); +void compileByteCodes(ByteCodes byteCodes); +ByteCodes allocByteCodes(); +void reallocByteCodes(ByteCodes byteCodes); +void freeByteCodes(ByteCodes byteCodes); +int compileOpcode(long opcode, long operand1); +void compileJump(long opcode, long jumplen); +int compileNumber(unsigned long value); +int compileNumber24(unsigned long value); + diff --git a/sc4pd/headers/lang/FIFOT.h b/sc4pd/headers/lang/FIFOT.h new file mode 100755 index 0000000..52b6203 --- /dev/null +++ b/sc4pd/headers/lang/FIFOT.h @@ -0,0 +1,75 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +A Fifo for sending/receiving some type of object. + +*/ + +#ifndef _FIFOT_ +#define _FIFOT_ + +template class FIFOT +{ +public: + FIFOT() + : mMask(N-1), mReadHead(0), mWriteHead(0) + { + } + void MakeEmpty() { mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + int CanGet() { + int diff = mWriteHead - mReadHead; + return diff >= 0 ? diff : N - diff; + } + int CanPut() { return N-1-CanGet(); } + + int NextPos(int inPos) { return (inPos + 1) & mMask; } + + bool Put(const T& inItem) + { + long next = NextPos(mWriteHead); + if (next == mReadHead) return false; // fifo is full + mItems[next] = inItem; + mWriteHead = next; + return true; + } + + bool Get(T& outItem) // get next and advance + { + if (IsEmpty()) return false; + long next = NextPos(mReadHead); + outItem = mItems[next]; + mReadHead = next; + return true; + } + void DebugDump() + { + post("FIFO N %d mMask %d mReadHead %d mWriteHead%d\n", + N, mMask, mReadHead, mWriteHead); + } + +private: + long mMask; + volatile long mReadHead, mWriteHead;// mReclaimHead; + T mItems[N]; +}; + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/GC.h b/sc4pd/headers/lang/GC.h new file mode 100755 index 0000000..4dc162a --- /dev/null +++ b/sc4pd/headers/lang/GC.h @@ -0,0 +1,263 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +The garbage collector for SuperCollider. +Based on Wilson and Johnstone's real time collector and the Baker treadmill. + +*/ + +#ifndef _GC_ +#define _GC_ + +#include "PyrObject.h" +#include "VMGlobals.h" +#include "AdvancingAllocPool.h" + +void DumpSimpleBackTrace(VMGlobals *g); + +const int kMaxPoolSet = 7; +const int kNumGCSizeClasses = 28; +const int kFinalizerSet = kNumGCSizeClasses; +const int kNumGCSets = kNumGCSizeClasses + 1; + +class GCSet +{ +public: + GCSet() {} + void Init(int inSizeClass); + + bool HasFree() { return mFree != &mBlack; } + +private: + friend class PyrGC; + + void MoveWhiteToFree(); + + PyrObjectHdr mBlack; + PyrObjectHdr mWhite; + PyrObjectHdr* mFree; +}; + +struct SlotRef { + SlotRef(PyrObject* inObj, int32 inIndex) : obj(inObj), slotIndex(inIndex) {} + + PyrObject *obj; + int32 slotIndex; +}; + +class PyrGC +{ +public: + PyrGC(VMGlobals *g, AllocPool *inPool, PyrClass *mainProcessClass, long poolSize); + + PyrObject* New(size_t inNumBytes, long inFlags, long inFormat, bool inCollect); + + static PyrObject* NewPermanent(size_t inNumBytes, + long inFlags, long inFormat); + + PyrObject* NewFinalizer(ObjFuncPtr finalizeFunc, PyrObject *inObject, bool inCollect); + + int32 ProcessID() { return mProcessID; } + +#if 0 +// Codewarrior is not inlining these.. why? + bool IsBlack(PyrObjectHdr* inObj) { return inObj->gc_color == mBlackColor; } + bool IsWhite(PyrObjectHdr* inObj) { return inObj->gc_color == mWhiteColor; } + bool IsGrey(PyrObjectHdr* inObj) { return inObj->gc_color == mGreyColor; } + bool IsMarker(PyrObjectHdr* inObj) { return inObj->gc_color == obj_gcmarker; } +#else + +#define IsBlack(inObj) ((inObj)->gc_color == mBlackColor) +#define IsWhite(inObj) ((inObj)->gc_color == mWhiteColor) +#define IsGrey(inObj) ((inObj)->gc_color == mGreyColor) +#define IsFree(inObj) (!(IsMarker(inObj) || inObj->IsPermanent() || \ + IsBlack(inObj) || IsWhite(inObj) || IsGrey(inObj))) +#define IsMarker(inObj) ((inObj)->gc_color == obj_gcmarker) +#endif + + bool ObjIsBlack(PyrObjectHdr* inObj) { return IsBlack(inObj); } + bool ObjIsGrey(PyrObjectHdr* inObj) { return IsGrey(inObj); } + bool ObjIsFree(PyrObjectHdr* inObj) { return IsFree(inObj); } + + + // general purpose write barriers: + void GCWrite(PyrObjectHdr* inParent, PyrSlot* inSlot) + { + if (IsBlack(inParent) && IsObj(inSlot) && IsWhite(inSlot->uo)) { + ToGrey(inSlot->uo); + } + } + void GCWrite(PyrObjectHdr* inParent, PyrObjectHdr* inChild) + { + if (IsBlack(inParent) && IsWhite(inChild)) { + ToGrey(inChild); + } + } + // when you know the parent is black: + void GCWriteBlack(PyrSlot* inSlot) + { + if (IsObj(inSlot)) { + if (IsWhite(inSlot->uo)) { + ToGrey(inSlot->uo); + } + } + } + void GCWriteBlack(PyrObjectHdr* inChild) + { + if (IsWhite(inChild)) { + ToGrey(inChild); + } + } + // when you know the child is white + void GCWriteNew(PyrObjectHdr* inParent, PyrObjectHdr* inChild) + { + if (IsBlack(inParent)) { + ToGrey(inChild); + } + } + +// users should not call anything below. + + void Collect(); + void Collect(int32 inNumToScan); + void FullCollection(); + void ScanFinalizers(); + GCSet* GetGCSet(PyrObjectHdr* inObj); + void CompletePartialScan(PyrObject *obj); + + void ToGrey(PyrObjectHdr* inObj); + void ToGrey2(PyrObjectHdr* inObj); + void ToBlack(PyrObjectHdr* inObj); + void ToWhite(PyrObjectHdr *obj); + + int32 StackDepth() { return mVMGlobals->sp - mStack->slots + 1; } + PyrObject* Stack() { return mStack; } + void SetStack(PyrObject* inStack) { mStack = inStack; } + + bool SanityCheck(); + bool SanityCheck2(); + bool LinkSanity(); + bool ListSanity(); + bool BlackToWhiteCheck(PyrObject *objA); + bool SanityMarkObj(PyrObject *objA, PyrObject *fromObj, int level); + bool SanityClearObj(PyrObject *objA, int level); + void DumpInfo(); + void DumpEverything(); + + void BecomePermanent(PyrObject *inObject); + void BecomeImmutable(PyrObject *inObject); + +private: + void Free(PyrObject* inObj); + void ScanSlots(PyrSlot *inSlots, long inNumToScan); + void SweepBigObjects(); + void DoPartialScan(int32 inObjSize); + bool ScanOneObj(); + void Flip(); + void ScanStack(); + void DLRemove(PyrObjectHdr *obj); + void DLInsertAfter(PyrObjectHdr *after, PyrObjectHdr *obj); + void DLInsertBefore(PyrObjectHdr *before, PyrObjectHdr *obj); + + void ClearMarks(); + void Finalize(PyrObject *obj); + + VMGlobals *mVMGlobals; + AllocPool *mPool; + AdvancingAllocPool mNewPool; + GCSet mSets[kNumGCSets]; + PyrProcess *mProcess; // the root is the pyrprocess which contains this struct + PyrObject *mStack; + PyrObject *mPartialScanObj; + PyrObjectHdr mGrey; + + GCSet *mPartialScanSet; + int32 mPartialScanSlot; + int32 mNumToScan; + int32 mNumGrey; + int32 mCurSet; + + int32 mFlips, mCollects, mAllocTotal, mScans, mNumAllocs; + + unsigned char mBlackColor, mGreyColor, mWhiteColor, mFreeColor; + int8 mProcessID; + bool mCanSweep; + bool mRunning; +}; + +inline void PyrGC::DLRemove(PyrObjectHdr *obj) +{ + obj->next->prev = obj->prev; + obj->prev->next = obj->next; +} + +inline void PyrGC::DLInsertAfter(PyrObjectHdr *after, PyrObjectHdr *obj) +{ + obj->next = after->next; + obj->prev = after; + after->next->prev = obj; + after->next = obj; +} + +inline void PyrGC::DLInsertBefore(PyrObjectHdr *before, PyrObjectHdr *obj) +{ + obj->prev = before->prev; + obj->next = before; + before->prev->next = obj; + before->prev = obj; +} + +inline GCSet* PyrGC::GetGCSet(PyrObjectHdr* inObj) +{ + return mSets + (inObj->classptr == class_finalizer ? kFinalizerSet : inObj->obj_sizeclass); +} + +inline void PyrGC::ToBlack(PyrObjectHdr *obj) +{ + if (IsGrey(obj)) { + mNumGrey--; + //post("ToBlack %d\n", mNumGrey); + } + + DLRemove(obj); + + GCSet *gcs = GetGCSet(obj); + DLInsertAfter(&gcs->mBlack, obj); + + obj->gc_color = mBlackColor; +} + +inline void PyrGC::ToWhite(PyrObjectHdr *obj) +{ + if (IsGrey(obj)) { + mNumGrey--; + //post("ToWhite %d\n", mNumGrey); + } + + DLRemove(obj); + + GCSet *gcs = GetGCSet(obj); + DLInsertAfter(&gcs->mWhite, obj); + + obj->gc_color = mWhiteColor; +} + +#endif diff --git a/sc4pd/headers/lang/HashTable.h b/sc4pd/headers/lang/HashTable.h new file mode 100755 index 0000000..835f593 --- /dev/null +++ b/sc4pd/headers/lang/HashTable.h @@ -0,0 +1,274 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _HashTable_ +#define _HashTable_ + +#include "SC_Types.h" +#include "SC_BoundsMacros.h" +#include "Hash.h" +#include + +template +class HashTable +{ + Allocator *mPool; + int32 mNumItems, mMaxItems, mTableSize, mHashMask; + T** mItems; + bool mCanResize; + +public: + + HashTable(Allocator *inPool, int32 inMaxItems, bool inCanResize = true) + : mPool(inPool) + { + mNumItems = 0; + mMaxItems = inMaxItems; + mTableSize = mMaxItems << 1; + mItems = AllocTable(mTableSize); + mHashMask = mTableSize - 1; + mCanResize = inCanResize; + } + + ~HashTable() { + mPool->Free(mItems); + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return mMaxItems; } + int32 NumItems() const { return mNumItems; } + + T** AllocTable(int inTableSize) + { + size_t size = inTableSize * sizeof(T*); + T** items = static_cast(mPool->Alloc(size)); + for (int i=0; i> 1; + mHashMask = mTableSize - 1; + mPool->Free(oldItems); + //printf("mMaxItems %d mTableSize %d newSize %d\n", mMaxItems, mTableSize, newSize); + } + + bool Add(T* inItem) + { + //printf("mNumItems %d\n", mNumItems); + //printf("mMaxItems %d\n", mMaxItems); + //printf("mCanResize %d\n", mCanResize); + if (mNumItems >= mMaxItems) { + if (!mCanResize) return false; + Resize(); + } + + //printf("GetHash(inItem) %d\n", GetHash(inItem)); + //printf("GetKey(inItem) %s\n", GetKey(inItem)); + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + //printf("index %d\n", index); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + int32 IndexFor(int32 inHashID, KeyType inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID + && strcmp(inKey, GetKey(item)) == 0) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(KeyType inKey) const + { + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, KeyType inKey) const + { + int32 index = IndexFor(inHashID, inKey); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + +private: + void FixCollisionsFrom(int32 inIndex) + { + int oldIndex = inIndex; + for (;;) { + oldIndex = (oldIndex + 1) & mHashMask; + T *oldItem = mItems[oldIndex]; + if (!oldItem) break; + int newIndex = IndexFor(GetHash(oldItem), GetKey(oldItem)); + if (oldIndex != newIndex) { + mItems[oldIndex] = mItems[newIndex]; + mItems[newIndex] = oldItem; + } + } + } +}; + +template +class StaticHashTable +{ + int32 mNumItems, mTableSize, mHashMask; + T* mItems[kMaxItems*2]; + +public: + + StaticHashTable() + { + mNumItems = 0; + mTableSize = kMaxItems << 1; + ClearTable(); + mHashMask = mTableSize - 1; + } + + ~StaticHashTable() { + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return kMaxItems; } + int32 NumItems() const { return mNumItems; } + + void ClearTable() + { + for (int i=0; i= kMaxItems) return false; + + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + int32 IndexFor(int32 inHashID, KeyType inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID + && strcmp(inKey, GetKey(item)) == 0) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(KeyType inKey) const + { + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, KeyType inKey) const + { + int32 index = IndexFor(inHashID, inKey); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + +private: + void FixCollisionsFrom(int32 inIndex) + { + int oldIndex = inIndex; + for (;;) { + oldIndex = (oldIndex + 1) & mHashMask; + T *oldItem = mItems[oldIndex]; + if (!oldItem) break; + int newIndex = IndexFor(GetHash(oldItem), GetKey(oldItem)); + if (oldIndex != newIndex) { + mItems[oldIndex] = mItems[newIndex]; + mItems[newIndex] = oldItem; + } + } + } +}; + + +#endif diff --git a/sc4pd/headers/lang/InitAlloc.h b/sc4pd/headers/lang/InitAlloc.h new file mode 100755 index 0000000..762b940 --- /dev/null +++ b/sc4pd/headers/lang/InitAlloc.h @@ -0,0 +1,32 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _InitAlloc_ +#define _InitAlloc_ + +#include "SCBase.h" +#include "SC_AllocPool.h" +#include + +#define MEMFAIL(ptr) if (!(ptr)) { throw std::runtime_error("Out of memory!\n"); } +#define MEMFAILED throw std::runtime_error("Out of memory!\n"); + +#endif + diff --git a/sc4pd/headers/lang/MiscInlineMath.h b/sc4pd/headers/lang/MiscInlineMath.h new file mode 100755 index 0000000..6dd33ab --- /dev/null +++ b/sc4pd/headers/lang/MiscInlineMath.h @@ -0,0 +1,54 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#define NUMPRIMES 6542 +long nthPrime(int n); +long findPrime(int n); +long prevPrime(int n); +long nextPrime(int n); + + +inline double linlin(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return (x-a)/(b-a) * (d-c) + c; +} + +inline double explin(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return (log(x/a)) / (log(b/a)) * (d-c) + c; +} + +inline double expexp(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return pow(d/c, log(x/a)) / (log(b/a)) * c; +} + +inline double linexp(double x, double a, double b, double c, double d) +{ + if (x <= a) return c; + if (x >= b) return d; + return pow(d/c, (x-a)/(b-a)) * c; +} diff --git a/sc4pd/headers/lang/OSCData.h b/sc4pd/headers/lang/OSCData.h new file mode 100755 index 0000000..b2721b0 --- /dev/null +++ b/sc4pd/headers/lang/OSCData.h @@ -0,0 +1 @@ +/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _OSCData_ #define _OSCData_ #include "PyrObject.h" #include "FIFOT.h" #include #endif \ No newline at end of file diff --git a/sc4pd/headers/lang/Opcodes.h b/sc4pd/headers/lang/Opcodes.h new file mode 100755 index 0000000..c5e1c7a --- /dev/null +++ b/sc4pd/headers/lang/Opcodes.h @@ -0,0 +1,426 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _OPCODES_H_ +#define _OPCODES_H_ + +/* opcodes */ +enum { + opExtended, // 0 + opPushInstVar, + opPushTempVar, + opPushTempZeroVar, + opPushLiteral, + opPushClassVar, // 5 + opPushSpecialValue, + opStoreInstVar, + opStoreTempVar, + opStoreClassVar, + opSendMsg, // 10 + opSendSuper, + opSendSpecialMsg, + opSendSpecialUnaryArithMsg, + opSendSpecialBinaryArithMsg, + opSpecialOpcode, // 15 + + + opNumOpcodes +}; + +/* special opcodes */ +enum { + opcDrop, // 0 + opcDup, + opcFunctionReturn, + opcReturn, + opcReturnSelf, + opcReturnTrue, // 5 + opcReturnFalse, + opcReturnNil, + opcJumpIfFalse, // IF 3 args + opcJumpIfFalsePushNil, // IF 2 args + opcJumpIfFalsePushFalse, // AND: (10) + opcJumpIfTruePushTrue, // OR: + opcJumpFwd, + opcJumpBak, + opcSpecialBinaryOpWithAdverb, + opcSuperNew, // 15 + + opcNewList, + + opcNumSpecialOpcodes +/* + opcSlotAt, + opcByteAt, // 15 + opcShortAt, + opcInt32At, + opcColorAt, + opcFloatAt, + opcDoubleAt +*/ +}; + +/* special unary math operators */ +enum { + opNeg, + opNot, + opIsNil, + opNotNil, + opBitNot, + opAbs, + opAsFloat, + opAsInt, + opCeil, //5 + opFloor, + opFrac, + opSign, + opSquared, + opCubed, //10 + opSqrt, + opExp, + opRecip, + opMIDICPS, + opCPSMIDI, //15 + + opMIDIRatio, + opRatioMIDI, + opDbAmp, + opAmpDb, + opOctCPS, //20 + opCPSOct, + opLog, + opLog2, + opLog10, + opSin, //25 + opCos, + opTan, + opArcSin, + opArcCos, + opArcTan, + opSinH, + opCosH, //30 + opTanH, + opRand, + opRand2, + opLinRand, + opBiLinRand, + +// opExpRand, +// opBiExpRand, + opSum3Rand, +// opGammaRand, +// opGaussRand, +// opPoiRand, + + opDistort, + opSoftClip, + opCoin, + + opDigitValue, + opSilence, + opThru, + opRectWindow, + opHanWindow, + opWelchWindow, + opTriWindow, + + opRamp, + opSCurve, + + opNumUnarySelectors +}; + +#define IS_UNARY_BOOL_OP(op) ((op)>=opCoin && (op)<=opOdd) +#define IS_BINARY_BOOL_OP(op) ((op)>=opEQ && (op)<=opGE) + +/* special binary math operators */ +enum { + opAdd, + opSub, + opMul, + opIDiv, + opFDiv, + opMod, + opEQ, + opNE, + opLT, + opGT, + opLE, + opGE, + //opIdentical, + //opNotIdentical, + + opMin, + opMax, + opBitAnd, + opBitOr, + opBitXor, + opLCM, + opGCD, + opRound, + opRoundUp, + opTrunc, + opAtan2, + opHypot, + opHypotx, + opPow, + opShiftLeft, + opShiftRight, + opUnsignedShift, + opFill, + opRing1, // a * (b + 1) == a * b + a + opRing2, // a * b + a + b + opRing3, // a*a*b + opRing4, // a*a*b - a*b*b + opDifSqr, // a*a - b*b + opSumSqr, // a*a + b*b + opSqrSum, // (a + b)^2 + opSqrDif, // (a - b)^2 + opAbsDif, // |a - b| + opThresh, + opAMClip, + opScaleNeg, + opClip2, + opExcess, + opFold2, + opWrap2, + opFirstArg, + opRandRange, + opExpRandRange, + + opNumBinarySelectors +}; + +/* other special math operators */ +enum { + /* 3 operands */ + opDivz, + opClip, + opWrap, + opFold, + opRampMult, + opMix, + /* 4 operands */ + opPoly3, + /* 5 operands */ + opMapRange +}; + +enum { + opmNew, // 0 + opmInit, + opmAt, + opmPut, + opmNext, + opmReset, // 5 + opmValue, + opmCopyToEnd, // used by multi assign + opmAdd, // used by dynamic list + //opmIsNil, + //opmNotNil, // 10 + opmSize, + opmClass, + opmIf, + opmWhile, + opmFor, // 15 + opmAnd, + opmOr, + opmIdentical, + opmNotIdentical, + opmPrint, // 20 + opmRemove, + opmIndexOf, + opmWrapAt, + opmClipAt, + opmFoldAt, // 25 + opmWrapPut, + opmClipPut, + opmFoldPut, + opmDo, + opmCollect, // 30 + opmSelect, + opmReject, + opmAny, + opmEvery, + opmFind, + opmChoose, + opmValueList, + opmAddFirst, + opmPrimitiveFailed, + opmSubclassResponsibility, + opmShouldNotImplement, + opmNotYetImplemented, + opmDoesNotUnderstand, + + opmAtSign, + opmWrapAtSign, + opmClipAtSign, + opmFoldAtSign, + + opmNewClear, + opmNewCopyArgs, + opmMultiNew, + opmMultiNewList, + opmAR, + opmKR, + opmIR, + + opmCopy, + opmPerformList, + opmIsKindOf, + opmPostln, + opmAsString, + + opmEnvirGet, + opmEnvirPut, + + opmHalt, + opmForBy, + opmReverseDo, + opmLoop, + + opmNonBooleanError, + + opmPlusPlus, + opmLTLT, + opmQuestionMark, + opmDoubleQuestionMark, + + opmYield, + opmName, + opmMulAdd, + + opmNumSpecialSelectors +}; + +enum { + opsvSelf, // 0 + opsvMinusOne, + opsvNegOne, + opsvZero, + opsvOne, + opsvTwo, // 5 + opsvFHalf, + opsvFNegOne, + opsvFZero, + opsvFOne, + opsvFTwo, // 10 + opsvPlusOne, + opsvTrue, + opsvFalse, + opsvNil, + opsvInf, // 15 + + opsvNumSpecialValues +}; + +enum { + opgProcess, + opgMethod, + opgFunctionDef, + opgFunction, + opgThread, + //opgSampleRate, + //opgAudioClock, + //opgLogicalClock, + + opgNumPseudoVars +}; + +/* selector types */ +enum { + selNormal, + selSpecial, + selUnary, + selBinary, + selIf, + selWhile, + selAnd, + selOr, + selLoop, + selSuperNew, + + selNumSelectorTypes +}; + + + +/* + special classes: + Object, List, Number, Int, Float, Signal, Complex, Point +*/ +enum { + op_class_object, + op_class_symbol, + op_class_nil, + op_class_boolean, + op_class_true, + op_class_false, + op_class_magnitude, + op_class_char, + op_class_number, + op_class_complex, + op_class_simple_number, + op_class_int, + op_class_float, + op_class_method, + op_class_fundef, + op_class_stream, + op_class_func, + op_class_frame, + op_class_process, + op_class_main, + op_class_class, + op_class_string, + op_class_collection, + op_class_sequenceable_collection, + op_class_arrayed_collection, + op_class_array, + op_class_int8array, + op_class_int16array, + op_class_int32array, + op_class_floatarray, + op_class_signal, + op_class_doublearray, + op_class_symbolarray, + op_class_list, + op_class_linkedlist, + op_class_bag, + op_class_set, + op_class_identityset, + op_class_dictionary, + op_class_identitydictionary, + op_class_sortedlist, + op_class_synth, + op_class_ref, + op_class_environment, + op_class_wavetable, + op_class_env, + + op_class_routine, + op_class_color, + op_class_rect, + + op_NumSpecialClasses +}; + + + +#endif diff --git a/sc4pd/headers/lang/PowerOfTwoAllocPool.h b/sc4pd/headers/lang/PowerOfTwoAllocPool.h new file mode 100755 index 0000000..8dde18f --- /dev/null +++ b/sc4pd/headers/lang/PowerOfTwoAllocPool.h @@ -0,0 +1,154 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +// Implements a power of two size class allocator. +// There is no consolidation of free space. Once a chunk is allocated it +// remains at that size from then on whether free or allocated. +// It uses AdvancingAllocPool as its parent allocator. +// It is very fast. This is used to allocate Unit output buffers. + +#ifndef _PowerOfTwoAllocPool_ +#define _PowerOfTwoAllocPool_ + +#include +#include +#include "clz.h" +#include "AdvancingAllocPool.h" +#include "SC_AllocPool.h" +void post(const char *fmt, ...); +void postbuf(const char *fmt, ...); + +template +class PowerOfTwoAllocPool +{ +public: + PowerOfTwoAllocPool(::AllocPool *inPool, + size_t initSize = 64*1024, + size_t growSize = 64*1024 + ) + { + mLargeObjPool = inPool; + mNumLargeObjects = 0; + mNumAlloc = 0; + mNumFree = 0; + size_t tooBigSize = (sizeof(Hdr) + (sizeof(Elem) << (LargeObjSizeClass-1))) + 1; + mSmallObjPool.Init(inPool, initSize, growSize, tooBigSize); + Init(); + assert(SanityCheck()); + } + ~PowerOfTwoAllocPool() + { + assert(SanityCheck()); + assert(mNumLargeObjects == 0); // you have to free the big ones yourself + mSmallObjPool.FreeAll(); + } + + Obj* Alloc(int32 inNumElems) + { + //mNumAlloc++; + assert(SanityCheck()); + int sizeclass = LOG2CEIL(inNumElems); + if (sizeclass >= LargeObjSizeClass) { + mNumLargeObjects++; + size_t size = sizeof(Hdr) + (sizeof(Elem) * inNumElems); + return (Obj*)mLargeObjPool->Alloc(size); + } + + // get from free list + Obj* obj = mFreeLists[sizeclass]; + if (obj != NULL) { + // set free list to next element. + mFreeLists[sizeclass] = *(Obj**)obj; + } else { + // have to allocate it + size_t size = mSizes[sizeclass]; + obj = (Obj*)mSmallObjPool.Alloc(size); + if (!obj) throw runtime_error("PowerOfTwoAllocPool out of memory"); + } + //obj->mMagic = 'magk'; + assert(SanityCheck()); + return obj; + } + void Free(Obj* inObjPtr) + { + //mNumFree++; + assert(SanityCheck()); + if (inObjPtr == 0) return; /* free(0) has no effect */ + /*if (inObjPtr->mMagic != 'magk') { + postbuf("bad object\n"); + throw runtime_error("bad object"); + }*/ + int sizeclass = inObjPtr->SizeClass(); + if (sizeclass >= LargeObjSizeClass) { + mLargeObjPool->Free(inObjPtr); + mNumLargeObjects--; + } else { + Obj* nextfree = mFreeLists[sizeclass]; + mFreeLists[sizeclass] = inObjPtr; + *(Obj**)inObjPtr = nextfree; + } + assert(SanityCheck()); + } + void FreeAll() + { + assert(mNumLargeObjects == 0); // you have to free the big ones yourself + mSmallObjPool.FreeAll(); + Init(); + } + + bool SanityCheck() + { + //postbuf("PowerOfTwoAllocPool::SanityCheck %d %d\n", mNumAlloc, mNumFree); + mLargeObjPool->DoCheckPool(); + mSmallObjPool.SanityCheck(); + for (int i=0; i=1000) { + post("linked loop??\n"); + throw runtime_error("linked loop??\n"); + return false; + } + obj = *(Obj**)obj; + } + } + return true; + } +private: + void Init() + { + for (int i=0; i + +template +class PriorityQueueT +{ +public: + PriorityQueueT() { + Empty(); + } + + bool Add(Event& inEvent) + { + if (mSize >= N) return false; + long mom = mSize++; + long me = mom; + for (; mom>0;) { /* percolate up heap */ + mom = mom - 1 >> 1; + if (inEvent.mTime < mEvents[mom].mTime) { + mEvents[me] = mEvents[mom]; + me = mom; + } else break; + } + mEvents[me] = inEvent; + return true; + } + void Perform(TimeType inNow) + { + while (NextTime() <= inNow) { + Event event = Remove(); + event.Perform(); + } + } + TimeType NextTime() { return mEvents[0].mTime; } + bool Ready(TimeType inTime) { return NextTime() <= inTime; } + void Flush() { Perform(std::numeric_limits::max()); } + void Empty() { mSize = 0; SetEmptyTime(); } + void SetEmptyTime() { mEvents[0].mTime = std::numeric_limits::max(); } + + Event Remove() + { + Event event = mEvents[0]; + if (--mSize == 0) SetEmptyTime(); + else { + Event temp = mEvents[mSize]; + long mom = 0; + long me = 1; + for (;me < mSize;) { /* demote heap */ + if (me+1 < mSize && mEvents[me].mTime > mEvents[me+1].mTime) { + me ++; + } + if (temp.mTime > mEvents[me].mTime) { + mEvents[mom] = mEvents[me]; + mom = me; + me = (me << 1) + 1; + } else break; + } + mEvents[mom] = temp; + } + return event; + } + +private: + long mSize; + Event mEvents[N]; +}; + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrArchiverT.h b/sc4pd/headers/lang/PyrArchiverT.h new file mode 100755 index 0000000..3beaa0c --- /dev/null +++ b/sc4pd/headers/lang/PyrArchiverT.h @@ -0,0 +1,619 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + +#ifndef _PyrArchiver_ +#define _PyrArchiver_ + +#include "PyrObject.h" +#include "SC_AllocPool.h" + +#include "PyrKernel.h" +#include "PyrPrimitive.h" +#include "VMGlobals.h" +#include "GC.h" +#include "ReadWriteMacros.h" + +const int32 kArchHdrSize = 12; +const int32 kObjectArrayInitialCapacity = 32; + +template +class PyrArchiver +{ +public: + PyrArchiver(VMGlobals *inG, bool inSameAddressSpace = false) + : g(inG), mObjectArray(mInitialObjectArray), mNumObjects(0), + mObjectArrayCapacity( kObjectArrayInitialCapacity ), + mSameAddressSpace(inSameAddressSpace), mReadArchiveVersion(0) + { + } + + ~PyrArchiver() + { + if (mObjectArray != mInitialObjectArray) { + g->allocPool->Free(mObjectArray); + } + } + + void setStream(S s) { mStream.SetStream(s); } + + int32 calcArchiveSize() + { + PyrSlot *slot; + int32 size = kArchHdrSize; + if (mNumObjects == 0) { + size += sizeOfElem(&mTopSlot) + 1; + } else { + // object table size + for (int i=0; iclassptr->name.us->length + 1; // class name symbol + size += sizeof(int32); // size + if (obj->obj_format <= obj_slot) { + size += obj->size; // tags + slot = obj->slots; + for (int j=0; jsize; ++j, ++slot) { + size += sizeOfElem(slot); + } + } else if (obj->obj_format == obj_symbol) { + PyrSymbol **symbol = ((PyrSymbolArray*)obj)->symbols; + for (int j=0; jsize; ++j, ++symbol) { + size += (**symbol).length + 1; + } + } else { + size += obj->size * gFormatElemSize[obj->obj_format]; + } + } + } + return size; + } + + long prepareToWriteArchive(PyrSlot *objectSlot) + { + long err = errNone; + + try { + mTopSlot.ucopy = objectSlot->ucopy; + if (IsObj(objectSlot)) constructObjectArray(objectSlot->uo); + } catch (std::exception &ex) { + error(ex.what()); + err = errFailed; + } + return err; + } + + long writeArchive() + { + long err = errNone; + + try { + writeArchiveHeader(); + + if (mNumObjects == 0) { + writeSlot(&mTopSlot); + } else { + for (int i=0; ireadArchive\n"); + long err = errNone; + + + SetNil(objectSlot); + + try { + readArchiveHeader(); + //postfl("readObjectHeaders %d\n", mNumObjects); + if (mNumObjects == 0) { + readSlot(objectSlot); + } else { + for (int i=0; i kObjectArrayInitialCapacity) { + mObjectArray = (PyrObject**)g->allocPool->Alloc(mNumObjects * sizeof(PyrObject*)); + mObjectArrayCapacity = mNumObjects; + } + + } + + void recurse(PyrObject *obj, int n) + { + PyrSlot *slot = obj->slots; + for (int i=0; iuo); + } + } + + void growObjectArray() + { + int32 newObjectArrayCapacity = mObjectArrayCapacity << 1; + + int32 newSize = newObjectArrayCapacity * sizeof(PyrObject*); + PyrObject** newArray = (PyrObject**)g->allocPool->Alloc(newSize); + memcpy(newArray, mObjectArray, mNumObjects * sizeof(PyrObject*)); + if (mObjectArray != mInitialObjectArray) { + g->allocPool->Free(mObjectArray); + } + mObjectArrayCapacity = newObjectArrayCapacity; + mObjectArray = newArray; + } + + void putObject(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = mNumObjects; + + // expand array if needed + if (mNumObjects >= mObjectArrayCapacity) growObjectArray(); + + // add to array + mObjectArray[mNumObjects++] = obj; + } + + void constructObjectArray(PyrObject *obj) + { + if (!obj->IsMarked()) { + if (isKindOf(obj, class_class)) { + } else if (isKindOf(obj, class_process)) { + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + } else if (isKindOf(obj, class_method)) { + throw std::runtime_error("cannot archive Methods.\n"); + } else if (isKindOf(obj, class_thread)) { + throw std::runtime_error("cannot archive Threads.\n"); + } else if (isKindOf(obj, class_frame)) { + throw std::runtime_error("cannot archive Frames.\n"); + } else if (isKindOf(obj, class_func)) { + if (NotNil(&((PyrClosure*)obj)->block.uoblk->context)) { + throw std::runtime_error("open Function can not be archived.\n"); + } + putObject(obj); + recurse(obj, obj->size); + } else { + if (mSameAddressSpace && obj->IsPermanent()) { + // skip it + } else { + if (isKindOf(obj, class_rawarray)) { + putObject(obj); + } else if (isKindOf(obj, class_array)) { + putObject(obj); + recurse(obj, obj->size); + + } else { + putObject(obj); + recurse(obj, obj->size); + } + } + } + } + } + + int32 sizeOfElem(PyrSlot *slot) + { + //postfl("writeSlot %08X\n", slot->utag); + switch (slot->utag) { + case tagObj : + if (isKindOf(slot->uo, class_class)) { + return slot->uoc->name.us->length + 1; + } else if (isKindOf(slot->uo, class_process)) { + return 0; + } else if (isKindOf(slot->uo, s_interpreter->u.classobj)) { + return 0; + } else { + return sizeof(int32); + } + break; + case tagHFrame : + case tagSFrame : + return 0; + case tagInt : + return sizeof(int32); + case tagSym : + return slot->us->length + 1; + case tagChar : + return sizeof(int32); + case tagNil : + return 0; + case tagFalse : + return 0; + case tagTrue : + return 0; + case tagInf : + return 0; + case tagPtr : + throw std::runtime_error("cannot archive RawPointers."); + return 0; + default : + return sizeof(double); + } + } + + PyrSymbol* readSymbolID() + { + char str[256]; + mStream.readSymbol(str); + return getsym(str); + } + + + PyrObject* readObjectID() + { + int32 objID = mStream.readInt32_be(); + //postfl("readObjectID %d\n", objID); + return mObjectArray[objID]; + } + + void writeObjectHeader(PyrObject *obj) + { + obj->ClearMark(); + + //postfl("writeObjectHeader %s\n", obj->classptr->name.us->name); + mStream.writeSymbol(obj->classptr->name.us->name); + + mStream.writeInt32_be(obj->size); + } + + PyrObject* readObjectHeader() + { + PyrSymbol* classname = readSymbolID(); + //post("readObjectHeader %s\n", classname->name); + PyrObject *obj; + int32 size = mStream.readInt32_be(); + if (classname->u.classobj->classFlags.ui & classHasIndexableInstances) { + obj = instantiateObject(g->gc, classname->u.classobj, size, false, false); + obj->size = size; + } else { + obj = instantiateObject(g->gc, classname->u.classobj, 0, false, false); + } + return obj; + } + + void writeSlots(PyrObject *obj) + { + //postfl(" writeSlots %s\n", obj->classptr->name.us->name); + if (isKindOf(obj, class_rawarray)) { + writeRawArray(obj); + } else if (isKindOf(obj, class_func)) { + PyrClosure* closure = (PyrClosure*)obj; + writeSlot(&closure->block); + } else { + for (int i=0; isize; ++i) { + writeSlot(obj->slots + i); + } + } + } + + void readSlots(PyrObject *obj) + { + //postfl("readSlots\n"); + if (isKindOf(obj, class_rawarray)) { + readRawArray(obj); + } else if (isKindOf(obj, class_func)) { + PyrClosure* closure = (PyrClosure*)obj; + readSlot(&closure->block); + closure->context.ucopy = g->process->interpreter.uoi->context.ucopy; + } else { + for (int i=0; isize; ++i) { + readSlot(obj->slots + i); + } + } + } + + void writeSlot(PyrSlot *slot) + { + PyrObject *obj; + //postfl(" writeSlot %08X\n", slot->utag); + switch (slot->utag) { + case tagObj : + obj = slot->uo; + if (isKindOf(obj, class_class)) { + mStream.writeInt8('C'); + mStream.writeSymbol(slot->uoc->name.us->name); + } else if (isKindOf(obj, class_process)) { + mStream.writeInt8('P'); + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + mStream.writeInt8('R'); + } else { + if (mSameAddressSpace && obj->IsPermanent()) { + mStream.writeInt8('z'); + mStream.writeInt32_be((int32)obj); + } else { + mStream.writeInt8('o'); + mStream.writeInt32_be(obj->scratch1); + } + } + break; + case tagHFrame : + case tagSFrame : + mStream.writeInt8('N'); + break; + case tagInt : + mStream.writeInt8('i'); + mStream.writeInt32_be(slot->ui); + break; + case tagSym : + mStream.writeInt8('s'); + mStream.writeSymbol(slot->us->name); + break; + case tagChar : + mStream.writeInt8('c'); + mStream.writeInt32_be(slot->ui); + break; + case tagNil : + mStream.writeInt8('N'); + break; + case tagFalse : + mStream.writeInt8('F'); + break; + case tagTrue : + mStream.writeInt8('T'); + break; + case tagInf : + mStream.writeInt8('I'); + break; + case tagPtr : + mStream.writeInt8('N'); + break; + default : + mStream.writeInt8('f'); + mStream.writeDouble_be(slot->uf); + break; + } + } + + void readSlot(PyrSlot *slot) + { + char tag = mStream.readInt8(); + switch (tag) { + case 'o' : + slot->utag = tagObj; + slot->uo = readObjectID(); + break; + case 'z' : + slot->utag = tagObj; + slot->ui = mStream.readInt32_be(); + break; + case 'C' : + slot->utag = tagObj; + slot->uo = (PyrObject*)readSymbolID()->u.classobj; + break; + case 'P' : + slot->utag = tagObj; + slot->uo = (PyrObject*)g->process; + break; + case 'R' : + slot->utag = tagObj; + slot->uo = g->process->interpreter.uo; + break; + case 'i' : + slot->utag = tagInt; + slot->ui = mStream.readInt32_be(); + break; + case 's' : + slot->utag = tagSym; + slot->us = readSymbolID(); + break; + case 'c' : + slot->utag = tagChar; + slot->ui = mStream.readInt32_be(); + break; + case 'f' : + slot->uf = mStream.readDouble_be(); + break; + case 'N' : + slot->utag = tagNil; + slot->ui = 0; + break; + case 'T' : + slot->utag = tagTrue; + slot->ui = 0; + break; + case 'F' : + slot->utag = tagFalse; + slot->ui = 0; + break; + case 'I' : + slot->utag = tagInf; + slot->ui = 0; + break; + default : + slot->utag = tagNil; + slot->ui = 0; + break; + } + } + + void writeRawArray(PyrObject *obj) + { + int32 size = obj->size; + //postfl("writeRawArray %d\n", size); + switch (obj->obj_format) { + case obj_char : + case obj_int8 : { + char *data = (char*)obj->slots; + mStream.writeData(data, size); + } break; + case obj_int16 : { + int16 *data = (int16*)obj->slots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; iname); + } + } break; + } + } + + void readRawArray(PyrObject *obj) + { + //postfl("readRawArray\n"); + int32 size = obj->size; + switch (obj->obj_format) { + case obj_char : + case obj_int8 : { + int8 *data = (int8*)obj->slots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; islots; + for (int i=0; i mStream; + int32 mReadArchiveVersion; + + PyrObject *mInitialObjectArray[kObjectArrayInitialCapacity]; +}; + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + + +#endif + diff --git a/sc4pd/headers/lang/PyrDeepCopier.h b/sc4pd/headers/lang/PyrDeepCopier.h new file mode 100755 index 0000000..3b46280 --- /dev/null +++ b/sc4pd/headers/lang/PyrDeepCopier.h @@ -0,0 +1,221 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + +#ifndef _PyrDeepCopier_ +#define _PyrDeepCopier_ + +#include "PyrObject.h" +#include "SC_AllocPool.h" + +#include "PyrKernel.h" +#include "PyrPrimitive.h" +#include "VMGlobals.h" +#include "GC.h" +#include "ReadWriteMacros.h" + +const int32 kDeepCopierObjectArrayInitialCapacity = 32; + +class PyrDeepCopier +{ +public: + PyrDeepCopier(VMGlobals *inG) + : g(inG), objectArray(initialObjectArray), numObjects(0), + objectArrayCapacity( kDeepCopierObjectArrayInitialCapacity ) + { + } + + ~PyrDeepCopier() + { + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + } + + long doDeepCopy(PyrSlot *objectSlot) + { + long err = errNone; + + try { + if (IsObj(objectSlot)) { + constructObjectArray(objectSlot->uo); + for (int i=0; iClearMark(); + } + + } + } catch (std::exception &ex) { + error(ex.what()); + err = errFailed; + } + return err; + } + +private: + + void recurse(PyrObject *obj, int n) + { + //post("->recurse %s %08X\n", obj->classptr->name.us->name, obj); + PyrSlot *slot = obj->slots; + for (int i=0; iuo); + } + //post("<-recurse %s %08X\n", obj->classptr->name.us->name, obj); + } + + void growObjectArray() + { + int32 newObjectArrayCapacity = objectArrayCapacity << 1; + + int32 newSize = newObjectArrayCapacity * sizeof(PyrObject*); + PyrObject** newArray = (PyrObject**)g->allocPool->Alloc(newSize); + memcpy(newArray, objectArray, numObjects * sizeof(PyrObject*)); + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + objectArrayCapacity = newObjectArrayCapacity; + objectArray = newArray; + } + + void putSelf(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = numObjects; + + // expand array if needed + if (numObjects >= objectArrayCapacity) growObjectArray(); + + //post("putSelf %d %08X\n", numObjects, obj); + // add to array + objectArray[numObjects++] = obj; + } + + void putCopy(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = numObjects; + + // expand array if needed + if (numObjects+2 >= objectArrayCapacity) growObjectArray(); + + // add a shallow copy to object array + PyrObject *copy = copyObject(g->gc, obj, false); + copy->ClearMark(); + + //post("putCopy %d %08X\n", numObjects, copy); + + // add to array + objectArray[numObjects++] = copy; + objectArray[numObjects++] = obj; + } + + void constructObjectArray(PyrObject *obj) + { + //post("->constructObjectArray %s %08X\n", obj->classptr->name.us->name, obj); + if (!obj->IsMarked()) { + if (isKindOf(obj, class_class)) { + putSelf(obj); + } else if (isKindOf(obj, class_process)) { + putSelf(obj); + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + putSelf(obj); + } else if (isKindOf(obj, class_rawarray)) { + putCopy(obj); + } else if (isKindOf(obj, class_array)) { + putCopy(obj); + recurse(obj, obj->size); + } else if (isKindOf(obj, class_func)) { + putSelf(obj); + } else if (isKindOf(obj, class_method)) { + putSelf(obj); + } else if (isKindOf(obj, class_thread)) { + putSelf(obj); + } else { + putCopy(obj); + recurse(obj, obj->size); + } + } + //post("<-constructObjectArray %s %08X\n", obj->classptr->name.us->name, obj); + } + + void fixObjSlot(PyrSlot* slot) + { + //post("fixObjSlot %s %08X %d %08X\n", slot->uo->classptr->name.us->name, slot->uo, slot->uo->scratch1, objectArray[slot->uo->scratch1]); + slot->uo = objectArray[slot->uo->scratch1]; + } + + void fixSlots(PyrObject *obj) + { + //post("fixSlots %s %08X %d\n", obj->classptr->name.us->name, obj, obj->IsMarked()); + if (!obj->IsMarked() && obj->obj_format <= obj_slot) { // it is a copy + PyrSlot *slot = obj->slots; + for (int i=0; isize; ++i, ++slot) { + if (IsObj(slot)) fixObjSlot(slot); + } + } + } + + VMGlobals *g; + + PyrObject **objectArray; + int32 numObjects; + int32 objectArrayCapacity; + + PyrObject *initialObjectArray[kDeepCopierObjectArrayInitialCapacity]; +}; + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + + +#endif + diff --git a/sc4pd/headers/lang/PyrDeepFreezer.h b/sc4pd/headers/lang/PyrDeepFreezer.h new file mode 100755 index 0000000..28d9a12 --- /dev/null +++ b/sc4pd/headers/lang/PyrDeepFreezer.h @@ -0,0 +1,178 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + +#ifndef _PyrDeepFreezer_ +#define _PyrDeepFreezer_ + +#include "PyrObject.h" +#include "SC_AllocPool.h" +#include "PyrKernel.h" +#include "PyrPrimitive.h" +#include "VMGlobals.h" +#include "GC.h" + +const int32 kDeepFreezerObjectArrayInitialCapacity = 32; + +class PyrDeepFreezer +{ +public: + PyrDeepFreezer(VMGlobals *inG) + : g(inG), objectArray(initialObjectArray), numObjects(0), + objectArrayCapacity( kDeepCopierObjectArrayInitialCapacity ) + { + } + + ~PyrDeepFreezer() + { + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + } + + long doDeepFreeze(PyrSlot *objectSlot) + { + long err = errNone; + + try { + if (IsObj(objectSlot)) { + constructObjectArray(objectSlot->uo); + for (int i=0; igc->BecomePermanent( objectArray[i] ); + } + } + } catch (std::exception &ex) { + error(ex.what()); + err = errFailed; + } + return err; + } + +private: + + void recurse(PyrObject *obj, int n) + { + PyrSlot *slot = obj->slots; + for (int i=0; iuo); + } + } + + void growObjectArray() + { + int32 newObjectArrayCapacity = objectArrayCapacity << 1; + + int32 newSize = newObjectArrayCapacity * sizeof(PyrObject*); + PyrObject** newArray = (PyrObject**)g->allocPool->Alloc(newSize); + memcpy(newArray, objectArray, numObjects * sizeof(PyrObject*)); + if (objectArrayCapacity > kDeepCopierObjectArrayInitialCapacity) { + g->allocPool->Free(objectArray); + } + objectArrayCapacity = newObjectArrayCapacity; + objectArray = newArray; + } + + void putObject(PyrObject *obj) + { + obj->SetMark(); + obj->scratch1 = numObjects; + + // expand array if needed + if (numObjects >= objectArrayCapacity) growObjectArray(); + + // add to array + objectArray[numObjects++] = obj; + } + + void constructObjectArray(PyrObject *obj) + { + if (obj->IsPermanent()) return; + + if (!obj->IsMarked()) { + if (isKindOf(obj, class_process)) { + throw std::runtime_error("cannot freeze Process.\n"); + } else if (isKindOf(obj, s_interpreter->u.classobj)) { + throw std::runtime_error("cannot freeze Interpreter.\n"); + } else if (isKindOf(obj, class_rawarray)) { + putObject(obj); + } else if (isKindOf(obj, class_array)) { + putObject(obj); + recurse(obj, obj->size); + } else if (isKindOf(obj, class_func)) { + if (NotNil(&((PyrClosure*)obj)->block.uoblk->context)) { + throw std::runtime_error("open Function can not be frozen.\n"); + } + putObject(obj); + recurse(obj, obj->size); + } else if (isKindOf(obj, class_method)) { + throw std::runtime_error("cannot freeze Methods.\n"); + } else if (isKindOf(obj, class_thread)) { + throw std::runtime_error("cannot freeze Threads.\n"); + } else if (isKindOf(obj, class_frame)) { + throw std::runtime_error("cannot freeze Frames.\n"); + } else { + putObject(obj); + recurse(obj, obj->size); + } + } + } + + VMGlobals *g; + + PyrObject **objectArray; + int32 numObjects; + int32 objectArrayCapacity; + + PyrObject *initialObjectArray[kDeepCopierObjectArrayInitialCapacity]; +}; + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +An object archiving system for SuperCollider. + +*/ + + + +#endif + diff --git a/sc4pd/headers/lang/PyrErrors.h b/sc4pd/headers/lang/PyrErrors.h new file mode 100755 index 0000000..b2be76e --- /dev/null +++ b/sc4pd/headers/lang/PyrErrors.h @@ -0,0 +1,49 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +virtual machine error codes. + +*/ + +#ifndef _SCErrors_ +#define _SCErrors_ + +enum { // primitive errors + errReturn = -1, // not really an error.. primitive executed a non-local return + errNone, + errFailed = 5000, + errBadPrimitive, + errWrongType, + errIndexNotAnInteger, + errIndexOutOfRange, + errImmutableObject, + errNotAnIndexableObject, + errStackOverflow, + errOutOfMemory, + errCantCallOS, + errException, + + errPropertyNotFound = 6000, + + errLastError +}; + +#endif diff --git a/sc4pd/headers/lang/PyrFilePrim.h b/sc4pd/headers/lang/PyrFilePrim.h new file mode 100755 index 0000000..3574927 --- /dev/null +++ b/sc4pd/headers/lang/PyrFilePrim.h @@ -0,0 +1,62 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef _PYRFILEPRIM_H_ +#define _PYRFILEPRIM_H_ + +#include "PyrObject.h" + +struct PyrFile : public PyrObjectHdr +{ + PyrSlot fileptr; +}; + +void initFilePrimitives(); + +long prFileDelete(VMGlobals *g, long numArgsPushed); +long prFileOpen(VMGlobals *g, long numArgsPushed); +long prFileClose(VMGlobals *g, long numArgsPushed); +long prFileSeek(VMGlobals *g, long numArgsPushed); +long prFilePos(VMGlobals *g, long numArgsPushed); +long prFileLength(VMGlobals *g, long numArgsPushed); +long prFileWrite(VMGlobals *g, long numArgsPushed); +long prFileReadLine(VMGlobals *g, long numArgsPushed); + +long prFilePutRGB(VMGlobals *g, long numArgsPushed); +long prFilePutInt32(VMGlobals *g, long numArgsPushed); +long prFilePutInt16(VMGlobals *g, long numArgsPushed); +long prFilePutInt8(VMGlobals *g, long numArgsPushed); +long prFilePutChar(VMGlobals *g, long numArgsPushed); +long prFilePutFloat(VMGlobals *g, long numArgsPushed); +long prFilePutDouble(VMGlobals *g, long numArgsPushed); + +long prFileGetRGB(VMGlobals *g, long numArgsPushed); +long prFileGetInt32(VMGlobals *g, long numArgsPushed); +long prFileGetInt16(VMGlobals *g, long numArgsPushed); +long prFileGetInt8(VMGlobals *g, long numArgsPushed); +long prFileGetChar(VMGlobals *g, long numArgsPushed); +long prFileGetFloat(VMGlobals *g, long numArgsPushed); +long prFileGetDouble(VMGlobals *g, long numArgsPushed); + +long prFilePutString(VMGlobals *g, long numArgsPushed); +long prFileRead(VMGlobals *g, long numArgsPushed); + + +#endif + diff --git a/sc4pd/headers/lang/PyrFileUtils.h b/sc4pd/headers/lang/PyrFileUtils.h new file mode 100755 index 0000000..1fd682b --- /dev/null +++ b/sc4pd/headers/lang/PyrFileUtils.h @@ -0,0 +1,50 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Some utils for file i/o. + +*/ + +#ifndef _PYRFILEUTIL_H_ +#define _PYRFILEUTIL_H_ + +int headerFormatFromSymbol(struct PyrSymbol *inSymbol); +int sampleFormatFromSymbol(struct PyrSymbol *inSymbol, int inHeaderFormat); + +#ifdef __MAC__ + +#include + +long setTypeCreator(unsigned char *filename, long type, long creator); +bool filelen(FILE *file, size_t *length); + +int allocasync(int fildes, int count, IOParam *pb, IOCompletionUPP completionFunc); +int createasync(unsigned char *path, int oflag, HParamBlockRec *hpb, IOCompletionUPP completionFunc); +int openasync(unsigned char *path, int oflag, HParamBlockRec *hpb, IOCompletionUPP completionFunc); +int closeasync(int fildes, HParamBlockRec *hpb, IOCompletionUPP completionFunc); +int writeasync(int fildes, const char *buf, int count, IOParam *pb, IOCompletionUPP completionFunc); +int readasync(int fildes, char *buf, int count, IOParam *pb, IOCompletionUPP completionFunc); +int seekwriteasync(int fildes, const char *buf, int count, int pos, IOParam *pb, IOCompletionUPP completionFunc); +int seekreadasync(int fildes, char *buf, int count, int pos, IOParam *pb, IOCompletionUPP completionFunc); + + +#endif +#endif diff --git a/sc4pd/headers/lang/PyrInterpreter.h b/sc4pd/headers/lang/PyrInterpreter.h new file mode 100755 index 0000000..a21126d --- /dev/null +++ b/sc4pd/headers/lang/PyrInterpreter.h @@ -0,0 +1,47 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRINTERPRETER_H_ +#define _PYRINTERPRETER_H_ + +#include "PyrSlot.h" +#include "VMGlobals.h" + +extern bool gRunningInterpreterThread; + +extern int gNumClasses; + +bool initInterpreter(VMGlobals *g, PyrSymbol *selector, int numArgsPushed); +bool initRuntime(VMGlobals *g, int poolSize, AllocPool *inPool, int processID); +void Interpret(VMGlobals *g); +void endInterpreter(VMGlobals *g); + +int doSpecialUnaryArithMsg(VMGlobals *g, int numArgsPushed); +int prSpecialBinaryArithMsg(VMGlobals *g, int numArgsPushed); +int doSpecialBinaryArithMsg(VMGlobals *g, int numArgsPushed, bool isPrimitive); +void DumpBackTrace(VMGlobals *g); +void DumpStack(VMGlobals *g, PyrSlot *sp); +void DumpFrame(struct PyrFrame *frame); +bool FrameSanity(PyrFrame *frame, char *tagstr); +struct PyrProcess* newPyrProcess(VMGlobals *g, struct PyrClass *classobj); +void startProcess(VMGlobals *g, PyrSymbol *selector); +void runInterpreter(VMGlobals *g, PyrSymbol *selector, int numArgsPushed); + +#endif diff --git a/sc4pd/headers/lang/PyrKernel.h b/sc4pd/headers/lang/PyrKernel.h new file mode 100755 index 0000000..d5c6af7 --- /dev/null +++ b/sc4pd/headers/lang/PyrKernel.h @@ -0,0 +1,256 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +This file contains the definitions of the core objects that implement the class system. + +*/ + +#ifndef _PYRKERNEL_H_ +#define _PYRKERNEL_H_ + +#include "PyrObject.h" +#include "VMGlobals.h" + +#define classClassNumInstVars 16 + +enum { classIsIntrinsic = 1, classHasIndexableInstances = 2, classCompileUGen = 4 }; + +struct PyrClass : public PyrObjectHdr +{ + PyrSlot name; + PyrSlot nextclass; + PyrSlot superclass; + PyrSlot subclasses; + PyrSlot methods; + + PyrSlot instVarNames; + PyrSlot classVarNames; + PyrSlot iprototype; // instance prototype + PyrSlot cprototype; // class var prototype + + PyrSlot instanceFormat; + PyrSlot instanceFlags; + PyrSlot classIndex; + PyrSlot classFlags; + PyrSlot maxSubclassIndex; // used by isKindOf + PyrSlot filenameSym; + PyrSlot charPos; +}; + + + +inline bool isKindOf(PyrObjectHdr *obj, struct PyrClass *testclass) +{ + int objClassIndex = obj->classptr->classIndex.ui; + return objClassIndex >= testclass->classIndex.ui && objClassIndex <= testclass->maxSubclassIndex.ui; +} + +inline bool isKindOfSlot(PyrSlot *slot, struct PyrClass *testclass) +{ + return IsObj(slot) && isKindOf(slot->uo, testclass); +} + +/* + operations on class: + numInstVars() + numClassVars() + +*/ + +struct PyrFrame { + PyrSlot vars[1]; + PyrSlot myself; + PyrSlot method; + PyrSlot caller; + PyrSlot context; + PyrSlot homeContext; + PyrSlot ip; +}; + +#define FRAMESIZE 6 +#define USESTACKFRAMES 1 + +struct PyrProcess : public PyrObjectHdr +{ + + PyrSlot classVars; + PyrSlot interpreter; + PyrSlot curThread, mainThread; + PyrSlot processID; + PyrSlot sysSchedulerQueue; +}; + + +enum { tInit, tStart, tReady, tRunning, tSleeping, tBlocked, tYieldToChild, tYieldToParent, tDone }; + +struct PyrThread : public PyrObjectHdr +{ + + PyrSlot state, func, stack, stackSize, method, block, frame, ip, sp; + PyrSlot numpop, returnLevels, receiver, numArgsPushed; + PyrSlot parent, terminalValue; + PyrSlot primitiveError; + PyrSlot primitiveIndex; + PyrSlot randData; + PyrSlot beats, seconds, clock; + PyrSlot environment; + PyrSlot exceptionHandler; +}; + +#define EVALSTACKDEPTH 8192 + + + +struct PyrMethodRaw { + + unsigned short unused1; + unsigned short specialIndex; + unsigned short methType; + unsigned short frameSize; + + unsigned char unused2; + unsigned char numargs; + unsigned char varargs; + unsigned char numvars; + unsigned char numtemps; + unsigned char needsHeapContext; + unsigned char popSize; + unsigned char posargs; + +}; + + +#define METHRAW(obj) ((PyrMethodRaw*)&(((PyrBlock*)obj)->rawData1)) + +struct PyrBlock : public PyrObjectHdr +{ + + PyrSlot rawData1; + PyrSlot rawData2; + PyrSlot code; // byte codes, nil if inlined + PyrSlot selectors; // method selectors, class names, closures table + PyrSlot constants; // floating point constants table (to alleviate the literal table problem) + PyrSlot prototypeFrame; // prototype of an activation frame + PyrSlot context; // ***defining block context + PyrSlot argNames; // ***arguments to block + PyrSlot varNames; // ***variables in block + PyrSlot sourceCode; // source code if it is a closed function. +}; + +struct PyrMethod : public PyrBlock +{ + PyrSlot ownerclass; + PyrSlot name; + PyrSlot primitiveName; + PyrSlot filenameSym; + PyrSlot charPos; + //PyrSlot byteMeter; + //PyrSlot callMeter; +}; + +enum { + methNormal = 0, + methReturnSelf, + methReturnLiteral, + methReturnArg, + methReturnInstVar, + methAssignInstVar, + methReturnClassVar, + methAssignClassVar, + methRedirect, + methForward, + methPrimitive, + methBlock +}; + +struct PyrClosure : public PyrObjectHdr +{ + + PyrSlot block; + PyrSlot context; +}; + +struct PyrInterpreter : public PyrObjectHdr +{ + + PyrSlot cmdLine, context; + PyrSlot a, b, c, d, e, f, g, h, i, j; + PyrSlot k, l, m, n, o, p, q, r, s, t; + PyrSlot u, v, w, x, y, z; + PyrSlot codeDump; +}; + +/* special values */ +enum { + svNil, + svFalse, + svTrue, + svNegOne, + svZero, + svOne, + svTwo, + svFHalf, + svFNegOne, + svFZero, + svFOne, + svFTwo, + svInf, + + svNumSpecialValues +}; + +extern double gSpecialValues[svNumSpecialValues]; + +extern PyrMethod *gNullMethod; // used to fill row table + +PyrObject* instantiateObject(class PyrGC *gc, PyrClass* classobj, int size, + bool fill, bool collect); + +PyrObject* newPyrObject(class PyrGC *gc, size_t inNumBytes, int inFlags, int inFormat, bool inCollect); +PyrString* newPyrString(class PyrGC *gc, const char *s, int flags, bool collect); +PyrString* newPyrStringN(class PyrGC *gc, int size, int flags, bool collect); +PyrObject* newPyrArray(class PyrGC *gc, int size, int flags, bool collect); +PyrSymbolArray* newPyrSymbolArray(class PyrGC *gc, int size, int flags, bool collect); +PyrInt8Array* newPyrInt8Array(class PyrGC *gc, int size, int flags, bool collect); +PyrInt32Array* newPyrInt32Array(class PyrGC *gc, int size, int flags, bool collect); +PyrDoubleArray* newPyrDoubleArray(class PyrGC *gc, int size, int flags, bool collect); + +PyrObject* copyObject(class PyrGC *gc, PyrObject *inobj, bool collect); +PyrObject* copyObjectRange(class PyrGC *gc, PyrObject *inobj, int start, int end, bool collect); + +inline void SetFrame(PyrSlot* slot, PyrFrame* frame) +{ + (slot)->ui = ((int)(frame)); + (slot)->utag = tagSFrame - METHRAW((frame)->method.uoblk)->needsHeapContext; +} + +inline void SetFrameOrNil(PyrSlot* slot, PyrFrame* frame) +{ + if (frame) { + (slot)->ui = ((int)(frame)); + (slot)->utag = tagSFrame - METHRAW((frame)->method.uoblk)->needsHeapContext; + } else { + (slot)->utag = tagNil; + (slot)->ui = 0; + } +} + +#endif diff --git a/sc4pd/headers/lang/PyrKernelProto.h b/sc4pd/headers/lang/PyrKernelProto.h new file mode 100755 index 0000000..f040507 --- /dev/null +++ b/sc4pd/headers/lang/PyrKernelProto.h @@ -0,0 +1,62 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRKERNELPROTO_H_ +#define _PYRKERNELPROTO_H_ + +PyrClass* newClassObj(PyrClass *classObjSuperClass, + PyrSymbol* className, PyrSymbol* superClassName, + int numInstVars, int numClassVars, int numInstMethods, + int instFormat, int instFlags); + +void reallocClassObj(PyrClass* classobj, + int numInstVars, int numClassVars, int numMethods, + int instFormat, int instFlags); + +int numInstVars(PyrClass* classobj); +int numClassVars(PyrClass* classobj); +int numSuperInstVars(PyrClass *superclassobj); +bool classFindInstVar(PyrClass* classobj, PyrSymbol *name, int *index); +bool classFindClassVar(PyrClass** classobj, PyrSymbol *name, int *index); + +void buildClassTree(); +void indexClassTree(PyrClass *classobj, int numSuperMethods); +void postClassTree(PyrClass *classobj, int level); +void setSelectorFlags(); +void buildBigMethodMatrix(); +void fillClassRow(PyrClass *classobj, struct PyrMethod** bigTable); + +bool funcFindArg(PyrBlock* func, PyrSymbol *name, int *index); +bool funcFindVar(PyrBlock* func, PyrSymbol *name, int *index); +void addMethod(PyrClass *classobj, PyrMethod *method); + + +PyrMethod* classFindDirectMethod(PyrClass* classobj, PyrSymbol *name); + +PyrBlock* newPyrBlock(int flags); +PyrMethod* newPyrMethod(); +PyrClass* makeIntrinsicClass(PyrSymbol *className, PyrSymbol *superClassName, + int numInstVars, int numClassVars); +void addIntrinsicVar(PyrClass *classobj, char *varName, PyrSlot *slot); + + + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrLexer.h b/sc4pd/headers/lang/PyrLexer.h new file mode 100755 index 0000000..5166337 --- /dev/null +++ b/sc4pd/headers/lang/PyrLexer.h @@ -0,0 +1,136 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRLEXER_H_ +#define _PYRLEXER_H_ + +#include "PyrSymbol.h" + +extern int charno, lineno, linepos; +extern int *linestarts; + +struct ClassExtFile { + struct ClassExtFile *next; + PyrSymbol *fileSym; +}; + +typedef struct classdep { + struct classdep *next; + struct classdep *superClassDep; + struct classdep *subclasses; + PyrSymbol *className; + PyrSymbol *superClassName; + PyrSymbol *fileSym; +} ClassDependancy; + +extern PyrSymbol *gCompilingFileSym; + +ClassDependancy* newClassDependancy(PyrSymbol *className, PyrSymbol *superClassName, + PyrSymbol *fileSym); +bool parseOneClass(PyrSymbol *fileSym); +void initPassOne(); +void finiPassOne(); +bool passOne(); +void buildDepTree(); +void traverseFullDepTree(); +void traverseDepTree(ClassDependancy *classdep, int level); +void traverseFullDepTree2(); +void traverseDepTree2(ClassDependancy *classdep, int level); +void compileClassExtensions(); +void compileFileSym(PyrSymbol *fileSym); + +void runLibrary(PyrSymbol* selector); + +void interpretCmdLine(const char *textbuf, int textlen, char *methodname); + + +int input(); +int input0(); +void unput(int c); +void unput0(int c); + +void finiLexer() ; +bool startLexer(char* filename) ; +void startLexerCmdLine(char *textbuf, int textbuflen); +int yylex() ; +void yyerror(char *s) ; +void fatal() ; +bool isValidSourceFileName(char *filename); +bool passOne_ProcessOneFile(char *filename, int level); + +extern void asRelativePath(char *inPath,char *outPath); + +void initLexer(); +void init_SuperCollider(); + +int processbinop(char *token); +int processident(char *token); +int processfloat(char *token, int sawpi); +int processint(char *token); +int processchar(int c); +int processintradix(char *s); +int processfloatradix(char *s); +int processhex(char *s); +int processsymbol(char *token); +int processstring(char *token); +int processkeywordbinop(char *token); + +void postErrorLine(int linenum, int start, int charpos); +bool scanForClosingBracket(); +void parseClasses(); + +extern int parseFailed; +extern bool compilingCmdLine; +extern bool compilingCmdLineErrorWindow; +extern bool compiledOK; + +#define MAXYYLEN 8192 + +extern int gNumCompiledFiles; +extern int gClassCompileOrderNum; +extern ClassDependancy **gClassCompileOrder; +extern char curfilename[PATH_MAX]; + +extern int runcount; + +extern char *binopchars; +extern char yytext[MAXYYLEN]; +extern char linebuf[256]; +extern char curfilename[PATH_MAX]; + +extern int yylen; +extern int lexCmdLine; +extern bool compilingCmdLine; +extern bool compilingCmdLineErrorWindow; +extern long zzval; + +extern int lineno, charno, linepos; +extern int *linestarts; +extern int maxlinestarts; + +extern char *text; +extern int textlen; +extern int textpos; +extern int parseFailed; +extern bool compiledOK; +extern int radixcharpos, decptpos; + +#endif diff --git a/sc4pd/headers/lang/PyrListPrim.h b/sc4pd/headers/lang/PyrListPrim.h new file mode 100755 index 0000000..43288a7 --- /dev/null +++ b/sc4pd/headers/lang/PyrListPrim.h @@ -0,0 +1,34 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRARRAYPRIM_H_ +#define _PYRARRAYPRIM_H_ + +void initArrayPrimitives(); + +int prArrayMultiChanExpand(VMGlobals *g, int numArgsPushed); + +int arrayAtIdentityHash(PyrObject *array, PyrSlot *key); +int arrayAtIdentityHashInPairs(PyrObject *array, PyrSlot *key); +int arrayAtIdentityHashInPairsWithHash(PyrObject *array, PyrSlot *key, int hash); + + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrMathPrim.h b/sc4pd/headers/lang/PyrMathPrim.h new file mode 100755 index 0000000..f4e2dd1 --- /dev/null +++ b/sc4pd/headers/lang/PyrMathPrim.h @@ -0,0 +1,51 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRMATHPRIM_H_ +#define _PYRMATHPRIM_H_ + +void initMathPrimitives(); + +int prAddNum(VMGlobals *g, int numArgsPushed); +int prSubNum(VMGlobals *g, int numArgsPushed); +int prMulNum(VMGlobals *g, int numArgsPushed); + +int prAddInt(VMGlobals *g, int numArgsPushed); +int prSubInt(VMGlobals *g, int numArgsPushed); +int prMulInt(VMGlobals *g, int numArgsPushed); + +int prAddFloat(VMGlobals *g, int numArgsPushed); +int prSubFloat(VMGlobals *g, int numArgsPushed); +int prMulFloat(VMGlobals *g, int numArgsPushed); + +int mathClip(VMGlobals *g, int numArgsPushed); +int mathWrap(VMGlobals *g, int numArgsPushed); +int mathFold(VMGlobals *g, int numArgsPushed); +int mathClipInt(VMGlobals *g, int numArgsPushed); +int mathWrapInt(VMGlobals *g, int numArgsPushed); +int mathFoldInt(VMGlobals *g, int numArgsPushed); +int mathClipFloat(VMGlobals *g, int numArgsPushed); +int mathWrapFloat(VMGlobals *g, int numArgsPushed); +int mathFoldFloat(VMGlobals *g, int numArgsPushed); +int mathClipSignal(VMGlobals *g, int numArgsPushed); +int mathWrapSignal(VMGlobals *g, int numArgsPushed); +int mathFoldSignal(VMGlobals *g, int numArgsPushed); + +#endif diff --git a/sc4pd/headers/lang/PyrMessage.h b/sc4pd/headers/lang/PyrMessage.h new file mode 100755 index 0000000..436128a --- /dev/null +++ b/sc4pd/headers/lang/PyrMessage.h @@ -0,0 +1,55 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRMESSAGE_H_ +#define _PYRMESSAGE_H_ + +#include "PyrKernel.h" + +#define MAXKEYSLOTS 128 +extern PyrSlot keywordstack[MAXKEYSLOTS]; +extern bool gKeywordError; +extern PyrMethod **gRowTable; + +void initUniqueMethods(); + +void sendMessageWithKeys(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed, long numKeyArgsPushed); +void sendMessage(VMGlobals *g, PyrSymbol *selector, long numArgsPushed); +void sendSuperMessageWithKeys(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed, long numKeyArgsPushed); +void sendSuperMessage(VMGlobals *g, PyrSymbol *selector, long numArgsPushed); +void doesNotUnderstandWithKeys(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed, long numKeyArgsPushed); +void doesNotUnderstand(VMGlobals *g, PyrSymbol *selector, + long numArgsPushed); +void returnFromBlock(VMGlobals *g); +void returnFromMethod(VMGlobals *g); +void executeMethod(VMGlobals *g, PyrMethod *meth, long numArgsPushed); +void executeMethodWithKeys(VMGlobals *g, PyrMethod *meth, long allArgsPushed, + long numKeyArgsPushed); +void keywordFixStack(VMGlobals *g, PyrMethod *meth, PyrMethodRaw *methraw, long allArgsPushed, + long numKeyArgsPushed); + +#endif + + + diff --git a/sc4pd/headers/lang/PyrObject.h b/sc4pd/headers/lang/PyrObject.h new file mode 100755 index 0000000..05abf21 --- /dev/null +++ b/sc4pd/headers/lang/PyrObject.h @@ -0,0 +1,288 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +PyrObject represents the structure of all SC Objects. + +*/ + +#ifndef _PYROBJECT_H_ +#define _PYROBJECT_H_ + +#include "PyrSlot.h" + +/* special gc colors */ +enum { + obj_permanent = 1, // sent to gc->New as a flag + obj_gcmarker = 2 // gc treadmill marker +}; + +/* obj flag fields */ +enum { + obj_immutable = 16, + obj_marked = 128 +}; + +/* format types : */ +enum { + obj_notindexed, + obj_slot, + obj_double, + obj_float, + obj_int32, + obj_int16, + obj_int8, + obj_char, + obj_symbol, + + NUMOBJFORMATS +}; + + +/* + PyrObjectHdr : object header fields + prev, next : pointers in the GC treadmill + classptr : pointer to the object's class + size : number of slots or indexable elements. + + obj_format : what kind of data this object holds + obj_sizeclass : power of two size class of the object + obj_flags : + immutable : set if object may not be updated. + finalize : set if object requires finalization. + marked : used by garbage collector debug sanity check. may be used by primitives but must be cleared before exiting primitive. + gc_color : GC color : black, grey, white, free, permanent + scratch1 : undefined value. may be used within primitives as a temporary scratch value. +*/ + +struct PyrObjectHdr { + struct PyrObjectHdr *prev, *next; + struct PyrClass *classptr; + int size; + + unsigned char obj_format; + unsigned char obj_sizeclass; + unsigned char obj_flags; + unsigned char gc_color; + + int scratch1; + + int SizeClass() { return obj_sizeclass; } + + void SetMark() { obj_flags |= obj_marked; } + void ClearMark() { obj_flags &= ~obj_marked; } + bool IsMarked() { return obj_flags & obj_marked; } + bool IsPermanent() { return gc_color == obj_permanent; } +}; + +struct PyrObject : public PyrObjectHdr { + PyrSlot slots[1]; +}; + +struct PyrList : public PyrObjectHdr +{ + PyrSlot array; +}; + +struct PyrDoubleArray : public PyrObjectHdr +{ + double d[1]; +}; + +struct PyrFloatArray : public PyrObjectHdr +{ + float f[1]; +}; + +struct PyrInt32Array : public PyrObjectHdr +{ + uint32 i[1]; +}; + +struct PyrInt16Array : public PyrObjectHdr +{ + uint16 i[1]; +}; + +struct PyrInt8Array : public PyrObjectHdr +{ + uint8 b[1]; +}; + +struct PyrRGBArray : public PyrObjectHdr +{ + RGBColor8 r[1]; +}; + +struct PyrString : public PyrObjectHdr +{ + char s[1]; +}; + +struct PyrSymbolArray : public PyrObjectHdr +{ + PyrSymbol* symbols[1]; +}; + +extern struct PyrClass *class_object; +extern struct PyrClass *class_array; +extern struct PyrClass *class_list, *class_method, *class_fundef, *class_frame, *class_class; +extern struct PyrClass *class_symbol, *class_nil; +extern struct PyrClass *class_boolean, *class_true, *class_false; +extern struct PyrClass *class_int, *class_char, *class_float, *class_complex; +extern struct PyrClass *class_rawptr; +extern struct PyrClass *class_string; +extern struct PyrClass *class_magnitude, *class_number, *class_collection; +extern struct PyrClass *class_sequenceable_collection; +extern struct PyrClass *class_arrayed_collection; +extern struct PyrClass *class_simple_number; +extern struct PyrClass *class_signal; +extern struct PyrClass *class_wavetable; +extern struct PyrClass *class_rawarray; +extern struct PyrClass *class_int8array; +extern struct PyrClass *class_int16array; +extern struct PyrClass *class_int32array; +extern struct PyrClass *class_symbolarray; +extern struct PyrClass *class_floatarray; +extern struct PyrClass *class_doublearray; +extern struct PyrClass *class_func, *class_absfunc; +extern struct PyrClass *class_stream; +extern struct PyrClass *class_process; +extern struct PyrClass *class_thread; +extern struct PyrClass *class_routine; +extern struct PyrClass *class_inf; +extern struct PyrClass *class_finalizer; + +extern PyrSymbol *s_none; +extern PyrSymbol *s_object; +extern PyrSymbol *s_bag; +extern PyrSymbol *s_set; +extern PyrSymbol *s_identityset; +extern PyrSymbol *s_dictionary; +extern PyrSymbol *s_identitydictionary; +extern PyrSymbol *s_linkedlist; +extern PyrSymbol *s_sortedlist; +extern PyrSymbol *s_array; +extern PyrSymbol *s_list, *s_method, *s_fundef, *s_frame, *s_class; +extern PyrSymbol *s_symbol, *s_nil, *s_inf; +extern PyrSymbol *s_boolean, *s_true, *s_false; +extern PyrSymbol *s_int, *s_char, *s_color, *s_float, *s_complex; +extern PyrSymbol *s_rawptr, *s_objptr; +extern PyrSymbol *s_string; +extern PyrSymbol *s_magnitude, *s_number, *s_collection; +extern PyrSymbol *s_ordered_collection; +extern PyrSymbol *s_sequenceable_collection; +extern PyrSymbol *s_arrayed_collection; +extern PyrSymbol *s_simple_number; +extern PyrSymbol *s_signal; +extern PyrSymbol *s_wavetable; +extern PyrSymbol *s_int8array; +extern PyrSymbol *s_int16array; +extern PyrSymbol *s_int32array; +extern PyrSymbol *s_symbolarray; +extern PyrSymbol *s_floatarray; +extern PyrSymbol *s_doublearray; +extern PyrSymbol *s_point; +extern PyrSymbol *s_rect; +extern PyrSymbol *s_stream; +extern PyrSymbol *s_process; +extern PyrSymbol *s_main; +extern PyrSymbol *s_thread; +extern PyrSymbol *s_routine; +extern PyrSymbol *s_linear, *s_exponential, *s_gate; +extern PyrSymbol *s_env; + +extern PyrSymbol *s_audio, *s_control, *s_scalar; +extern PyrSymbol *s_run; +extern PyrSymbol *s_next; +extern PyrSymbol *s_at; +extern PyrSymbol *s_put; +extern PyrSymbol *s_series, *s_copyseries, *s_putseries; +extern PyrSymbol *s_value; +extern PyrSymbol *s_performList; +extern PyrSymbol *s_superPerformList; +extern PyrSymbol *s_ugen, *s_outputproxy; +extern PyrSymbol *s_new, *s_ref; +extern PyrSymbol *s_synth, *s_spawn, *s_environment, *s_event; +extern PyrSymbol *s_interpreter; +extern PyrSymbol *s_finalizer; +extern PyrSymbol *s_awake; +extern PyrSymbol *s_appclock; +extern PyrSymbol *s_systemclock; + + +extern int gFormatElemSize[NUMOBJFORMATS]; +extern int gFormatElemCapc[NUMOBJFORMATS]; +extern int gFormatElemTag[NUMOBJFORMATS]; + +void dumpObject(PyrObject *obj); +void dumpObjectSlot(PyrSlot *slot); + +bool respondsTo(PyrSlot *slot, PyrSymbol *selector); +bool isSubclassOf(struct PyrClass *classobj, struct PyrClass *testclass); + +const int kFloatTagIndex = 12; +extern struct PyrClass* gTagClassTable[16]; + +inline struct PyrClass* classOfSlot(PyrSlot *slot) +{ + PyrClass *classobj; + int tag; + if (IsFloat(slot)) classobj = gTagClassTable[kFloatTagIndex]; + else if ((tag = slot->utag & 0xF) == 1) classobj = slot->uo->classptr; + else classobj = gTagClassTable[tag]; + + return classobj; +} + +typedef int (*ObjFuncPtr)(struct VMGlobals*, struct PyrObject*); + +void stringFromPyrString(PyrString *obj, char *str, int maxlength); +void pstringFromPyrString(PyrString *obj, unsigned char *str, int maxlength); + +int instVarOffset(char *classname, char *instvarname); +int classVarOffset(char *classname, char *classvarname, PyrClass** classobj); + +void fillSlots(PyrSlot* slot, int size, PyrSlot* fillslot); +void nilSlots(PyrSlot* slot, int size); +void zeroSlots(PyrSlot* slot, int size); + +int calcHash(PyrSlot *a); +int getIndexedFloat(struct PyrObject *obj, int index, float *value); +int getIndexedDouble(struct PyrObject *obj, int index, double *value); +void getIndexedSlot(struct PyrObject *obj, PyrSlot *a, int index); +int putIndexedSlot(struct VMGlobals *g, struct PyrObject *obj, PyrSlot *c, int index); +int putIndexedFloat(PyrObject *obj, double val, int index); + +inline int ARRAYMAXINDEXSIZE(PyrObjectHdr* obj) +{ + return (1L << obj->obj_sizeclass); +} + +inline int MAXINDEXSIZE(PyrObjectHdr* obj) +{ + return ((1L << obj->obj_sizeclass) * gFormatElemCapc[ obj->obj_format ]); +} + +void InstallFinalizer(VMGlobals* g, PyrObject *inObj, int slotIndex, ObjFuncPtr inFunc); + +///// + +#endif diff --git a/sc4pd/headers/lang/PyrObjectProto.h b/sc4pd/headers/lang/PyrObjectProto.h new file mode 100755 index 0000000..b66ecc2 --- /dev/null +++ b/sc4pd/headers/lang/PyrObjectProto.h @@ -0,0 +1,44 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYROBJPROTO_H_ +#define _PYROBJPROTO_H_ + +#include "PyrObject.h" + +void initSymbols(); +void initClasses(); +void buildClassTree(); + +void freePyrSlot(PyrSlot *slot); +void freePyrObject(PyrObject* obj); + +bool objAddIndexedSlot(PyrObject *obj, PyrSlot *slot); +bool objAddIndexedSymbol(PyrSymbolArray *obj, PyrSymbol *symbol); +bool objAddIndexedObject(PyrObject *obj, PyrObject *obj2); + +void CallStackSanity(struct VMGlobals *g, char* tagstr); +bool FrameSanity(struct PyrFrame *frame, char* tagstr); + +void dumpBadObject(PyrObject *obj); +void initRawRegistry(); + +#endif + diff --git a/sc4pd/headers/lang/PyrParseNode.h b/sc4pd/headers/lang/PyrParseNode.h new file mode 100755 index 0000000..cd6688c --- /dev/null +++ b/sc4pd/headers/lang/PyrParseNode.h @@ -0,0 +1,456 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRPARSENODE_H_ +#define _PYRPARSENODE_H_ + +#include "PyrSlot.h" +#include "PyrKernel.h" +#include "ByteCodeArray.h" +#include "Opcodes.h" +#include "AdvancingAllocPool.h" + +extern AdvancingAllocPool gParseNodePool; + +#define ALLOCNODE(type) (type*)gParseNodePool.Alloc(sizeof(type)) +//#define FREENODE(node) if (node) (*parseNodeClasses[(node)->classno]->deleteFunc)(node); +#define DUMPNODE(node, level) if (node) (*parseNodeClasses[(node)->classno]->dumpFunc)((node),(level)); +#define COMPILENODE(node, result) (*parseNodeClasses[(node)->classno]->compileFunc)((node),(result)); + +typedef void (*PyrCompileNodeFunc)(void*, void*); +typedef void (*PyrDumpNodeFunc)(void*,int); + +typedef struct pyrparsenodeclass { + int type; + PyrCompileNodeFunc compileFunc; + PyrDumpNodeFunc dumpFunc; +} PyrParseNodeClass; + + +struct PyrParseNode { + struct PyrParseNode *next; + struct PyrParseNode *tail; + short lineno; + unsigned char charno, classno; +}; + + +struct PyrSlotNode : public PyrParseNode { + PyrSlot slot; +}; + +extern PyrParseNodeClass *pyrSlotNodeClass; + +struct PyrPushNameNode : public PyrParseNode { + PyrSlot varName; +} ; + +extern PyrParseNodeClass *pyrPushNameNodeClass; + +struct PyrClassExtNode : public PyrParseNode { + struct PyrSlotNode* className; + struct PyrMethodNode *methods; +} ; + +extern PyrParseNodeClass *pyrClassExtNodeClass; + +struct PyrClassNode : public PyrParseNode { + struct PyrSlotNode* className; + struct PyrSlotNode* superClassName; + struct PyrSlotNode* indexType; + struct PyrVarListNode *varlists; + struct PyrMethodNode *methods; + int varTally[3]; + int numsuperinstvars; +} ; + +extern PyrParseNodeClass *pyrClassNodeClass; + +struct PyrMethodNode : public PyrParseNode { + struct PyrSlotNode* methodName; + struct PyrSlotNode* primitiveName; + struct PyrArgListNode *arglist; + struct PyrVarListNode *varlist; + struct PyrParseNode *body; + int isClassMethod; // is class method? + bool extension; +} ; + +extern PyrParseNodeClass *pyrMethodNodeClass; + +struct PyrVarListNode : public PyrParseNode { + struct PyrVarDefNode *varDefs; + int flags; +} ; + +extern PyrParseNodeClass *pyrVarListNodeClass; + +struct PyrVarDefNode : public PyrParseNode { + struct PyrSlotNode* varName; + struct PyrLiteralNode* defVal; + int flags; +} ; + +extern PyrParseNodeClass *pyrVarDefNodeClass; + +struct PyrCallNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *arglist; + struct PyrParseNode *keyarglist; +} ; + +extern PyrParseNodeClass *pyrCallNodeClass; + +struct PyrBinopCallNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *arg1; + struct PyrParseNode *arg2; + struct PyrParseNode *arg3; +} ; + +extern PyrParseNodeClass *pyrBinopCallNodeClass; + +struct PyrDropNode : public PyrParseNode { + struct PyrParseNode *expr1; + struct PyrParseNode *expr2; +} ; + +extern PyrParseNodeClass *pyrDropNodeClass; + +struct PyrPushLitNode : public PyrParseNode { + PyrSlot literalSlot; +} ; + +extern PyrParseNodeClass *pyrPushLitNodeClass; + +struct PyrPushKeyArgNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *expr; +} ; + +extern PyrParseNodeClass *pyrPushKeyArgNodeClass; + +struct PyrLiteralNode : public PyrParseNode { + PyrSlot literalSlot; +} ; + +extern PyrParseNodeClass *pyrLiteralNodeClass; + + +struct PyrReturnNode : public PyrParseNode { + struct PyrParseNode *expr; // if null, return self +} ; + +extern PyrParseNodeClass *pyrReturnNodeClass; + +struct PyrBlockReturnNode : public PyrParseNode { + struct PyrParseNode *expr; // if null, return self +} ; + +extern PyrParseNodeClass *pyrBlockReturnNodeClass; + + +struct PyrAssignNode : public PyrParseNode { + struct PyrSlotNode* varName; + struct PyrParseNode *expr; + bool drop; // allow drop +} ; + +extern PyrParseNodeClass *pyrAssignNodeClass; + +struct PyrSetterNode : public PyrParseNode { + struct PyrSlotNode* selector; + struct PyrParseNode *expr1; + struct PyrParseNode *expr2; + int flags; // is a var def ? +} ; + +extern PyrParseNodeClass *pyrSetterNodeClass; + +struct PyrMultiAssignNode : public PyrParseNode { + struct PyrMultiAssignVarListNode *varList; + struct PyrParseNode *expr; + bool drop; // allow drop +} ; + +extern PyrParseNodeClass *pyrMultiAssignNodeClass; + +struct PyrMultiAssignVarListNode : public PyrParseNode { + struct PyrSlotNode *varNames; + struct PyrSlotNode *rest; +} ; + +extern PyrParseNodeClass *pyrMultiAssignVarListNodeClass; + +struct PyrBlockNode : public PyrParseNode { + struct PyrArgListNode *arglist; + struct PyrVarListNode *varlist; + struct PyrParseNode *body; + bool isTopLevel; + int beginCharNo; +} ; + + +extern PyrParseNodeClass *pyrBlockNodeClass; + +struct PyrArgListNode : public PyrParseNode { + struct PyrVarDefNode *varDefs; + struct PyrSlotNode *rest; +} ; + +extern PyrParseNodeClass *pyrArgListNodeClass; + +struct PyrDynListNode : public PyrParseNode { + struct PyrParseNode *classname; + struct PyrParseNode *elems; +} ; + +extern PyrParseNodeClass *pyrDynListNodeClass; + +struct PyrDynDictNode : public PyrParseNode { + struct PyrParseNode *elems; +} ; + +extern PyrParseNodeClass *pyrDynDictNodeClass; + +struct PyrLitListNode : public PyrParseNode { + struct PyrParseNode *classname; + struct PyrParseNode *elems; +} ; + +extern PyrParseNodeClass *pyrLitListNodeClass; + +extern PyrParseNode* gRootParseNode; +extern int gParserResult; + +enum { rwPrivate=0, rwReadOnly=1, rwWriteOnly=2, rwReadWrite=3 }; + +enum { varInst, varClass, varTemp, varPseudo }; + +enum { + /* structural units */ + pn_ClassNode, + pn_ClassExtNode, + pn_MethodNode, + pn_BlockNode, + pn_SlotNode, + + /* variable declarations */ + pn_VarListNode, + pn_VarDefNode, + pn_DynDictNode, + pn_DynListNode, + pn_LitListNode, + + pn_StaticVarListNode, + pn_InstVarListNode, + pn_PoolVarListNode, + pn_ArgListNode, + pn_SlotDefNode, + + /* selectors */ + pn_LiteralNode, + + /* code */ + pn_PushLitNode, + pn_PushNameNode, + pn_PushKeyArgNode, + pn_CallNode, + pn_BinopCallNode, + pn_DropNode, + pn_AssignNode, + pn_MultiAssignNode, + pn_MultiAssignVarListNode, + pn_SetterNode, + + pn_ReturnNode, + pn_BlockReturnNode, + + pn_NumTypes +}; + +extern char *parseNodeFormat[pn_NumTypes]; +extern PyrParseNodeClass* parseNodeClasses[pn_NumTypes]; + + +void initParseNodes(); + +PyrParseNodeClass* newParseNodeClass(int type, PyrCompileNodeFunc compileFunc, + PyrDumpNodeFunc dumpFunc); + +PyrSlotNode* newPyrSlotNode(PyrSlot *slot); +PyrClassNode* newPyrClassNode(PyrSlotNode* className, PyrSlotNode* superClassName, + PyrVarListNode* varlists, PyrMethodNode* methods, PyrSlotNode* indexType); +PyrClassExtNode* newPyrClassExtNode(PyrSlotNode* className, PyrMethodNode* methods); +PyrMethodNode* newPyrMethodNode(PyrSlotNode* methodName, PyrSlotNode* primitiveName, + PyrArgListNode* arglist, PyrVarListNode *varlist, PyrParseNode* body, int isClassMethod); +PyrArgListNode* newPyrArgListNode(PyrVarDefNode* varDefs, PyrSlotNode* rest); +PyrVarListNode* newPyrVarListNode(PyrVarDefNode* vardefs, int flags); +PyrVarDefNode* newPyrVarDefNode(PyrSlotNode* varName, PyrLiteralNode* defVal, int flags); +PyrCallNode* newPyrCallNode(PyrSlotNode* selector, PyrParseNode* arglist, + PyrParseNode* keyarglist, PyrParseNode* blocklist); +PyrBinopCallNode* newPyrBinopCallNode(PyrSlotNode* selector, + PyrParseNode* arg1, PyrParseNode* arg2, PyrParseNode* arg3); +PyrDropNode* newPyrDropNode(PyrParseNode* expr1, PyrParseNode* expr2); +PyrPushKeyArgNode* newPyrPushKeyArgNode(PyrSlotNode* selector, PyrParseNode* expr); +PyrPushLitNode* newPyrPushLitNode(PyrSlotNode* literalSlot, PyrParseNode* literalObj); +PyrLiteralNode* newPyrLiteralNode(PyrSlotNode* literalSlot, PyrParseNode* literalObj); +PyrReturnNode* newPyrReturnNode(PyrParseNode* expr); +PyrBlockReturnNode* newPyrBlockReturnNode(); +PyrAssignNode* newPyrAssignNode(PyrSlotNode* varName, PyrParseNode* expr, int flags); +PyrSetterNode* newPyrSetterNode(PyrSlotNode* varName, + PyrParseNode* expr1, PyrParseNode* expr2); +PyrMultiAssignNode* newPyrMultiAssignNode(PyrMultiAssignVarListNode* varList, + PyrParseNode* expr, int flags); +PyrPushNameNode* newPyrPushNameNode(PyrSlotNode *slotNode); +PyrDynDictNode* newPyrDynDictNode(PyrParseNode *elems); +PyrDynListNode* newPyrDynListNode(PyrParseNode *classname, PyrParseNode *elems); +PyrLitListNode* newPyrLitListNode(PyrParseNode *classname, PyrParseNode *elems); +PyrMultiAssignVarListNode* newPyrMultiAssignVarListNode(PyrSlotNode* varNames, + PyrSlotNode* rest); +PyrBlockNode* newPyrBlockNode(PyrArgListNode *arglist, PyrVarListNode *varlist, PyrParseNode *body, bool isTopLevel); + +void compilePyrSlotNode(PyrSlotNode* node, void *result); +void compilePyrClassNode(PyrClassNode* node, void *result); +void compilePyrClassExtNode(PyrClassExtNode* node, void *result); +void compilePyrMethodNode(PyrMethodNode* node, void *result); +void compilePyrArgListNode(PyrArgListNode* node, void *result); +void compilePyrVarListNode(PyrVarListNode* node, void *result); +void compilePyrVarDefNode(PyrVarDefNode* node, void *result); +void compilePyrCallNode(PyrCallNode* node, void *result); +void compilePyrBinopCallNode(PyrBinopCallNode* node, void *result); +void compilePyrPushLitNode(PyrPushLitNode* node, void *result); +void compilePyrLiteralNode(PyrLiteralNode* node, void *result); +void compilePyrReturnNode(PyrReturnNode* node, void *result); +void compilePyrBlockReturnNode(PyrBlockReturnNode* node, void *result); +void compilePyrAssignNode(PyrAssignNode* node, void *result); +void compilePyrSetterNode(PyrSetterNode* node, void* result); +void compilePyrMultiAssignNode(PyrMultiAssignNode* node, void *result); +void compilePyrMultiAssignVarListNode(PyrMultiAssignVarListNode* node, void *result); +void compilePyrDynDictNode(PyrDynDictNode* node, void *result); +void compilePyrDynListNode(PyrDynListNode* node, void *result); +void compilePyrLitListNode(PyrLitListNode* node, void *result); +void compilePyrBlockNode(PyrBlockNode* node, void *result); +void compilePyrPushNameNode(PyrPushNameNode* node, void *result); +void compilePyrDropNode(PyrDropNode* node, void *result); +void compilePyrPushKeyArgNode(PyrPushKeyArgNode* node, void *result); + +void dumpPyrSlotNode(PyrSlotNode* node, int level); +void dumpPyrClassNode(PyrClassNode* node, int level); +void dumpPyrClassExtNode(PyrClassExtNode* node, int level); +void dumpPyrMethodNode(PyrMethodNode* node, int level); +void dumpPyrArgListNode(PyrArgListNode* node, int level); +void dumpPyrVarListNode(PyrVarListNode* node, int level); +void dumpPyrVarDefNode(PyrVarDefNode* node, int level); +void dumpPyrCallNode(PyrCallNode* node, int level); +void dumpPyrBinopCallNode(PyrBinopCallNode* node, int level); +void dumpPyrPushLitNode(PyrPushLitNode* node, int level); +void dumpPyrLiteralNode(PyrLiteralNode* node, int level); +void dumpPyrReturnNode(PyrReturnNode* node, int level); +void dumpPyrBlockReturnNode(PyrBlockReturnNode* node, int level); +void dumpPyrAssignNode(PyrAssignNode* node, int level); +void dumpPyrSetterNode(PyrSetterNode* node, int level); +void dumpPyrMultiAssignNode(PyrMultiAssignNode* node, int level); +void dumpPyrMultiAssignVarListNode(PyrMultiAssignVarListNode* node, int level); +void dumpPyrDynDictNode(PyrDynDictNode* node, int level); +void dumpPyrDynListNode(PyrDynListNode* node, int level); +void dumpPyrLitListNode(PyrLitListNode* node, int level); +void dumpPyrBlockNode(PyrBlockNode* node, int level); +void dumpPyrPushNameNode(PyrPushNameNode* node, int level); +void dumpPyrPushKeyArgNode(PyrPushKeyArgNode* node, int level); +void dumpPyrDropNode(PyrDropNode* node, int level); + +PyrClass* getNodeSuperclass(PyrClassNode *node); +void countNodeMethods(PyrClassNode* node, int *numClassMethods, int *numInstMethods); +void compileExtNodeMethods(PyrClassExtNode* node); +void countVarDefs(PyrClassNode* node); +bool compareVarDefs(PyrClassNode* node, PyrClass* classobj); +void recompileSubclasses(PyrClass* classobj); +void compileNodeMethods(PyrClassNode* node); +void fillClassPrototypes(PyrClassNode *node, PyrClass *classobj, PyrClass *superclassobj); + +int nodeListLength(PyrParseNode *node); +bool isSuperObjNode(PyrParseNode *node); +bool isThisObjNode(PyrParseNode *node); +int conjureSelectorIndex(PyrParseNode *node, PyrBlock* func, + bool isSuper, PyrSymbol *selector, int *selType); +int conjureLiteralSlotIndex(PyrParseNode *node, PyrBlock* func, PyrSlot *slot); +bool findVarName(PyrBlock* func, PyrClass **classobj, PyrSymbol *name, + int *varType, int *level, int *index, PyrBlock** tempfunc); +void countClassVarDefs(PyrClassNode* node, int *numClassMethods, int *numInstMethods); +void compileNodeList(PyrParseNode *node); +void dumpNodeList(PyrParseNode *node); +int compareCallArgs(PyrMethodNode* node, PyrCallNode *cnode, int *varIndex); + +bool findSpecialClassName(PyrSymbol *className, int *index); +int getIndexType(PyrClassNode *classnode); + +void compileIfMsg(PyrCallNode* node); +void compileWhileMsg(PyrCallNode* node); +void compileLoopMsg(PyrCallNode* node); +void compileAndMsg(PyrParseNode* arg1, PyrParseNode* arg2); +void compileOrMsg(PyrParseNode* arg1, PyrParseNode* arg2); + +void compilePushInt(int value); +void compileAssignVar(PyrParseNode *node, PyrSymbol* varName, bool drop); +void compilePushVar(PyrParseNode *node, PyrSymbol *varName); +bool isAnInlineableBlock(PyrParseNode *node); +bool isWhileTrue(PyrParseNode *node); +void installByteCodes(PyrBlock *block); + +ByteCodes compileSubExpression(PyrPushLitNode* litnode); +ByteCodes compileSubExpressionWithGoto(PyrPushLitNode* litnode, int branchLen); +//ByteCodes compileDefaultValue(int litIndex, int realExprLen); + +void initParser(); +void finiParser(); +void initParserPool(); +void freeParserPool(); + +void initSpecialSelectors(); +void initSpecialClasses(); + +void nodePostErrorLine(PyrParseNode* node); + +PyrParseNode* linkNextNode(PyrParseNode* a, PyrParseNode* b); +PyrParseNode* linkAfterHead(PyrParseNode* a, PyrParseNode* b); + +extern int compileErrors; + +extern long zzval; +extern PyrSymbol *ps_newlist; +extern PyrSymbol *gSpecialUnarySelectors[opNumUnarySelectors]; +extern PyrSymbol *gSpecialBinarySelectors[opNumBinarySelectors]; +extern PyrSymbol *gSpecialSelectors[opmNumSpecialSelectors]; +extern PyrSymbol* gSpecialClasses[op_NumSpecialClasses]; + +extern PyrClass *gCurrentClass; +extern PyrClass *gCurrentMetaClass; +extern PyrClass *gCompilingClass; +extern PyrMethod *gCompilingMethod; +extern PyrBlock *gCompilingBlock; + +/* + compiling + "inlining" of special arithmetic opcodes. + inlining of IF, WHILE, AND, OR +*/ + +#endif diff --git a/sc4pd/headers/lang/PyrPrimitive.h b/sc4pd/headers/lang/PyrPrimitive.h new file mode 100755 index 0000000..4afe653 --- /dev/null +++ b/sc4pd/headers/lang/PyrPrimitive.h @@ -0,0 +1,42 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Functions for defining language primitives. + +*/ + +#ifndef _PYRPRIMITIVE_H_ +#define _PYRPRIMITIVE_H_ + +#include "PyrSlot.h" + +typedef int (*PrimitiveHandler)(struct VMGlobals *g, int numArgsPushed); +typedef int (*PrimitiveWithKeysHandler)(struct VMGlobals *g, int numArgsPushed, int numKeyArgsPushed); + +int nextPrimitiveIndex(); +int definePrimitive(int base, int index, char *name, PrimitiveHandler handler, int numArgs, int varArgs); +int definePrimitiveWithKeys(int base, int index, char *name, + PrimitiveHandler handler, PrimitiveWithKeysHandler keyhandler, + int numArgs, int varArgs); +int getPrimitiveNumArgs(int index); +PyrSymbol* getPrimitiveName(int index); + +#endif diff --git a/sc4pd/headers/lang/PyrPrimitiveProto.h b/sc4pd/headers/lang/PyrPrimitiveProto.h new file mode 100755 index 0000000..43464a4 --- /dev/null +++ b/sc4pd/headers/lang/PyrPrimitiveProto.h @@ -0,0 +1,81 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRPRIMITIVEPROTO_H_ +#define _PYRPRIMITIVEPROTO_H_ + +#include "PyrPrimitive.h" + +int basicNew(VMGlobals *g, int numArgsPushed); +int basicNewClear(VMGlobals *g, int numArgsPushed); +int basicSwap(VMGlobals *g, int numArgsPushed); +int instVarAt(VMGlobals *g, int numArgsPushed); +int instVarPut(VMGlobals *g, int numArgsPushed); +int instVarSize(VMGlobals *g, int numArgsPushed); +int objectHash(VMGlobals *g, int numArgsPushed); +int objectClass(VMGlobals *g, int numArgsPushed); +int blockValue(VMGlobals *g, int numArgsPushed); +int blockValueWithKeys(VMGlobals *g, int allArgsPushed, int numKeyArgsPushed); +int blockValueArray(VMGlobals *g, int numArgsPushed); +int blockSpawn(VMGlobals *g, int numArgsPushed); + +int objectIsKindOf(VMGlobals *g, int numArgsPushed); +int objectIsMemberOf(VMGlobals *g, int numArgsPushed); +int objectDump(VMGlobals *g, int numArgsPushed); +int haltInterpreter(VMGlobals *g, int numArgsPushed); +int objectIdentical(VMGlobals *g, int numArgsPushed); +int objectNotIdentical(VMGlobals *g, int numArgsPushed); +int objectPerform(VMGlobals *g, int numArgsPushed); +int objectPerformList(VMGlobals *g, int numArgsPushed); +int objectPerformSelList(VMGlobals *g, int numArgsPushed); +int undefinedPrimitive(VMGlobals *g, int numArgsPushed); + +int prObjectString(VMGlobals *g, int numArgsPushed); +int prClassString(VMGlobals *g, int numArgsPushed); +int prSymbolString(VMGlobals *g, int numArgsPushed); +int prSymbolClass(VMGlobals *g, int numArgsPushed); +int prPostString(VMGlobals *g, int numArgsPushed); +int prPostLine(VMGlobals *g, int numArgsPushed); +int prFlushPostBuf(VMGlobals *g, int numArgsPushed); + +int prPrimitiveError(VMGlobals *g, int numArgsPushed); +int prPrimitiveErrorString(VMGlobals *g, int numArgsPushed); +int prDumpStack(VMGlobals *g, int numArgsPushed); +int prDebugger(VMGlobals *g, int numArgsPushed); +int prPrimName(VMGlobals *g, int numArgsPushed); +int prObjectShallowCopy(VMGlobals *g, int numArgsPushed); +int prObjectCopyRange(VMGlobals *g, int numArgsPushed); +int prObjectPointsTo(VMGlobals *g, int numArgsPushed); +int prObjectRespondsTo(VMGlobals *g, int numArgsPushed); + +int prCompileString(VMGlobals *g, int numArgsPushed); +int prDumpBackTrace(VMGlobals *g, int numArgsPushed); +int prDumpByteCodes(VMGlobals *g, int numArgsPushed); +int prAllClasses(VMGlobals *g, int numArgsPushed); +int prPostClassTree(VMGlobals *g, int numArgsPushed); + +void initPrimitiveTable(); +void growPrimitiveTable(int newsize); + +void initPrimitives(); +void doPrimitive(VMGlobals* g, struct PyrMethod* meth, int numArgsPushed); +void doPrimitiveWithKeys(VMGlobals* g, struct PyrMethod* meth, int allArgsPushed, int numKeysPushed); + +#endif diff --git a/sc4pd/headers/lang/PyrSched.h b/sc4pd/headers/lang/PyrSched.h new file mode 100755 index 0000000..5102582 --- /dev/null +++ b/sc4pd/headers/lang/PyrSched.h @@ -0,0 +1,58 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PYRSCHED_H_ +#define _PYRSCHED_H_ + +#include "VMGlobals.h" +#include + +extern pthread_mutex_t gLangMutex; + +void schedInit(); +void schedCleanup(); + +void schedRun(); +void schedStop(); +void schedClear(); + +double elapsedTime(); +int64 OSCTime(); + +int64 ElapsedTimeToOSC(double elapsed); +double OSCToElapsedTime(int64 oscTime); + +void syncOSCOffsetWithTimeOfDay(); +void doubleToTimespec(double secs, struct timespec *spec); + + +bool addheap(VMGlobals *g, PyrObject *heap, double schedtime, PyrSlot *task); +bool lookheap(PyrObject *heap, double *schedtime, PyrSlot *task) ; +bool getheap(PyrObject *heap, double *schedtime, PyrSlot *task) ; +void offsetheap(VMGlobals *g, PyrObject *heap, double offset) ; +void dumpheap(PyrObject *heap); + +const double kSecondsToOSC = 4294967296.; // pow(2,32)/1 +const double kMicrosToOSC = 4294.967296; // pow(2,32)/1e6 +const double kNanosToOSC = 4.294967296; // pow(2,32)/1e9 +const double kOSCtoSecs = 2.328306436538696e-10; // 1/pow(2,32) +const double kOSCtoNanos = 0.2328306436538696; // 1e9/pow(2,32) + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/PyrSignal.h b/sc4pd/headers/lang/PyrSignal.h new file mode 100755 index 0000000..ee57b38 --- /dev/null +++ b/sc4pd/headers/lang/PyrSignal.h @@ -0,0 +1,417 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#pragma once on + +#include "PyrObject.h" +#include "GC.h" + +#define UNROLL 1 + +enum { + kSignalRate = 0, // index of rate slot + kSignalNextNode +}; + +#define FSINESIZE 8192. +#define SINESIZE 8192 +#define SINEMASK 8191 +#define VERY_BIG_FLOAT (1.e10) +extern float *sineCycle; +extern float *invSineCycle; +extern float *pmSineCycle; +extern double phaseToSineIndex; +extern double sineIndexToPhase; + +//#define FRACTABLESIZE 4096 +//#define FRACMASK 0x3FFC +//extern float *gFracTable; + + +PyrObject* newPyrSignal(VMGlobals *g, long size); + +#if 0 +#define UNROLL8_CODE(size,var,stmt) \ + endptr = var + size; \ + switch (size & 7) { \ + while (var < endptr) { \ + stmt; \ + case 7 : stmt; \ + case 6 : stmt; \ + case 5 : stmt; \ + case 4 : stmt; \ + case 3 : stmt; \ + case 2 : stmt; \ + case 1 : stmt; \ + case 0 : ; \ + } \ + } +#else +#define UNROLL8_CODE(size,var,stmt) \ + { int tempi, tempend; \ + tempend = size>>3; \ + for (tempi=0; tempi>2; \ + for (tempi=0; tempi>2; \ + for (tempi=0; tempislots) - 1; \ + b = (float*)(inb->slots) - 1; \ + size = sc_min(ina->size, inb->size); \ + outc = newPyrSignal(g, size); \ + c = (float*)(outc->slots) - 1; \ + endptr = c + size; \ + switch (size & 3) { \ + while (c < endptr) { \ + *++c = *++a OP *++b; \ + case 3 : *++c = *++a OP *++b; \ + case 2 : *++c = *++a OP *++b; \ + case 1 : *++c = *++a OP *++b; \ + case 0 : ; \ + } \ + } \ + return outc; \ + + +#define BINOP_LOOP2(STMT1) \ + float *a, *b, *c, *endptr; \ + PyrObject *outc; \ + long size; \ + a = (float*)(ina->slots) - 1; \ + b = (float*)(inb->slots) - 1; \ + size = sc_min(ina->size, inb->size); \ + outc = newPyrSignal(g, size); \ + c = (float*)(outc->slots) - 1; \ + endptr = c + size; \ + switch (size & 3) { \ + while (c < endptr) { \ + STMT1; \ + case 3 :STMT1; \ + case 2 :STMT1; \ + case 1 :STMT1; \ + case 0 : ; \ + } \ + } \ + return outc; \ + +#endif + +/* + compound formulas : + amclip out = B<=0 ? 0 : A*B; // two quadrant amplitude modulation + ring1 out = A*(B+1) = A*B + A; // amplitude modulation of a by b. + ring2 out = A*B + A + B; // ring modulation plus both original signals + ring3 out = A*A*B; // ring modulation variant + ring4 out = A*A*B - A*B*B; // ring modulation variant + difsqr out = A*A - B*B; // difference of squares + sumsqr out = A*A + B*B; // sum of squares + sqrdif out = (A - B)^2 // square of the difference = a^2 + b^2 - 2ab + sqrsum out = (A + B)^2 // square of the sum = a^2 + b^2 + 2ab +*/ + +void signal_init_globs(); +PyrObject* signal_fill(PyrObject *outSignal, float inValue); +PyrObject* signal_scale(PyrObject *outSignal, float inValue); +PyrObject* signal_offset(PyrObject *outSignal, float inValue); +PyrObject* signal_scale_offset(PyrObject *outSignal, float mul, float add); +PyrObject* signal_mix(PyrObject* ina, PyrObject* inb, float start, float end, float slopeFactor); +PyrObject* signal_add_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sub_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_mul_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_mul_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_add_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sub_ds_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring1_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring3_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_ring4_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_thresh_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_amclip_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_div_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_difsqr_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sumsqr_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sqrsum_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_sqrdif_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_add_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sub_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_mul_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring1_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring3_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring4_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_thresh_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_amclip_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_div_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_difsqr_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sumsqr_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sqrsum_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_sqrdif_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_ring1_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_ring2_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_ring3_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_ring4_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_thresh_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_amclip_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sub_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_div_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_difsqr_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sumsqr_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sqrsum_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_sqrdif_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_min_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_max_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_min_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_max_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_invert(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_recip(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_squared(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_cubed(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_abs(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sign(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_negative(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_positive(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_strictly_positive(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_nyqring(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_clip_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_clip_f_ds(PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_clip_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc); +PyrObject* signal_wrap_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_wrap_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc); +PyrObject* signal_fold_f(VMGlobals *g, PyrObject *inPyrSignal, float lo, float hi); +PyrObject* signal_fold_x(VMGlobals *g, PyrObject *ina, PyrObject *inb, PyrObject *inc); +PyrObject* signal_log(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_log2(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_log10(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sin(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_cos(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_tan(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sinh(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_cosh(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_tanh(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_asin(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_acos(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_atan(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_exp(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_sqrt(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_distort(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_distortneg(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_softclip(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_softclipneg(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_fsin(VMGlobals *g, PyrObject *inPyrSignal); +PyrObject* signal_poly3(VMGlobals *g, PyrObject *inPyrSignal, float a, float b, float c); +PyrObject* signal_poly3r(VMGlobals *g, PyrObject *inPyrSignal, + float a1, float a2, float b1, float b2, float c1, float c2, float slopeFactor); +PyrObject* signal_integrate(VMGlobals *g, PyrObject *inPyrSignal, float *ioSum); +PyrObject* signal_leakdc(VMGlobals *g, PyrObject *inPyrSignal, float *ioDC, float leakFactor); +PyrObject* signal_ampflw1(VMGlobals *g, PyrObject *inPyrSignal, float *ioAmp, float leak1); +PyrObject* signal_ampflw2(VMGlobals *g, PyrObject *inPyrSignal, float *ioAmp, float leak1); +PyrObject* signal_differentiate(VMGlobals *g, PyrObject *inPyrSignal, float *ioPrev); +PyrObject* signal_rotate(VMGlobals *g, PyrObject* ina, int rot); +PyrObject* signal_reverse_ds(PyrObject* ina); +PyrObject* signal_cat(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_insert(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index); +PyrObject* signal_overdub(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index); +PyrObject* signal_overwrite(VMGlobals *g, PyrObject* ina, PyrObject* inb, long index); +PyrObject* signal_cat3(VMGlobals *g, PyrObject* ina, PyrObject* inb, PyrObject* inc); +PyrObject* signal_linen(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp); +PyrObject* signal_linen2(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp, float midamp); +PyrObject* signal_writesplice(VMGlobals *g, PyrObject* outc, PyrObject* ina, PyrObject* inb, + long indexc, long indexa, long indexb, long fadelen, float midamp); +PyrObject* signal_splice(VMGlobals *g, PyrObject* ina, PyrObject* inb, + long indexa, long indexb, long fadelen, float midamp); + +PyrObject* signal_invert_ds(PyrObject *inPyrSignal); +PyrObject* signal_recip_ds(PyrObject *inPyrSignal); +PyrObject* signal_squared_ds(PyrObject *inPyrSignal); +PyrObject* signal_cubed_ds(PyrObject *inPyrSignal); +PyrObject* signal_abs_ds(PyrObject *inPyrSignal); +PyrObject* signal_sign_ds(PyrObject *inPyrSignal); +PyrObject* signal_negative_ds(PyrObject *inPyrSignal); +PyrObject* signal_positive_ds(PyrObject *inPyrSignal); +PyrObject* signal_strictly_positive_ds(PyrObject *inPyrSignal); +PyrObject* signal_nyqring_ds(PyrObject *inPyrSignal); + +PyrObject* signal_clipneg_ds(PyrObject *inPyrSignal); +PyrObject* signal_distort_ds(PyrObject *inPyrSignal); +PyrObject* signal_distortneg_ds(PyrObject *inPyrSignal); +PyrObject* signal_softclip_ds(PyrObject *inPyrSignal); +PyrObject* signal_softclipneg_ds(PyrObject *inPyrSignal); +PyrObject* signal_fsin_ds(PyrObject *inPyrSignal); + +PyrObject* signal_log_ds(PyrObject *inPyrSignal); +PyrObject* signal_log2_ds(PyrObject *inPyrSignal); +PyrObject* signal_log10_ds(PyrObject *inPyrSignal); +PyrObject* signal_sin_ds(PyrObject *inPyrSignal); +PyrObject* signal_cos_ds(PyrObject *inPyrSignal); +PyrObject* signal_tan_ds(PyrObject *inPyrSignal); +PyrObject* signal_sinh_ds(PyrObject *inPyrSignal); +PyrObject* signal_cosh_ds(PyrObject *inPyrSignal); +PyrObject* signal_tanh_ds(PyrObject *inPyrSignal); +PyrObject* signal_asin_ds(PyrObject *inPyrSignal); +PyrObject* signal_acos_ds(PyrObject *inPyrSignal); +PyrObject* signal_atan_ds(PyrObject *inPyrSignal); +PyrObject* signal_exp_ds(PyrObject *inPyrSignal); +PyrObject* signal_sqrt_ds(PyrObject *inPyrSignal); + +float signal_findpeak(PyrObject *inPyrSignal); +PyrObject* signal_normalize(PyrObject *inPyrSignal); +PyrObject* signal_normalize_transfer_fn(PyrObject *inPyrSignal); +float signal_integral(PyrObject *inPyrSignal); +PyrObject* signal_combself(VMGlobals *g, PyrObject* ina, long rot); +PyrObject* signal_bilinen(VMGlobals *g, PyrObject* ina, long atk, long dcy, float amp, float midamp); +PyrObject* signal_lace2(VMGlobals *g, PyrObject* ina, PyrObject* inb); +void signal_unlace2(VMGlobals *g, PyrObject* ina, PyrObject** outb, PyrObject** outc); +void signal_convolve(VMGlobals *g, PyrObject* ina, PyrObject* ir, PyrObject* previn, long *ppos); +PyrObject* signal_thumbnail(VMGlobals *g, PyrObject* ina, long startpos, long length, int binsize); + +PyrObject* signal_scaleneg_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_scaleneg_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_scaleneg_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_clip2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_clip2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_clip2_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_fold2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_fold2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_fold2_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_wrap2_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_wrap2_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_wrap2_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_excess_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); +PyrObject* signal_excess_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_excess_fx(VMGlobals *g, float ina, PyrObject* inb); + +PyrObject* signal_absdif_fx(VMGlobals *g, float ina, PyrObject* inb); +PyrObject* signal_absdif_xf(VMGlobals *g, PyrObject* ina, float inb); +PyrObject* signal_absdif_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); + +bool signal_equal_xf(VMGlobals *g, PyrObject* ina, float inb); +bool signal_equal_xx(VMGlobals *g, PyrObject* ina, PyrObject* inb); + +void signal_get_bounds(PyrObject* ina, float *ominval, float *omaxval); + +void signal_smooth_ds(PyrObject* inPyrSignal); +void signal_hanning_ds(PyrObject* inPyrSignal); +void signal_welch_ds(PyrObject* inPyrSignal); +void signal_parzen_ds(PyrObject* inPyrSignal); + +PyrObject* signal_normalize_range(PyrObject* ina, long start, long end); +PyrObject* signal_zero_range(PyrObject* ina, long start, long end); +PyrObject* signal_invert_range(PyrObject* ina, long start, long end); +PyrObject* signal_reverse_range(PyrObject* ina, long start, long end); +PyrObject* signal_fade_in(PyrObject* ina, long start, long end); +PyrObject* signal_fade_out(PyrObject* ina, long start, long end); +PyrObject* signal_abs_range(PyrObject* ina, long start, long end); +PyrObject* signal_squared_range(PyrObject* ina, long start, long end); +PyrObject* signal_cubed_range(PyrObject* ina, long start, long end); +PyrObject* signal_distort_range(PyrObject* ina, long start, long end); + +PyrObject* signal_fade_range(PyrObject* ina, long start, long end, float lvl0, float lvl1); diff --git a/sc4pd/headers/lang/PyrSignalPrim.h b/sc4pd/headers/lang/PyrSignalPrim.h new file mode 100755 index 0000000..bea68ca --- /dev/null +++ b/sc4pd/headers/lang/PyrSignalPrim.h @@ -0,0 +1,56 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _PYRSIGNALPRIM_H_ +#define _PYRSIGNALPRIM_H_ + +extern PyrSymbol *s_wavetable; +extern struct PyrClass *class_wavetable; + +void initSignalPrimitives(); + +int prSignalCat(VMGlobals *g, int numArgsPushed); +int prSignalFill(VMGlobals *g, int numArgsPushed); +int prSignalRamp(VMGlobals *g, int numArgsPushed); +int prSignalScale(VMGlobals *g, int numArgsPushed); +int prSignalOffset(VMGlobals *g, int numArgsPushed); +int prSignalString(VMGlobals *g, int numArgsPushed); + +int prSignalPeak(VMGlobals *g, int numArgsPushed); +int prSignalNormalize(VMGlobals *g, int numArgsPushed); +int prSignalNormalizeTransferFn(VMGlobals *g, int numArgsPushed); +int prSignalIntegral(VMGlobals *g, int numArgsPushed); + +int prSignalOverDub(VMGlobals *g, int numArgsPushed); +int prSignalOverWrite(VMGlobals *g, int numArgsPushed); +int prSignalFade(VMGlobals *g, int numArgsPushed); +int prSignalAddHarmonic(VMGlobals *g, int numArgsPushed); +int prSignalAsWavetable(VMGlobals *g, int numArgsPushed); +int prWavetableAsSignal(VMGlobals *g, int numArgsPushed); + +int prSignalInvert(VMGlobals *g, int numArgsPushed); +int prSignalReverse(VMGlobals *g, int numArgsPushed); +int prSignalRotate(VMGlobals *g, int numArgsPushed); + +void signalAsWavetable(float *signal, float *wavetable, int size); +void wavetableAsSignal(float *wavetable, float *signal, int size); + +#endif diff --git a/sc4pd/headers/lang/PyrSlot.h b/sc4pd/headers/lang/PyrSlot.h new file mode 100755 index 0000000..78bcd12 --- /dev/null +++ b/sc4pd/headers/lang/PyrSlot.h @@ -0,0 +1,286 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +PyrSlot is a value holder for SC variables. +A PyrSlot is an 8-byte value which is either a double precision float or a +32-bit tag plus a 32-bit value. + +*/ + +#ifndef _PYRSLOT_H_ +#define _PYRSLOT_H_ + +#include "SC_Endian.h" +#include "PyrSymbol.h" + +/* + Pyrite slots are the size of an 8 byte double. If the upper bits + indicate that the double is a 'Not-A-Number' then the upper 32 + bits are used as a tag to indicate one of a number of other types + whose data is in the lower 32 bits. +*/ + +/* some DSPs like the TIC32 do not support 8 byte doubles */ +/* on such CPUs, set DOUBLESLOTS to zero */ + +#define DOUBLESLOTS 1 + +/* use the high order bits of an IEEE double NaN as a tag */ +enum { + tagObj = 0x7FF90001, + tagHFrame = 0x7FF90002, + tagSFrame = 0x7FF90003, + tagInt = 0x7FF90004, + tagSym = 0x7FF90005, + tagChar = 0x7FF90006, + tagNil = 0x7FF90007, // nil, false, and true are indicated by the tag alone. + tagFalse = 0x7FF90008, // the lower 32 bits are zero. + tagTrue = 0x7FF90009, + tagInf = 0x7FF9000A, + tagPtr = 0x7FF9000B, + /* anything else is a double */ + tagUnused = 0x7FF9000E + + +#if !DOUBLESLOTS + ,tagFloat = 0x7FF9000F /* used only to initialized 4 byte float tags, never compared with */ +#endif +}; + +struct RGBColor8 { + unsigned char c[4]; +}; + +typedef union pyrslot { + double f; + struct { +#if BYTE_ORDER == BIG_ENDIAN + int tag; +#endif // BIG_ENDIAN + union { + int c; /* char */ + int i; + float f; + void *ptr; + struct RGBColor8 r; + struct PyrObject *o; + PyrSymbol *s; + struct PyrMethod *om; + struct PyrBlock *oblk; + struct PyrClass *oc; + struct PyrFrame *of; + struct PyrList *ol; + struct PyrString *os; + struct PyrInt8Array *ob; + struct PyrDoubleArray *od; + struct PyrSymbolArray *osym; + struct PyrParseNode *opn; + struct PyrProcess *op; + struct PyrThread *ot; + struct PyrInterpreter *oi; + struct PyrPlug *plug; + } u; +#if BYTE_ORDER == LITTLE_ENDIAN + // need to swap on intel + int tag; +#endif // LITTLE_ENDIAN + } s; +} PyrSlot; + +/* + these are some defines to make accessing the structure less verbose. + obviously it polutes the namespace of identifiers beginning with 'u'. +*/ +#define utag s.tag +//int +#define ui s.u.i +//PyrObject +#define uo s.u.o +//PyrSymbol +#define us s.u.s +//RGBColor8 +#define ur s.u.r +#define uc s.u.c +#define uoc s.u.oc +#define uof s.u.of +#define uol s.u.ol +#define uod s.u.od +#define uob s.u.ob +#define uop s.u.op +#define uoi s.u.oi +#define uod s.u.od +//string +#define uos s.u.os +#define uot s.u.ot +//method +#define uom s.u.om +//symbol array +#define uosym s.u.osym +#define uoblk s.u.oblk +#define uopn s.u.opn +#define uptr s.u.ptr +#define uplug s.u.plug + +#if DOUBLESLOTS +#define uf f +#else +#define uf s.u.f +#endif + +#define ucopy f + +/* + Note that on the PowerPC, the fastest way to copy a slot is to + copy the double field, not the struct. +*/ + +/* some macros for setting values of slots */ +inline void SetInt(PyrSlot* slot, int val) { (slot)->utag = tagInt; (slot)->ui = (val); } +inline void SetObject(PyrSlot* slot, void* val) { (slot)->utag = tagObj; (slot)->uo = (PyrObject*)(val); } +inline void SetSymbol(PyrSlot* slot, PyrSymbol *val) { (slot)->utag = tagSym; (slot)->us = (val); } +inline void SetChar(PyrSlot* slot, char val) { (slot)->utag = tagChar; (slot)->uc = (val); } +inline void SetPtr(PyrSlot* slot, void* val) { (slot)->utag = tagPtr; (slot)->uptr = (void*)(val); } +inline void SetObjectOrNil(PyrSlot* slot, PyrObject* val) +{ + if (val) { + (slot)->utag = tagObj; + (slot)->uo = (val); + } else { + (slot)->utag = tagNil; + (slot)->ui = 0; + } +} + +inline void SetTrue(PyrSlot* slot) { (slot)->utag = tagTrue; (slot)->ui = 0; } +inline void SetFalse(PyrSlot* slot) { (slot)->utag = tagFalse; (slot)->ui = 0; } +inline void SetBool(PyrSlot* slot, bool test) { (slot)->utag = ((test) ? tagTrue : tagFalse); (slot)->ui = 0; } +inline void SetNil(PyrSlot* slot) { (slot)->utag = tagNil; (slot)->ui = 0; } +inline void SetInf(PyrSlot* slot) { (slot)->utag = tagInf; (slot)->ui = 0; } + +#if DOUBLESLOTS +inline void SetFloat(PyrSlot* slot, double val) { (slot)->uf = (val); } +#else +inline void SetFloat(PyrSlot* slot, double val) { (slot)->utag = s_float; (slot)->uf = (val); } +#endif + +inline bool IsObj(PyrSlot* slot) { return ((slot)->utag == tagObj); } +inline bool NotObj(PyrSlot* slot) { return ((slot)->utag != tagObj); } + +inline bool IsNil(PyrSlot* slot) { return ((slot)->utag == tagNil); } +inline bool NotNil(PyrSlot* slot) { return ((slot)->utag != tagNil); } + +inline bool IsFalse(PyrSlot* slot) { return ((slot)->utag == tagFalse); } +inline bool IsTrue(PyrSlot* slot) { return ((slot)->utag == tagTrue); } + +inline bool SlotEq(PyrSlot* a, PyrSlot* b) { return ((a)->ui == (b)->ui && (a)->utag == (b)->utag); } + +inline bool IsSym(PyrSlot* slot) { return ((slot)->utag == tagSym); } +inline bool NotSym(PyrSlot* slot) { return ((slot)->utag != tagSym); } + +inline bool IsInt(PyrSlot* slot) { return ((slot)->utag == tagInt); } +inline bool NotInt(PyrSlot* slot) { return ((slot)->utag != tagInt); } + +inline bool IsFloatTag(int tag) { return ((tag & 0xFFFFFFF0) != 0x7FF90000); } +inline bool IsFloat(PyrSlot* slot) { return (((slot)->utag & 0xFFFFFFF0) != 0x7FF90000); } +inline bool NotFloat(PyrSlot* slot) { return (((slot)->utag & 0xFFFFFFF0) == 0x7FF90000); } + +inline bool IsInf(PyrSlot* slot) { return ((slot)->utag == tagInf); } +inline bool IsPtr(PyrSlot* slot) { return ((slot)->utag == tagPtr); } + +inline bool IsFrame(PyrSlot* slot) { return ((slot)->utag == tagHFrame || (slot)->utag == tagSFrame); } + + +void dumpPyrSlot(PyrSlot* slot); +void slotString(PyrSlot *slot, char *str); +void slotOneWord(PyrSlot *slot, char *str); +bool postString(PyrSlot *slot, char *str); +char *slotSymString(PyrSlot* slot); +int asCompileString(PyrSlot *slot, char *str); + +int slotIntVal(PyrSlot* slot, int *value); +int slotFloatVal(PyrSlot* slot, float *value); +int slotDoubleVal(PyrSlot *slot, double *value); +int slotStrVal(PyrSlot *slot, char *str, int maxlen); +int slotPStrVal(PyrSlot *slot, unsigned char *str); +int slotSymbolVal(PyrSlot *slot, PyrSymbol **symbol); + +extern PyrSlot o_nil, o_true, o_false, o_inf; +extern PyrSlot o_pi, o_twopi; +extern PyrSlot o_fhalf, o_fnegone, o_fzero, o_fone, o_ftwo; +extern PyrSlot o_negtwo, o_negone, o_zero, o_one, o_two; +extern PyrSlot o_emptyarray, o_onenilarray, o_argnamethis; + +extern PyrSymbol *s_object; // "Object" +extern PyrSymbol *s_this; // "this" +extern PyrSymbol *s_super; // "super" + +inline int slotFloatVal(PyrSlot *slot, float *value) +{ + if (IsFloat(slot)) { + *value = slot->uf; + return errNone; + } else if (IsInt(slot)) { + *value = slot->ui; + return errNone; + } + return errWrongType; +} + +inline int slotIntVal(PyrSlot *slot, int *value) +{ + if (IsInt(slot)) { + *value = slot->ui; + return errNone; + } else if (IsFloat(slot)) { + *value = (int)slot->uf; + return errNone; + } + return errWrongType; +} + +inline int slotDoubleVal(PyrSlot *slot, double *value) +{ + if (IsFloat(slot)) { + *value = slot->uf; + return errNone; + } else if (IsInt(slot)) { + *value = slot->ui; + return errNone; + } + return errWrongType; +} + +inline int slotSymbolVal(PyrSlot *slot, PyrSymbol **symbol) +{ + if (!IsSym(slot)) return errWrongType; + *symbol = slot->us; + return errNone; +} + +inline void slotCopy(PyrSlot *dst, PyrSlot *src, int num) +{ + double *dstp = (double*)dst - 1; + double *srcp = (double*)src - 1; + for (int i=0;i +#include + +template +class SC_IOStream +{ +protected: + T s; +public: + SC_IOStream() : s(0) {} + SC_IOStream(T inStream) : s(inStream) {} + + void SetStream(T inStream) { s = inStream; } + T GetStream() { return s; } + + // core routines + void readData(char *data, int size); + uint8 readUInt8(); + + void writeData(char *data, int size); + void writeUInt8(uint8 inInt); + + // built using core routines + void writeInt8(int8 inInt) + { + writeUInt8((uint8)inInt); + } + + void writeInt16_be(int16 inInt) + { + writeUInt8((uint8)(inInt >> 8)); + writeUInt8(inInt); + } + + void writeInt16_le(int16 inInt) + { + writeUInt8((uint8)inInt); + writeUInt8((uint8)(inInt >> 8)); + } + + void writeInt32_be(int32 inInt) + { + writeUInt8((uint8)(inInt >> 24)); + writeUInt8((uint8)(inInt >> 16)); + writeUInt8((uint8)(inInt >> 8)); + writeUInt8((uint8)inInt); + } + + void writeInt32_le(int32 inInt) + { + writeUInt8((uint8)inInt); + writeUInt8((uint8)(inInt >> 8)); + writeUInt8((uint8)(inInt >> 16)); + writeUInt8((uint8)(inInt >> 24)); + } + +#if BYTE_ORDER == BIG_ENDIAN + void writeFloat_be(float inFloat) +#else + void writeFloat_le(float inFloat) +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.f = inFloat; + writeUInt8(u.c[0]); + writeUInt8(u.c[1]); + writeUInt8(u.c[2]); + writeUInt8(u.c[3]); + } + +#if BYTE_ORDER == BIG_ENDIAN + void writeFloat_le(float inFloat) +#else + void writeFloat_be(float inFloat) +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.f = inFloat; + writeUInt8(u.c[3]); + writeUInt8(u.c[2]); + writeUInt8(u.c[1]); + writeUInt8(u.c[0]); + } + + +#if BYTE_ORDER == BIG_ENDIAN + void writeDouble_be(double inDouble) +#else + void writeDouble_le(double inDouble) +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.f = inDouble; + writeUInt8(u.c[0]); + writeUInt8(u.c[1]); + writeUInt8(u.c[2]); + writeUInt8(u.c[3]); + writeUInt8(u.c[4]); + writeUInt8(u.c[5]); + writeUInt8(u.c[6]); + writeUInt8(u.c[7]); + } + +#if BYTE_ORDER == BIG_ENDIAN + void writeDouble_le(double inDouble) +#else + void writeDouble_be(double inDouble) +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.f = inDouble; + writeUInt8(u.c[7]); + writeUInt8(u.c[6]); + writeUInt8(u.c[5]); + writeUInt8(u.c[4]); + writeUInt8(u.c[3]); + writeUInt8(u.c[2]); + writeUInt8(u.c[1]); + writeUInt8(u.c[0]); + } + + + int8 readInt8() + { + return (int8)readUInt8(); + } + + int16 readInt16_be() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + return (int16)((a << 8) | b); + } + + int16 readInt16_le() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + return (int16)((b << 8) | a); + } + + int32 readInt32_be() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + uint8 c = readUInt8(); + uint8 d = readUInt8(); + return (int32)((a << 24) | (b << 16) | (c << 8) | d); + } + + int32 readInt32_le() + { + uint8 a = readUInt8(); + uint8 b = readUInt8(); + uint8 c = readUInt8(); + uint8 d = readUInt8(); + return (int32)((d << 24) | (c << 16) | (b << 8) | a); + } + +#if BYTE_ORDER == BIG_ENDIAN + float readFloat_be() +#else + float readFloat_le() +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.c[0] = readUInt8(); + u.c[1] = readUInt8(); + u.c[2] = readUInt8(); + u.c[3] = readUInt8(); + return u.f; + } + +#if BYTE_ORDER == BIG_ENDIAN + float readFloat_le() +#else + float readFloat_be() +#endif + { + union { + float f; + uint8 c[4]; + } u; + u.c[3] = readUInt8(); + u.c[2] = readUInt8(); + u.c[1] = readUInt8(); + u.c[0] = readUInt8(); + return u.f; + } + + +#if BYTE_ORDER == BIG_ENDIAN + double readDouble_be() +#else + double readDouble_le() +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.c[0] = readUInt8(); + u.c[1] = readUInt8(); + u.c[2] = readUInt8(); + u.c[3] = readUInt8(); + u.c[4] = readUInt8(); + u.c[5] = readUInt8(); + u.c[6] = readUInt8(); + u.c[7] = readUInt8(); + return u.f; + } + +#if BYTE_ORDER == BIG_ENDIAN + double readDouble_le() +#else + double readDouble_be() +#endif + { + union { + double f; + uint8 c[8]; + } u; + u.c[7] = readUInt8(); + u.c[6] = readUInt8(); + u.c[5] = readUInt8(); + u.c[4] = readUInt8(); + u.c[3] = readUInt8(); + u.c[2] = readUInt8(); + u.c[1] = readUInt8(); + u.c[0] = readUInt8(); + return u.f; + } + + void readSymbol(char *outString) + { + int length = readUInt8(); + readData(outString, length); + outString[length] = 0; + } + + void writeSymbol(char *inString) + { + int32 length = strlen(inString); + writeUInt8((uint8)length); + writeData(inString, length); + } +}; + + +// core routines +inline void SC_IOStream::readData(char *data, int size) +{ + fread(data, 1, size, s); +} + +inline uint8 SC_IOStream::readUInt8() +{ + return (uint8)fgetc(s); +} + +inline void SC_IOStream::writeData(char *data, int size) +{ + fwrite(data, 1, size, s); +} + +inline void SC_IOStream::writeUInt8(uint8 inInt) +{ + fputc(inInt, s); +} + +// core routines +inline void SC_IOStream::readData(char *data, int size) +{ + memcpy(data, s, size); + s += size; +} +inline uint8 SC_IOStream::readUInt8() +{ + return (uint8)*s++; +} + +inline void SC_IOStream::writeData(char *data, int size) +{ + memcpy(s, data, size); + s += size; +} + +inline void SC_IOStream::writeUInt8(uint8 inInt) +{ + *s++ = (inInt & 255); +} + + +#endif + diff --git a/sc4pd/headers/lang/SCBase.h b/sc4pd/headers/lang/SCBase.h new file mode 100755 index 0000000..10fe0ed --- /dev/null +++ b/sc4pd/headers/lang/SCBase.h @@ -0,0 +1,68 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Contains the most common definitions. + +*/ + +#ifndef _SCBASE_ +#define _SCBASE_ + +#include +#include + +#include "SC_BoundsMacros.h" +#include "SC_Types.h" +#include "PyrErrors.h" +#include "AllocPools.h" + +void postfl(const char *fmt, ...); +void post(const char *fmt, ...); +void error(const char *fmt, ...); +void postText(const char *text, long length); +void postChar(char c); +void flushPostBuf(); +void setPostFile(FILE *file); // If file is not NULL, causes all posted text to also be written to the file. + +void debugf(char *fmt, ...); +void pprintf(unsigned char *str, char *fmt, ...); + +#pragma export on + +extern "C" { +void schedInit(); +void init_OSC(int port); +bool pyr_init_mem_pools(int runtime_space, int runtime_grow); + +void schedRun(); +void schedStop(); +bool compileLibrary(); +void runLibrary(struct PyrSymbol* selector); +struct VMGlobals* scGlobals(); +void runInterpreter(struct VMGlobals *g, struct PyrSymbol *selector, int numArgsPushed); + +struct PyrSymbol* getsym(const char *inName); +struct PyrSymbol* findsym(const char *name); +} + +#pragma export off + +#endif diff --git a/sc4pd/headers/lang/SC_ComPort.h b/sc4pd/headers/lang/SC_ComPort.h new file mode 100755 index 0000000..bdbeabc --- /dev/null +++ b/sc4pd/headers/lang/SC_ComPort.h @@ -0,0 +1,118 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_ComPort_ +#define _SC_ComPort_ + +#include +#include +#include "SC_Msg.h" +#include "SC_Sem.h" + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_CmdPort +{ +protected: + pthread_t mThread; + + void Start(); + virtual ReplyFunc GetReplyFunc()=0; +public: + SC_CmdPort(); + + virtual void* Run()=0; +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_ComPort : public SC_CmdPort +{ +protected: + int mPortNum; + int mSocket; + struct sockaddr_in mBindSockAddr; + +public: + SC_ComPort(int inPortNum); + virtual ~SC_ComPort(); + + int Socket() { return mSocket; } + + int PortNum() const { return mPortNum; } +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_UdpInPort : public SC_ComPort +{ +protected: + struct sockaddr_in mReplySockAddr; + virtual ReplyFunc GetReplyFunc(); + +public: + SC_UdpInPort(int inPortNum); + ~SC_UdpInPort(); + + int PortNum() const { return mPortNum; } + + void* Run(); +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpInPort : public SC_ComPort +{ + SC_Semaphore mConnectionAvailable; + int mBacklog; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpInPort(int inPortNum, int inMaxConnections, int inBacklog); + + virtual void* Run(); + + void ConnectionTerminated(); +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpConnectionPort : public SC_ComPort +{ + SC_TcpInPort *mParent; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpConnectionPort(SC_TcpInPort *inParent, int inSocket); + virtual ~SC_TcpConnectionPort(); + + virtual void* Run(); +}; + +const int kTextBufSize = 8192; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/lang/SC_LanguageClient.h b/sc4pd/headers/lang/SC_LanguageClient.h new file mode 100644 index 0000000..b7a499c --- /dev/null +++ b/sc4pd/headers/lang/SC_LanguageClient.h @@ -0,0 +1,164 @@ +// emacs: -*- c++ -*- +// file: SC_LanguageClient.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_LanguageClient.h,v 1.1.1.1 2004-07-14 16:21:17 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_LANGUAGECLIENT_H_INCLUDED +#define SC_LANGUAGECLIENT_H_INCLUDED + +#include "SC_StringBuffer.h" +#include +#include +#include + +// ===================================================================== +// SC_LanguageClient - abstract sclang client. +// ===================================================================== + +struct PyrSymbol; +struct VMGlobals; + +extern long compiledOK; +extern pthread_mutex_t gLangMutex; +extern VMGlobals* gMainVMGlobals; + +class SC_LanguageClient +{ +public: + struct Options + { + Options() + : mMemSpace(2*1024*1024), + mMemGrow(256*1024), + mPort(57120), + mRuntimeDir(0) + { } + + int mMemSpace; // memory space in bytes + int mMemGrow; // memory growth in bytes + int mPort; // network port number + char* mRuntimeDir; // runtime directory + }; + +public: + // create singleton instance + SC_LanguageClient(const char* name); + virtual ~SC_LanguageClient(); + + // return the singleton instance + static SC_LanguageClient* instance() { return gInstance; } + + // initialize language runtime + void initRuntime(const Options& opt=Options()); + + // return application name + const char* getName() const { return mName; } + + // library startup/shutdown + bool readLibraryConfig(const char* filePath, const char* fileName=0); + bool readDefaultLibraryConfig(); + bool isLibraryCompiled() { return compiledOK; } + void compileLibrary(); + void shutdownLibrary(); + void recompileLibrary(); + + // interpreter access + void lock() { pthread_mutex_lock(&gLangMutex); } + bool trylock() { return pthread_mutex_trylock(&gLangMutex) == 0; } + void unlock() { pthread_mutex_unlock(&gLangMutex); } + + VMGlobals* getVMGlobals() { return gMainVMGlobals; } + + void setCmdLine(const char* buf, size_t size); + void setCmdLine(const char* str); + void setCmdLine(const SC_StringBuffer& strBuf); + void setCmdLinef(const char* fmt, ...); + void runLibrary(PyrSymbol* pyrSymbol); + void runLibrary(const char* methodName); + void interpretCmdLine() { runLibrary(s_interpretCmdLine); } + void interpretPrintCmdLine() { runLibrary(s_interpretPrintCmdLine); } + void executeFile(const char* fileName); + void runMain() { runLibrary(s_run); } + void stopMain() { runLibrary(s_stop); } + + // post file access + FILE* getPostFile() { return mPostFile; } + void setPostFile(FILE* file) { mPostFile = file; } + + // post buffer output (subclass responsibility) + // these routines should be thread-save. + virtual void post(const char *fmt, va_list ap, bool error) = 0; + virtual void post(char c) = 0; + virtual void post(const char* str, size_t len) = 0; + virtual void flush() = 0; + + // common symbols + // only valid after the library has been compiled. + static PyrSymbol* s_interpretCmdLine; + static PyrSymbol* s_interpretPrintCmdLine; + static PyrSymbol* s_run; + static PyrSymbol* s_stop; + + // command line argument handling utilities + static void snprintMemArg(char* dst, size_t size, int arg); + static bool parseMemArg(const char* arg, int* res); + static bool parsePortArg(const char* arg, int* res); + +protected: + // AppClock driver + // to be called from client mainloop. + void tick(); + + // language notifications, subclasses can override + + // called after language runtime has been initialized + virtual void onInitRuntime(); + // called after the library has been compiled + virtual void onLibraryStartup(); + // called before the library is shut down + virtual void onLibraryShutdown(); + // called after the interpreter has been started + virtual void onInterpStartup(); + +private: + friend void closeAllGUIScreens(); + friend void initGUIPrimitives(); + friend void initGUI(); + +private: + char* mName; + FILE* mPostFile; + SC_StringBuffer mScratch; + bool mRunning; + static SC_LanguageClient* gInstance; +}; + +// ===================================================================== +// library functions +// ===================================================================== + +extern void setPostFile(FILE* file); +extern "C" int vpost(const char *fmt, va_list vargs); +extern void post(const char *fmt, ...); +extern void postfl(const char *fmt, ...); +extern void postText(const char *text, long length); +extern void postChar(char c); +extern void error(const char *fmt, ...); +extern void flushPostBuf(); + +#endif // SC_LANGUAGECLIENT_H_INCLUDED diff --git a/sc4pd/headers/lang/SC_LibraryConfig.h b/sc4pd/headers/lang/SC_LibraryConfig.h new file mode 100644 index 0000000..5f7df3b --- /dev/null +++ b/sc4pd/headers/lang/SC_LibraryConfig.h @@ -0,0 +1,108 @@ +// emacs: -*- c++ -*- +// file: SC_LibraryConfig.h +// cvs: $Id: SC_LibraryConfig.h,v 1.1.1.1 2004-07-14 16:21:24 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_LIBRARYCONFIG_H_INCLUDED +#define SC_LIBRARYCONFIG_H_INCLUDED + +#include +#include + +// ===================================================================== +// SC_LibraryConfigFile +// simple library configuration file parser +// ===================================================================== + +class SC_LibraryConfig; + +class SC_LibraryConfigFile +{ +public: + typedef void (*ErrorFunc)(const char* fmt, ...); + +public: + SC_LibraryConfigFile(ErrorFunc errorFunc=0); + + bool open(const char* filePath); + bool read(const char* fileName, SC_LibraryConfig* libConf); + void close(); + +protected: + enum State + { + kBegin, + kAction, + kPath, + kEscape, + kEnvVar, + kEnvVarName, + kEnd + }; + + enum + { + kMaxIncludeDepth = 10 + }; + + bool read(int depth, const char* fileName, SC_LibraryConfig* libConf); + bool parseLine(int depth, const char* fileName, int lineNumber, const char* line, SC_LibraryConfig* libConf); + static void defaultErrorFunc(const char* fmt, ...); + +private: + ErrorFunc mErrorFunc; + FILE* mFile; +}; + +// ===================================================================== +// SC_LibraryConfig +// library configuration management +// Copyright 2003 Maurizio Umberto Puxeddu +// ===================================================================== + +class SC_LibraryConfig +{ +public: + SC_LibraryConfig(void); + virtual ~SC_LibraryConfig(); + + char **includedDirectories(void); + char **excludedDirectories(void); + + void postExcludedDirectories(void); + bool forEachIncludedDirectory(bool (*func)(char *, int)); + + bool pathIsExcluded(const char *path); + + void addIncludedDirectory(char *name); + void addExcludedDirectory(char *name); + + // convenience functions to access the global library config + static bool readLibraryConfig(SC_LibraryConfigFile& file, const char* fileName); + static void freeLibraryConfig(); + +private: + int m_nIncludedDirectories; + char **m_includedDirectories; + int m_nExcludedDirectories; + char **m_excludedDirectories; +}; + +extern SC_LibraryConfig* gLibraryConfig; +extern char *unixStandardizePath(const char *path, char *newpath); + +#endif // SC_LIBRARYCONFIG_H_INCLUDED diff --git a/sc4pd/headers/lang/SC_List.h b/sc4pd/headers/lang/SC_List.h new file mode 100755 index 0000000..1713521 --- /dev/null +++ b/sc4pd/headers/lang/SC_List.h @@ -0,0 +1,229 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +A doubly linked list template. + +*/ + +#ifndef _SC_List_ +#define _SC_List_ + +#include +#ifndef NDEBUG +# define NDEBUG +#endif +#include + + +// A Link can be a node in a list or a list itself. + +template +class Link +{ +public: + Link() : mNext(this), mPrev(this) {} + + T* Prev() { return static_cast(mPrev); } + T* Next() { return static_cast(mNext); } + + void RemoveLeaveDangling() + { + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + } + + void Remove() + { + RemoveLeaveDangling(); + mNext = mPrev = this; + } + + void InsertAfter(T *inLink) + { + mPrev = inLink; + mNext = inLink->mNext; + mNext->mPrev = this; + mPrev->mNext = this; + } + + void InsertBefore(T *inLink) + { + mNext = inLink; + mPrev = inLink->mPrev; + mNext->mPrev = this; + mPrev->mNext = this; + } + + T* Head() { return static_cast(mNext); } + T* Tail() { return static_cast(mPrev); } + + T* PopHead(); + T* PopTail(); + void PushHead(T* inBuf); + void PushTail(T* inBuf); + + bool ContainsBuf(T* inBuf); + bool IsEmpty() { return mNext == this; } + void BeEmpty() { mNext = mPrev = this; } + + void Cat(T* inLink); + + bool SanityCheck(); + void DebugDump(); + +//private: +// Codewarrior refuses to inline Next() in some places.. + Link *mNext, *mPrev; +}; + +template +void MakeListEmpty(Link *inLink, Alloc* inAlloc) +{ + Link* link = inLink->mNext; + while (link != inLink) { + Link* nextlink = link->mNext; + // SC uses placement new extensively, so here we do a 'placement delete'. + // Using DestructSelf allows me to have either virtual + // or non virtual destructors in subclasses at the discretion of the subclass. + ((T*)(link))->DestructSelf(); + inAlloc->Free(static_cast(link)); + link = nextlink; + } + inLink->mNext = inLink->mPrev = inLink; +} + +template +void Link::PushHead(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertAfter(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopHead() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mNext; + + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::PushTail(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertBefore(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopTail() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mPrev; + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::Cat(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + + if (link->IsEmpty()) return; + if (IsEmpty()) { + mNext = link->mNext; + mPrev = link->mPrev; + link->mNext->mPrev = this; + link->mPrev->mNext = this; + } else { + link->mNext->mPrev = mPrev; + link->mPrev->mNext = this; + mPrev->mNext = link->mNext; + mPrev = link->mPrev; + } + link->mPrev = link; + link->mNext = link; + + assert(SanityCheck()); +} + +template +bool Link::ContainsBuf(T* inLink) +{ + Link* link = static_cast*>(inLink); + Link* curLink = mNext; + while (curLink != this) { + if (curLink == link) return true; + curLink = curLink->mNext; + } + return false; +} + +template +void Link::DebugDump() +{ + Link* link = mNext; + while (link != this) { + //post("Link-> %08X next %08X prev %08X\n", + // link, link->mNext, link->mPrev); + link = link->mNext; + } +} + +template +bool Link::SanityCheck() +{ + Link* link = mNext; + while (link != this) { + if (link->mPrev->mNext != link) { + throw std::runtime_error("Link: bad link <-,->"); + } + if (link->mNext->mPrev != link) { + throw std::runtime_error("Link: bad link ->,<-"); + } + link = link->mNext; + } + return true; +} + + + +#endif diff --git a/sc4pd/headers/lang/SC_LogFile.h b/sc4pd/headers/lang/SC_LogFile.h new file mode 100755 index 0000000..d94c4e2 --- /dev/null +++ b/sc4pd/headers/lang/SC_LogFile.h @@ -0,0 +1,29 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_LogFile_ +#define _SC_LogFile_ + +#include + +extern FILE *gLogFile; + +#endif diff --git a/sc4pd/headers/lang/SC_Msg.h b/sc4pd/headers/lang/SC_Msg.h new file mode 100755 index 0000000..b187f09 --- /dev/null +++ b/sc4pd/headers/lang/SC_Msg.h @@ -0,0 +1,70 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Msg_ +#define _SC_Msg_ + +#include +#include +#include +#include "sc_msg_iter.h" + +class SC_Msg; + +enum { // Handler IDs + kUnknownAction = 0, + kRealTimeAction = 1, + kNonRealTimeAction = 2, + kEitherTimeAction = 3 +}; + +typedef void (*ReplyFunc)(struct ReplyAddress *inReplyAddr, char* inBuf, int inSize); + +struct ReplyAddress +{ + struct sockaddr_in mSockAddr; + int mSockAddrLen; + int mSocket; + ReplyFunc mReplyFunc; +}; + +inline void SendReply(ReplyAddress *inReplyAddr, char* inBuf, int inSize) +{ + (inReplyAddr->mReplyFunc)(inReplyAddr, inBuf, inSize); +} + +void DumpReplyAddress(ReplyAddress *inReplyAddress); +int32 Hash(ReplyAddress *inReplyAddress); + +struct OSC_Packet +{ + char *mData; + int32 mSize; + bool mIsBundle; + + ReplyAddress mReplyAddr; +}; + +void FreeOSCPacket(OSC_Packet *inPacket); + +#endif + + diff --git a/sc4pd/headers/lang/SC_SynthImpl.h b/sc4pd/headers/lang/SC_SynthImpl.h new file mode 100755 index 0000000..88411b3 --- /dev/null +++ b/sc4pd/headers/lang/SC_SynthImpl.h @@ -0,0 +1,42 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_SynthImpl_ +#define _SC_SynthImpl_ + +#include "SC_Synth.h" +#include "SC_SynthDef.h" +#include "HashTable.h" +#include "SC_AllocPool.h" +#include "SC_UnorderedList.h" + +extern SynthInterfaceTable gSynthInterfaceTable; +void InitSynthInterfaceTable(); + +typedef void (*SetupInterfaceFunc)(SynthInterfaceTable*); + +const int kMaxSynths = 1024; +extern StaticHashTable gSynthTable; +extern AllocPool *gSynthAllocPool; + +extern float32 gSine[8193]; + +#endif \ No newline at end of file diff --git a/sc4pd/headers/lang/SC_TerminalClient.h b/sc4pd/headers/lang/SC_TerminalClient.h new file mode 100644 index 0000000..b0375d0 --- /dev/null +++ b/sc4pd/headers/lang/SC_TerminalClient.h @@ -0,0 +1,92 @@ +// emacs: -*- c++ -*- +// file: SC_TerminalClient.h +// copyright: 2003 stefan kersten +// cvs: $Id: SC_TerminalClient.h,v 1.1.1.1 2004-07-14 16:21:27 timblech Exp $ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA + +#ifndef SC_TERMINALCLIENT_H_INCLUDED +#define SC_TERMINALCLIENT_H_INCLUDED + +#include "SC_LanguageClient.h" +#include "SC_StringBuffer.h" + +// ===================================================================== +// SC_TerminalClient - command line sclang client. +// ===================================================================== + +class SC_TerminalClient : public SC_LanguageClient +{ +public: + enum + { + kInterpretCmdLine = 0x1b, + kInterpretPrintCmdLine = 0x0c + }; + + struct Options : public SC_LanguageClient::Options + { + Options() + : mLibraryConfigFile(0), + mDaemon(false), + mCallRun(false), + mCallStop(false), + mArgc(0), mArgv(0) + { } + + char* mLibraryConfigFile; + bool mDaemon; + bool mCallRun; + bool mCallStop; + int mArgc; + char** mArgv; + }; + + SC_TerminalClient(const char* name); + + const Options& options() const { return mOptions; } + bool shouldBeRunning() const { return mShouldBeRunning; } + + int run(int argc, char** argv); + void quit(int code); + + virtual void post(const char *fmt, va_list ap, bool error); + virtual void post(char c); + virtual void post(const char* str, size_t len); + virtual void flush(); + +protected: + bool parseOptions(int& argc, char**& argv, Options& opt); + void printUsage(); + + // fd is assumed to be non-blocking + bool readCmdLine(int fd, SC_StringBuffer& cmdLine); + void interpretCmdLine(PyrSymbol* method, SC_StringBuffer& cmdLine); + + // subclasses should override + virtual void commandLoop(); + virtual void daemonLoop(); + + static int prExit(struct VMGlobals* g, int); + virtual void onLibraryStartup(); + +private: + bool mShouldBeRunning; + int mReturnCode; + Options mOptions; +}; + +#endif // SC_TERMINALCLIENT_H_INCLUDED diff --git a/sc4pd/headers/lang/SC_UnorderedList.h b/sc4pd/headers/lang/SC_UnorderedList.h new file mode 100755 index 0000000..37ce8d9 --- /dev/null +++ b/sc4pd/headers/lang/SC_UnorderedList.h @@ -0,0 +1,60 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_UnorderedList_ +#define _SC_UnorderedList_ + +template +class SC_UnorderedList +{ + T* mList[kMaxItems]; + unsigned int mSize; +public: + SC_UnorderedList() : mSize(0) {} + + unsigned int Size() const { return mSize; } + Synth* GetAt(unsigned int inIndex) + { + if (inIndex >= mSize) return 0; + return mList[inIndex]; + } + + void Add(T *inItem) + { + if (mSize < kMaxItems) { + mList[mSize] = inItem; + SetListIndex(inItem, mSize++); + } + } + + void Remove(T *inItem) + { + --mSize; + unsigned int index = GetListIndex(inItem); + if (index < mSize) { + mList[index] = mList[mSize]; + SetListIndex(mList[index], index); + } + } +}; + +#endif + diff --git a/sc4pd/headers/lang/SFHeaders.h b/sc4pd/headers/lang/SFHeaders.h new file mode 100755 index 0000000..0504b27 --- /dev/null +++ b/sc4pd/headers/lang/SFHeaders.h @@ -0,0 +1 @@ +/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SFHeaders_ #define _SFHeaders_ #include "SCBase.h" #include "ReadWriteMacros.h" enum { unsupported_sound_file = -1, AIFF_sound_file, AIFC_sound_file, RIFF_sound_file, NeXT_sound_file, IRCAM_sound_file, SD2_sound_file, raw_sound_file }; enum { snd_unsupported = -1, snd_no_snd, snd_16_linear, snd_8_mulaw, snd_8_linear, snd_32_float, snd_32_linear, snd_8_alaw, snd_8_unsigned, snd_24_linear, snd_64_double, snd_16_linear_little_endian, snd_32_linear_little_endian, snd_32_float_little_endian, snd_64_double_little_endian, snd_16_unsigned, snd_16_unsigned_little_endian, snd_24_linear_little_endian, snd_32_vax_float, snd_12_linear, snd_12_linear_little_endian, snd_12_unsigned, snd_12_unsigned_little_endian }; class SFHeaderInfo { public: SFHeaderInfo(); bool WriteHeader(FILE *inFile); void SetPath(char *inPath); double SampleRate() { return mSampleRate; } void SetSampleRate(double inSampleRate) { mSampleRate = inSampleRate; } void SetFormat(int inHeaderFormat, int inSampleFormat, int inCreator); double Freq() { return mFreq; } uint8 LoNote() { return mLoNote; } uint8 HiNote() { return mHiNote; } uint8 LoVeloc() { return mLoVeloc; } uint8 HiVeloc() { return mHiVeloc; } uint8 NumChannels() { return mNumChannels; } int32 NumFramesInFile() { return mNumFramesInFile; } int makeSoundFileHeader(SC_IOStream& rw); int32 headerFileType(); int headerSize(); int sampleFormatSize(); void newSoundFilePath(); bool ReadSoundFileHeader(FILE *fp); int32 CalcFrameSize(); bool SetTypeCreator(); char mPath[256]; double mSampleRate; double mFreq; int32 mNumFramesInFile; int32 mDataOffset; int32 mCreator; void *mExtraStuff; int16 mGain; int8 mHeaderFormat; int8 mSampleFormat; uint8 mNumChannels; uint8 mLoNote, mHiNote, mLoVeloc, mHiVeloc; private: int make_AIFF_header(SC_IOStream& rw); int make_AIFC_header(SC_IOStream& rw); int make_RIFF_header(SC_IOStream& rw); int make_Next_header(SC_IOStream& rw); int make_IRCAM_header(SC_IOStream& rw); int sampleFormat_AIFF(); int sampleFormat_AIFC(); int sampleFormat_RIFF(); int sampleFormat_Next(); int sampleFormat_Next_inv(int inFormat); void writeCompressionFormat_AIFC(SC_IOStream& rw); bool read_AIFF_Header(SC_IOStream& rw); bool read_RIFF_Header(SC_IOStream& rw); bool read_Next_Header(SC_IOStream& rw); }; extern char gDefaultSoundFolder[256]; extern char gDefaultSoundFilePath[256]; int sampleFormatSize(int inSampleFormat); #endif \ No newline at end of file diff --git a/sc4pd/headers/lang/Samp.h b/sc4pd/headers/lang/Samp.h new file mode 100755 index 0000000..7593ba8 --- /dev/null +++ b/sc4pd/headers/lang/Samp.h @@ -0,0 +1,46 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +Samp is a typedef for the output sample type. +Should be defined to be either float or double. + +*/ + +#ifndef _Samp_ +#define _Samp_ + +#include "SC_Types.h" + +const long kSineSize = 8192; +const long kSineMask = kSineSize - 1; +const double kSinePhaseScale = kSineSize / (2.0 * 3.1415926535897932384626433832795); + +extern float32 gSine[kSineSize+1]; +extern float32 gPMSine[kSineSize+1]; +extern float32 gInvSine[kSineSize+1]; +extern float32 gSineWavetable[2*kSineSize]; + +void SignalAsWavetable(float32* signal, float32* wavetable, long inSize); +void WavetableAsSignal(float32* wavetable, float32* signal, long inSize); + +#endif + diff --git a/sc4pd/headers/lang/SimpleStack.h b/sc4pd/headers/lang/SimpleStack.h new file mode 100755 index 0000000..3313785 --- /dev/null +++ b/sc4pd/headers/lang/SimpleStack.h @@ -0,0 +1,32 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +typedef struct { + long *stak; + short num, maxsize; +} LongStack; + +void initLongStack(LongStack *self) ; +void freeLongStack(LongStack *self); +void growLongStack(LongStack *self); +void pushls(LongStack *self, long value); +long popls(LongStack *self); +int emptyls(LongStack *self); diff --git a/sc4pd/headers/lang/VMGlobals.h b/sc4pd/headers/lang/VMGlobals.h new file mode 100755 index 0000000..9b5f2e1 --- /dev/null +++ b/sc4pd/headers/lang/VMGlobals.h @@ -0,0 +1,94 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +Each virtual machine has a copy of VMGlobals, which contains the state of the virtual machine. + +*/ + +#ifndef _VMGLOBALS_H_ +#define _VMGLOBALS_H_ + +#include "PyrSlot.h" +#include "SC_AllocPool.h" +#include "SC_RGen.h" + +const int kNumProcesses = 1; +const int kMainProcessID = 0; + +typedef void (*FifoMsgFunc)(struct VMGlobals*, struct FifoMsg*); + +struct FifoMsg { + FifoMsg() : func(0), dataPtr(0) { dataWord[0] = dataWord[1] = 0; } + void Perform(struct VMGlobals* g); + void Free(struct VMGlobals* g); + + FifoMsgFunc func; + void* dataPtr; + long dataWord[2]; +}; + +struct VMGlobals { + VMGlobals(); + + // global context + class AllocPool *allocPool; + struct PyrProcess *process; + class SymbolTable *symbolTable; + class PyrGC *gc; // garbage collector for this process + PyrSlot *classvars; + bool canCallOS; + + // thread context + struct PyrThread *thread; + struct PyrMethod *method; + struct PyrBlock *block; + struct PyrFrame *frame; + struct PyrMethod *primitiveMethod; + unsigned char *ip; // current instruction pointer + PyrSlot *sp; // current stack ptr + PyrSlot *args; + PyrSlot receiver; // the receiver + PyrSlot result; + int numpop; // number of args to pop for primitive + long returnLevels; + long processID; + long primitiveIndex; + RGen *rgen; + + // scratch context + long execMethod; +} ; + +inline void FifoMsg::Perform(struct VMGlobals* g) + { + (func)(g, this); + } + +inline void FifoMsg::Free(struct VMGlobals* g) + { + g->allocPool->Free(dataPtr); + } + +extern VMGlobals gVMGlobals[kNumProcesses]; +extern VMGlobals *gMainVMGlobals; +extern VMGlobals *gCompilingVMGlobals; +#endif + diff --git a/sc4pd/headers/lang/bullet.h b/sc4pd/headers/lang/bullet.h new file mode 100755 index 0000000..463b062 --- /dev/null +++ b/sc4pd/headers/lang/bullet.h @@ -0,0 +1,7 @@ + +// this should be an outstanding character +// it is used in printing errors + +#define BULLET "¥" +#define BULLET_CHAR '¥' + diff --git a/sc4pd/headers/lang/libraryConfig.h b/sc4pd/headers/lang/libraryConfig.h new file mode 100644 index 0000000..b1f3844 --- /dev/null +++ b/sc4pd/headers/lang/libraryConfig.h @@ -0,0 +1,31 @@ +// Copyright 2003 Maurizio Umberto Puxeddu + +#ifndef _Supercollider_libraryConfig_h_ +#define _Supercollider_libraryConfig_h_ + +class LibraryConfig { + public: + LibraryConfig(void); + virtual ~LibraryConfig(); + + char **includedDirectories(void); + char **excludedDirectories(void); + + void postExcludedDirectories(void); + bool forEachIncludedDirectory(bool (*func)(char *, int)); + + bool pathIsExcluded(const char *path); + + void addIncludedDirectory(char *name); + void addExcludedDirectory(char *name); + + private: + int m_nIncludedDirectories; + char **m_includedDirectories; + int m_nExcludedDirectories; + char **m_excludedDirectories; +}; + +extern char *unixStandardizePath(const char *path, char *newpath); + +#endif // _Supercollider_libraryConfig_h_ diff --git a/sc4pd/headers/lang/readSamples.h b/sc4pd/headers/lang/readSamples.h new file mode 100755 index 0000000..835f975 --- /dev/null +++ b/sc4pd/headers/lang/readSamples.h @@ -0,0 +1 @@ +/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _readSamples_ #define _readSamples_ long readSamplesInterleaved(FILE* fp, float *out, long numSamplesToRead, long format); void convertSamplesIn(float **out, char *in, long numFramesToRead, long numChannels, long sampOffset, long format); float convertSamplesOut(float **in, char *buffer, int numFramesToWrite, int numChannels, long sampOffset, int format); void convertSamplesInInterleaved(float *out, char *buffer, long numSamplesToRead, long sampOffset, long format); float convertSamplesOutInterleaved(float *in, char *buffer, long numSampsToWrite, int format); #endif \ No newline at end of file diff --git a/sc4pd/headers/plugin_interface/Hash.h b/sc4pd/headers/plugin_interface/Hash.h new file mode 100755 index 0000000..e42eaf4 --- /dev/null +++ b/sc4pd/headers/plugin_interface/Hash.h @@ -0,0 +1,152 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _Hash_ +#define _Hash_ + +#include "SC_Types.h" +#include "SC_Endian.h" + +// These hash functions are among the best there are in terms of both speed and quality. +// A good hash function makes a lot of difference. +// I have not used Bob Jenkins own hash function because the keys I use are relatively short. + + +// hash function for a string +inline int32 Hash(const char *inKey) +{ + // the one-at-a-time hash. + // a very good hash function. ref: a web page by Bob Jenkins. + // http://www.burtleburtle.net/bob/hash/doobs.html + int32 hash = 0; + while (*inKey) { + hash += *inKey++; + hash += hash << 10; + hash ^= hash >> 6; + } + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + return hash; +} + +// hash function for a string that also returns the length +inline int32 Hash(const char *inKey, int32 *outLength) +{ + // the one-at-a-time hash. + // a very good hash function. ref: a web page by Bob Jenkins. + const char *origKey = inKey; + int32 hash = 0; + while (*inKey) { + hash += *inKey++; + hash += hash << 10; + hash ^= hash >> 6; + } + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + *outLength = inKey - origKey; + return hash; +} + +// hash function for an array of char +inline int32 Hash(const char *inKey, int32 inLength) +{ + // the one-at-a-time hash. + // a very good hash function. ref: a web page by Bob Jenkins. + int32 hash = 0; + for (int i=0; i> 6; + } + hash += hash << 3; + hash ^= hash >> 11; + hash += hash << 15; + return hash; +} + +// hash function for integers +inline int32 Hash(int32 inKey) +{ + // Thomas Wang's integer hash. + // http://www.concentric.net/~Ttwang/tech/inthash.htm + // a faster hash for integers. also very good. + uint32 hash = (uint32)inKey; + hash += ~(hash << 15); + hash ^= hash >> 10; + hash += hash << 3; + hash ^= hash >> 6; + hash += ~(hash << 11); + hash ^= hash >> 16; + return (int32)hash; +} + +inline int64 Hash64(int64 inKey) +{ + // Thomas Wang's 64 bit integer hash. + uint64 hash = (uint64)inKey; + hash += ~(hash << 32); + hash ^= (hash >> 22); + hash += ~(hash << 13); + hash ^= (hash >> 8); + hash += (hash << 3); + hash ^= (hash >> 15); + hash += ~(hash << 27); + hash ^= (hash >> 31); + return (int64)hash; +} + +inline int32 Hash(const int32 *inKey, int32 inLength) +{ + // one-at-a-time hashing of a string of int32's. + // uses Thomas Wang's integer hash for the combining step. + int32 hash = 0; + for (int i=0; i=0?(a) : -(a)) +#define sc_max(a,b) (((a) > (b)) ? (a) : (b)) +#define sc_min(a,b) (((a) < (b)) ? (a) : (b)) +#define sc_clip(x, lo, hi) ((x) > (hi) ? (hi) : ((x) < (lo) ? (lo) : (x))) + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_BufGen.h b/sc4pd/headers/plugin_interface/SC_BufGen.h new file mode 100644 index 0000000..9a275c1 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_BufGen.h @@ -0,0 +1,40 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _BufGen_ +#define _BufGen_ + +#include "SC_Types.h" + +typedef void (*BufGenFunc)(struct World *world, struct SndBuf *buf, struct sc_msg_iter *msg); + +struct BufGen +{ + int32 mBufGenName[kSCNameLen]; + int32 mHash; + + BufGenFunc mBufGenFunc; +}; + +extern "C" { +bool BufGen_Create(char *inName, BufGenFunc inFunc); +} + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Constants.h b/sc4pd/headers/plugin_interface/SC_Constants.h new file mode 100755 index 0000000..b827cad --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Constants.h @@ -0,0 +1,46 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Constants_ +#define _SC_Constants_ + +#include + +#ifndef __FP__ +const double pi = acos(-1.); +#endif +const double pi2 = pi * .5; +const double pi32 = pi * 1.5; +const double twopi = pi * 2.; +const double rtwopi = 1. / twopi; +const double log001 = log(0.001); +const double log01 = log(0.01); +const double log1 = log(0.1); +const double rlog2 = 1./log(2.); +const double sqrt2 = sqrt(2.); +const double rsqrt2 = 1. / sqrt2; + +// used to truncate precision +const float truncFloat = (float)(3. * pow(2,22)); +const double truncDouble = 3. * pow(2,51); + +const float kBadValue = 1e20f; // used in the secant table for values very close to 1/0 + +#endif \ No newline at end of file diff --git a/sc4pd/headers/plugin_interface/SC_DemandUnit.h b/sc4pd/headers/plugin_interface/SC_DemandUnit.h new file mode 100644 index 0000000..6f273b3 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_DemandUnit.h @@ -0,0 +1,54 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_DemandUnit_ +#define _SC_DemandUnit_ + +#include "SC_Unit.h" +#include "SC_Wire.h" + +// demand rate unit support. + +inline bool IsDemandInput(Unit* unit, int index) +{ + Unit* fromUnit = unit->mInput[index]->mFromUnit; + return fromUnit && fromUnit->mCalcRate == calc_DemandRate; +} + +inline float DemandInput(Unit* unit, int index) +{ + Unit* fromUnit = unit->mInput[index]->mFromUnit; + if (fromUnit && fromUnit->mCalcRate == calc_DemandRate) + (fromUnit->mCalcFunc)(fromUnit, 1); + return IN0(index); +} + +inline void ResetInput(Unit* unit, int index) +{ + Unit* fromUnit = unit->mInput[index]->mFromUnit; + if (fromUnit && fromUnit->mCalcRate == calc_DemandRate) + (fromUnit->mCalcFunc)(fromUnit, 0); +} + +#define ISDEMANDINPUT(index) IsDemandInput(unit, (index)) +#define DEMANDINPUT(index) DemandInput(unit, (index)) +#define RESETINPUT(index) ResetInput(unit, (index)) + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Dimension.h b/sc4pd/headers/plugin_interface/SC_Dimension.h new file mode 100644 index 0000000..923b283 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Dimension.h @@ -0,0 +1,31 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Dimension_ +#define _SC_Dimension_ + +struct SC_Dimension +{ + long mWidth, mHeight, mNumPixels; + float mXSlopeFactor, mYSlopeFactor; +}; +typedef struct SC_Dimension SC_Dimension; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_FifoMsg.h b/sc4pd/headers/plugin_interface/SC_FifoMsg.h new file mode 100644 index 0000000..7d83e0a --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_FifoMsg.h @@ -0,0 +1,59 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _FifoMsg_ +#define _FifoMsg_ + +typedef void (*FifoMsgFunc)(struct FifoMsg*); + +struct FifoMsg +{ + FifoMsg() : mPerformFunc(0), mFreeFunc(0), mData(0), mWorld(0) {} + + void Set(struct World *inWorld, FifoMsgFunc inPerform, FifoMsgFunc inFree, void* inData); + void Perform(); + void Free(); + + FifoMsgFunc mPerformFunc; + FifoMsgFunc mFreeFunc; + void* mData; + struct World *mWorld; +}; + +inline void FifoMsg::Set(World *inWorld, FifoMsgFunc inPerform, FifoMsgFunc inFree, void* inData) +{ + mWorld = inWorld; + mPerformFunc = inPerform; + mFreeFunc = inFree; + mData = inData; +} + +inline void FifoMsg::Perform() +{ + if (mPerformFunc) (mPerformFunc)(this); +} + +inline void FifoMsg::Free() +{ + if (mFreeFunc) (mFreeFunc)(this); +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_Graph.h b/sc4pd/headers/plugin_interface/SC_Graph.h new file mode 100644 index 0000000..68d3d59 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Graph.h @@ -0,0 +1,53 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Graph_ +#define _SC_Graph_ + +#include "SC_Node.h" +#include "SC_Rate.h" +#include "SC_Dimension.h" + +struct Graph +{ + Node mNode; + + uint32 mNumWires; + struct Wire *mWire; + + uint32 mNumControls; + float *mControls; + float **mMapControls; + + uint32 mNumUnits; + struct Unit **mUnits; + + int mNumCalcUnits; + struct Unit **mCalcUnits; // excludes i-rate units. + + int mSampleOffset; + struct RGen* mRGen; + + struct Unit *mLocalAudioBusUnit; + struct Unit *mLocalControlBusUnit; +}; +typedef struct Graph Graph; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h b/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h new file mode 100755 index 0000000..2d9668b --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h @@ -0,0 +1,574 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _BinaryOpUGen_ +#define _BinaryOpUGen_ + +#include "SC_BoundsMacros.h" +#include + +inline float sc_mod(float in, float hi) +{ + // avoid the divide if possible + const float lo = (float)0.; + if (in >= hi) { + in -= hi; + if (in < hi) return in; + } else if (in < lo) { + in += hi; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - hi*floor(in/hi); +} + +inline double sc_mod(double in, double hi) +{ + // avoid the divide if possible + const double lo = (double)0.; + if (in >= hi) { + in -= hi; + if (in < hi) return in; + } else if (in < lo) { + in += hi; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - hi*floor(in/hi); +} + +inline float sc_wrap(float in, float lo, float hi) +{ + float range; + // avoid the divide if possible + if (in >= hi) { + range = hi - lo; + in -= range; + if (in < hi) return in; + } else if (in < lo) { + range = hi - lo; + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline double sc_wrap(double in, double lo, double hi) +{ + double range; + // avoid the divide if possible + if (in >= hi) { + range = hi - lo; + in -= range; + if (in < hi) return in; + } else if (in < lo) { + range = hi - lo; + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline double sc_wrap(double in, double lo, double hi, double range) +{ + // avoid the divide if possible + if (in >= hi) { + in -= range; + if (in < hi) return in; + } else if (in < lo) { + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline double sc_wrap(float in, float lo, float hi, float range) +{ + // avoid the divide if possible + if (in >= hi) { + in -= range; + if (in < hi) return in; + } else if (in < lo) { + in += range; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + return in - range * floor((in - lo)/range); +} + +inline float sc_fold(float in, float lo, float hi) +{ + float x, c, range, range2; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + range = hi - lo; + range2 = range + range; + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline double sc_fold(double in, double lo, double hi) +{ + double x, c, range, range2; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + range = hi - lo; + range2 = range + range; + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline double sc_fold(float in, float lo, float hi, float range, float range2) +{ + float x, c; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline double sc_fold(double in, double lo, double hi, double range, double range2) +{ + double x, c; + x = in - lo; + + // avoid the divide if possible + if (in >= hi) { + in = hi + hi - in; + if (in >= lo) return in; + } else if (in < lo) { + in = lo + lo - in; + if (in < hi) return in; + } else return in; + + if (hi == lo) return lo; + // ok do the divide + c = x - range2 * floor(x / range2); + if (c>=range) c = range2 - c; + return c + lo; +} + +inline float sc_pow(float a, float b) +{ + return a >= 0.f ? pow(a, b) : -pow(-a, b); +} + +inline double sc_pow(double a, double b) +{ + return a >= 0.f ? pow(a, b) : -pow(-a, b); +} + +template +inline float sc_thresh(T a, T b) +{ + return a < b ? (T)0 : a; +} + +inline float sc_clip2(float a, float b) +{ + return sc_clip(a, -b, b); +} + +inline float sc_wrap2(float a, float b) +{ + return sc_wrap(a, -b, b); +} + +inline float sc_fold2(float a, float b) +{ + return sc_fold(a, -b, b); +} + +inline float sc_excess(float a, float b) +{ + return a - sc_clip(a, -b, b); +} + +inline float sc_round(float x, float quant) +{ + return quant==0. ? x : floor(x/quant + .5f) * quant; +} + +inline double sc_round(double x, double quant) +{ + return quant==0. ? x : floor(x/quant + .5) * quant; +} + +inline float sc_roundUp(float x, float quant) +{ + return quant==0. ? x : ceil(x/quant) * quant; +} + +inline double sc_roundUp(double x, double quant) +{ + return quant==0. ? x : ceil(x/quant) * quant; +} + +inline float sc_trunc(float x, float quant) +{ + return quant==0. ? x : floor(x/quant) * quant; +} + +inline double sc_trunc(double x, double quant) +{ + return quant==0. ? x : floor(x/quant) * quant; +} + +inline float sc_atan2(float a, float b) +{ + return atan2(a, b); +} + + +inline float sc_scaleneg(float a, float b) +{ + b = 0.5f * b + 0.5f; + return (fabs(a) - a) * b + a; +} + +inline float sc_amclip(float a, float b) +{ + return a * 0.5f * (b + fabs(b)); +} + +inline double sc_amclip(double a, double b) +{ + return a * 0.5 * (b + fabs(b)); +} + +const float kFSQRT2M1 = sqrt(2.) - 1.; +const double kDSQRT2M1 = sqrt(2.) - 1.; + +inline float sc_hypotx(float x, float y) +{ + float minxy; + + x = fabs(x); + y = fabs(y); + + minxy = sc_min(x,y); + + return x + y - kFSQRT2M1 * minxy; +} + +inline double sc_hypotx(double x, double y) +{ + double minxy; + + x = fabs(x); + y = fabs(y); + + minxy = sc_min(x,y); + + return x + y - kDSQRT2M1 * minxy; +} + +#pragma mark - + + +inline int sc_div(int a, int b) +{ + int c; + if (b) { + if (a<0) c = (a+1)/b - 1; + else c = a/b; + } else c = a; + return c; +} + +/* +inline int sc_mod(int a, int b) +{ + long c; + c = a % b; + if (c<0) c += b; + return c; +} +*/ + +inline int sc_mod(int in, int hi) +{ + // avoid the divide if possible + const int lo = 0; + if (in >= hi) { + in -= hi; + if (in < hi) return in; + } else if (in < lo) { + in += hi; + if (in >= lo) return in; + } else return in; + + if (hi == lo) return lo; + + int c; + c = in % hi; + if (c<0) c += hi; + return c; +} + +inline int sc_wrap(int in, int lo, int hi) +{ + return sc_mod(in - lo, hi - lo + 1) + lo; +} + +inline int sc_clip2(int a, int b) +{ + return sc_clip(a, -b, b); +} + +inline int sc_wrap2(int a, int b) +{ + return sc_wrap(a, -b, b); +} + +inline int sc_fold(int in, int lo, int hi) +{ + int b = hi - lo; + int b2 = b+b-2; + int c = sc_mod(in - lo, b2); + if (c>=b) c = b2-c; + return c + lo; +} + +inline int sc_fold2(int a, int b) +{ + return sc_fold(a, -b, b); +} + +inline int sc_excess(int a, int b) +{ + return a - sc_clip(a, -b, b); +} + +inline int sc_gcd(int u, int v) +{ + int t; + u = sc_abs(u); + v = sc_abs(v); + if (u <= 1 || v <= 1) return 1; + while (u>0) { + if (u> b; +} + +inline int sc_unsignedRightShift(int a, int b) +{ + return (uint32)a >> b; +} + +inline int sc_round(int x, int quant) +{ + return quant==0 ? x : sc_div(x + quant/2, quant) * quant; +} + + +inline int sc_roundUp(int x, int quant) +{ + return quant==0 ? x : sc_div(x + quant - 1, quant) * quant; +} + +inline int sc_trunc(int x, int quant) +{ + return quant==0 ? x : sc_div(x, quant) * quant; +} + +#pragma mark - + +#if 0 + +inline long sc_div(long a, long b) +{ + int c; + if (b) { + if (a<0) c = (a+1)/b - 1; + else c = a/b; + } else c = a; + return c; +} + + +inline long sc_clip2(long a, long b) +{ + return sc_clip(a, -b, b); +} + +inline long sc_wrap(long in, long lo, long hi) +{ + return sc_mod(in - lo, hi - lo + 1) + lo; +} + +inline long sc_wrap2(long a, long b) +{ + return sc_wrap(a, -b, b); +} + +inline long sc_fold(long in, long lo, long hi) +{ + long b = hi - lo; + long b2 = b+b-2; + long c = sc_mod(in - lo, b2); + if (c>=b) c = b2-c; + return c + lo; +} + +inline long sc_fold2(long a, long b) +{ + return sc_fold(a, -b, b); +} + +inline long sc_thresh(long a, long b) +{ + return a < b ? 0 : a; +} + +inline long sc_bitAnd(long a, long b) +{ + return a & b; +} + +inline long sc_bitOr(long a, long b) +{ + return a | b; +} + +inline long sc_leftShift(long a, long b) +{ + return a << b; +} + +inline long sc_rightShift(long a, long b) +{ + return a >> b; +} + +inline long sc_unsignedRightShift(long a, long b) +{ + return (unsigned long)a >> b; +} + +inline long sc_gcd(long u, long v) +{ + long t; + u = sc_abs(u); + v = sc_abs(v); + if (u <= 1 || v <= 1) return 1; + while (u>0) { + if (u= 0.f || x <= 0.f)); +} + +/////////////////////////////////////////////////////////////////////////////////////// + +// versions provided for float32 and float64 +// did not supply template because do not want to instantiate for integers. +// all constants explicitly cast to prevent PowerPC frsp instruction generation. + +/////////////////////////////////////////////////////////////////////////////////////// + +// this is a function for preventing pathological math operations in ugens. +// can be used at the end of a block to fix any recirculating filter values. +inline float32 zapgremlins(float32 x) +{ + float32 absx = fabs(x); + // very small numbers fail the first test, eliminating denormalized numbers + // (zero also fails the first test, but that is OK since it returns zero.) + // very large numbers fail the second test, eliminating infinities + // Not-a-Numbers fail both tests and are eliminated. + return (absx > (float32)1e-15 && absx < (float32)1e15) ? x : (float32)0.; +} + +inline float32 sc_log2(float32 x) +{ + return log(fabs(x)) * rlog2; +} + +inline float32 sc_log10(float32 x) +{ + return log10(fabs(x)); +} + +inline float32 sc_midicps(float32 note) +{ + return (float32)440. * pow((float32)2., (note - (float32)69.) * (float32)0.083333333333); +} + +inline float32 sc_cpsmidi(float32 freq) +{ + return sc_log2(freq * (float32)0.0022727272727) * (float32)12. + (float32)69.; +} + +inline float32 sc_midiratio(float32 midi) +{ + return pow((float32)2. , midi * (float32)0.083333333333); +} + +inline float32 sc_ratiomidi(float32 ratio) +{ + return (float32)12. * sc_log2(ratio); +} + +inline float32 sc_octcps(float32 note) +{ + return (float32)440. * pow((float32)2., note - (float32)4.75); +} + +inline float32 sc_cpsoct(float32 freq) +{ + return sc_log2(freq * (float32)0.0022727272727) + (float32)4.75; +} + +inline float32 sc_ampdb(float32 amp) +{ + return log10(amp) * (float32)20.; +} + +inline float32 sc_dbamp(float32 db) +{ + return pow((float32)10., db * (float32).05); +} + +inline float32 sc_squared(float32 x) +{ + return x * x; +} + +inline float32 sc_cubed(float32 x) +{ + return x * x * x; +} + +inline float32 sc_sqrt(float32 x) +{ + return x < (float32)0. ? -sqrt(-x) : sqrt(x); +} + + +inline float32 sc_hanwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + return (float32)0.5 - (float32)0.5 * cos(x * twopi); +} + +inline float32 sc_welwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + return sin(x * pi); +} + +inline float32 sc_triwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + if (x < (float32)0.5) return (float32)2. * x; + else return (float32)-2. * x + (float32)2.; +} + +inline float32 sc_bitriwindow(float32 x) +{ + float32 ax = (float32)1. - fabs(x); + if (ax <= (float32)0.) return (float32)0.; + return ax; +} + +inline float32 sc_rectwindow(float32 x) +{ + if (x < (float32)0. || x > (float32)1.) return (float32)0.; + return (float32)1.; +} + +inline float32 sc_scurve(float32 x) +{ + if (x <= (float32)0.) return (float32)0.; + if (x >= (float32)1.) return (float32)1.; + return x * x * ((float32)3. - (float32)2. * x); +} + +inline float32 sc_scurve0(float32 x) +{ + // assumes that x is in range + return x * x * ((float32)3. - (float32)2. * x); +} + +inline float32 sc_ramp(float32 x) +{ + if (x <= (float32)0.) return (float32)0.; + if (x >= (float32)1.) return (float32)1.; + return x; +} + +inline float32 sc_distort(float32 x) +{ + return x / ((float32)1. + fabs(x)); +} + +inline float32 sc_softclip(float32 x) +{ + float32 absx = fabs(x); + if (absx <= (float32)0.5) return x; + else return (absx - (float32)0.25) / x; +} + +// Taylor expansion out to x**9/9! factored into multiply-adds +// from Phil Burk. +inline float32 taylorsin(float32 x) +{ + // valid range from -pi/2 to +3pi/2 + x = pi2 - fabs(pi2 - x); + float32 x2 = x * x; + return x*(x2*(x2*(x2*(x2*(1.0/362880.0) + - (1.0/5040.0)) + + (1.0/120.0)) + - (1.0/6.0)) + + 1.0); +} + +inline float32 sc_trunc(float32 x) +{ + // truncFloat is a number which causes a loss of precision of + // the fractional part. + // NOTE: this will only work if the FPU is set to round downward. + // That is NOT the default rounding mode. SC sets it to this mode. + float32 tmp1 = x + truncFloat; + float32 tmp2 = tmp1 - truncFloat; + return tmp2; +} + +inline float32 sc_frac(float32 x) +{ + return x - sc_trunc(x); +} + +inline float32 sc_lg3interp(float32 x1, float32 a, float32 b, float32 c, float32 d) +{ + // cubic lagrange interpolator + float32 x0 = x1 + 1.f; + float32 x2 = x1 - 1.f; + float32 x3 = x1 - 2.f; + + float32 x03 = x0 * x3 * 0.5f; + float32 x12 = x1 * x2 * 0.16666666666666667f; + + return x12 * (d * x0 - a * x3) + x03 * (b * x2 - c * x1); +} + +inline float32 sc_CalcFeedback(float32 delaytime, float32 decaytime) +{ + if (delaytime == 0.f) { + return 0.f; + } else if (decaytime > 0.f) { + return exp(log001 * delaytime / decaytime); + } else if (decaytime < 0.f) { + return -exp(log001 * delaytime / -decaytime); + } else { + return 0.f; + } +} + +inline float32 sc_wrap1(float32 x) +{ + if (x >= (float32) 1.) return x + (float32)-2.; + if (x < (float32)-1.) return x + (float32) 2.; + return x; +} + +inline float32 sc_fold1(float32 x) +{ + if (x >= (float32) 1.) return (float32) 2. - x; + if (x < (float32)-1.) return (float32)-2. - x; + return x; +} + + +/////////////////////////////////////////////////////////////////////////////////////// + +inline float64 zapgremlins(float64 x) +{ + float64 absx = fabs(x); + // very small numbers fail the first test, eliminating denormalized numbers + // (zero also fails the first test, but that is OK since it returns zero.) + // very large numbers fail the second test, eliminating infinities + // Not-a-Numbers fail both tests and are eliminated. + return (absx > (float64)1e-15 && absx < (float64)1e15) ? x : (float64)0.; +} + +inline float64 sc_log2(float64 x) +{ + return log(fabs(x)) * rlog2; +} + +inline float64 sc_log10(float64 x) +{ + return log10(fabs(x)); +} + +inline float64 sc_midicps(float64 note) +{ + return (float64)440. * pow((float64)2., (note - (float64)69.) * (float64)0.083333333333); +} + +inline float64 sc_cpsmidi(float64 freq) +{ + return sc_log2(freq * (float64)0.0022727272727) * (float64)12. + (float64)69.; +} + +inline float64 sc_midiratio(float64 midi) +{ + return pow((float64)2. , midi * (float64)0.083333333333); +} + +inline float64 sc_ratiomidi(float64 ratio) +{ + return (float64)12. * sc_log2(ratio); +} + +inline float64 sc_octcps(float64 note) +{ + return (float64)440. * pow((float64)2., note - (float64)4.75); +} + +inline float64 sc_cpsoct(float64 freq) +{ + return sc_log2(freq * (float64)0.0022727272727) + (float64)4.75; +} + +inline float64 sc_ampdb(float64 amp) +{ + return log10(amp) * (float64)20.; +} + +inline float64 sc_dbamp(float64 db) +{ + return pow((float64)10., db * (float64).05); +} + +inline float64 sc_squared(float64 x) +{ + return x * x; +} + +inline float64 sc_cubed(float64 x) +{ + return x * x * x; +} + +inline float64 sc_sqrt(float64 x) +{ + return x < (float64)0. ? -sqrt(-x) : sqrt(x); +} + +inline float64 sc_hanwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + return (float64)0.5 - (float64)0.5 * cos(x * twopi); +} + +inline float64 sc_welwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + return sin(x * pi); +} + +inline float64 sc_triwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + if (x < (float64)0.5) return (float64)2. * x; + else return (float64)-2. * x + (float64)2.; +} + +inline float64 sc_bitriwindow(float64 x) +{ + float64 ax = fabs(x); + if (ax > (float64)1.) return (float64)0.; + return (float64)1. - ax; +} + +inline float64 sc_rectwindow(float64 x) +{ + if (x < (float64)0. || x > (float64)1.) return (float64)0.; + return (float64)1.; +} + +inline float64 sc_scurve(float64 x) +{ + if (x <= (float64)0.) return (float64)0.; + if (x >= (float64)1.) return (float64)1.; + return x * x * ((float64)3. - (float64)2. * x); +} + +inline float64 sc_scurve0(float64 x) +{ + // assumes that x is in range + return x * x * ((float64)3. - (float64)2. * x); +} + +inline float64 sc_ramp(float64 x) +{ + if (x <= (float64)0.) return (float64)0.; + if (x >= (float64)1.) return (float64)1.; + return x; +} + +inline float64 sc_distort(float64 x) +{ + return x / ((float64)1. + fabs(x)); +} + +inline float64 sc_softclip(float64 x) +{ + float64 absx = fabs(x); + if (absx <= (float64)0.5) return x; + else return (absx - (float64)0.25) / x; +} + +// Taylor expansion out to x**9/9! factored into multiply-adds +// from Phil Burk. +inline float64 taylorsin(float64 x) +{ + x = pi2 - fabs(pi2 - x); + float64 x2 = x * x; + return x*(x2*(x2*(x2*(x2*(1.0/362880.0) + - (1.0/5040.0)) + + (1.0/120.0)) + - (1.0/6.0)) + + 1.0); +} + +inline float64 sc_trunc(float64 x) +{ + // truncDouble is a number which causes a loss of precision of + // the fractional part. + // NOTE: this will only work if the FPU is set to round downward. + // That is NOT the default rounding mode. SC sets it to this mode. + float64 tmp1 = x + truncDouble; + float64 tmp2 = tmp1 - truncDouble; + return tmp2; +} + +inline float64 sc_frac(float64 x) +{ + return x - sc_trunc(x); +} + +inline float64 sc_wrap1(float64 x) +{ + if (x >= (float64) 1.) return x + (float64)-2.; + if (x < (float64)-1.) return x + (float64) 2.; + return x; +} + +inline float64 sc_fold1(float64 x) +{ + if (x >= (float64) 1.) return (float64) 2. - x; + if (x < (float64)-1.) return (float64)-2. - x; + return x; +} + +inline int32 sc_grayCode(int32 x) +{ + return x ^ (x >> 1); +} + + + +/////////////////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_InterfaceTable.h b/sc4pd/headers/plugin_interface/SC_InterfaceTable.h new file mode 100644 index 0000000..20cb864 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_InterfaceTable.h @@ -0,0 +1,175 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_SynthInterfaceTable_ +#define _SC_SynthInterfaceTable_ + +#include "SC_Types.h" +#include "SC_SndBuf.h" +#include "SC_Unit.h" +#include "SC_BufGen.h" +#include "SC_FifoMsg.h" +#include + +struct World; + +typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData); +typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData); + +struct InterfaceTable +{ + unsigned int mSineSize; + float32 *mSineWavetable; + float32 *mSine; + float32 *mCosecant; + + // call printf for debugging. should not use in finished code. + int (*fPrint)(const char *fmt, ...); + + // get a seed for a random number generator + int32 (*fRanSeed)(); + + // define a unit def + bool (*fDefineUnit)(char *inUnitClassName, size_t inAllocSize, + UnitCtorFunc inCtor, UnitDtorFunc inDtor, uint32 inFlags); + + // define a command /cmd + bool (*fDefinePlugInCmd)(char *inCmdName, PlugInCmdFunc inFunc, void* inUserData); + + // define a command for a unit generator /u_cmd + bool (*fDefineUnitCmd)(char *inUnitClassName, char *inCmdName, UnitCmdFunc inFunc); + + // define a buf gen + bool (*fDefineBufGen)(char *inName, BufGenFunc inFunc); + + // clear all of the unit's outputs. + void (*fClearUnitOutputs)(Unit *inUnit, int inNumSamples); + + // non real time memory allocation + void* (*fNRTAlloc)(size_t inSize); + void* (*fNRTRealloc)(void *inPtr, size_t inSize); + void (*fNRTFree)(void *inPtr); + + // real time memory allocation + void* (*fRTAlloc)(World *inWorld, size_t inSize); + void* (*fRTRealloc)(World *inWorld, void *inPtr, size_t inSize); + void (*fRTFree)(World *inWorld, void *inPtr); + + // call to set a Node to run or not. + void (*fNodeRun)(struct Node* node, int run); + + // call to stop a Graph after the next buffer. + void (*fNodeEnd)(struct Node* graph); + + // send a trigger from a Node to clients + void (*fSendTrigger)(struct Node* inNode, int triggerID, float value); + + // sending messages between real time and non real time levels. + bool (*fSendMsgFromRT)(World *inWorld, struct FifoMsg& inMsg); + bool (*fSendMsgToRT)(World *inWorld, struct FifoMsg& inMsg); + + // libsndfile support + int (*fSndFileFormatInfoFromStrings)(SF_INFO *info, + const char *headerFormatString, const char *sampleFormatString); + + // get nodes by id + struct Node* (*fGetNode)(World *inWorld, int inID); + struct Graph* (*fGetGraph)(World *inWorld, int inID); + + void (*fNRTLock)(World *inWorld); + void (*fNRTUnlock)(World *inWorld); + + bool mAltivecAvailable; + + void (*fGroup_DeleteAll)(struct Group* group); + void (*fDoneAction)(int doneAction, struct Unit *unit); + + int (*fDoAsynchronousCommand) + ( + World *inWorld, + void* replyAddr, + const char* cmdName, + void *cmdData, + AsyncStageFn stage2, // stage2 is non real time + AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true + AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true + AsyncFreeFn cleanup, + int completionMsgSize, + void* completionMsgData + ); + + + // fBufAlloc should only be called within a BufGenFunc + int (*fBufAlloc)(SndBuf *inBuf, int inChannels, int inFrames, double inSampleRate); +}; +typedef struct InterfaceTable InterfaceTable; + +#define Print (*ft->fPrint) +#define RanSeed (*ft->fRanSeed) +#define NodeEnd (*ft->fNodeEnd) +#define NodeRun (*ft->fNodeRun) +#define DefineUnit (*ft->fDefineUnit) +#define DefinePlugInCmd (*ft->fDefinePlugInCmd) +#define DefineUnitCmd (*ft->fDefineUnitCmd) +#define DefineBufGen (*ft->fDefineBufGen) +#define ClearUnitOutputs (*ft->fClearUnitOutputs) +#define SendTrigger (*ft->fSendTrigger) +#define SendMsgFromRT (*ft->fSendMsgFromRT) +#define SendMsgToRT (*ft->fSendMsgToRT) +#define DoneAction (*ft->fDoneAction) + +#define NRTAlloc (*ft->fNRTAlloc) +#define NRTRealloc (*ft->fNRTRealloc) +#define NRTFree (*ft->fNRTFree) + +#define RTAlloc (*ft->fRTAlloc) +#define RTRealloc (*ft->fRTRealloc) +#define RTFree (*ft->fRTFree) + +#define SC_GetNode (*ft->fGetNode) +#define SC_GetGraph (*ft->fGetGraph) + +#define NRTLock (*ft->fNRTLock) +#define NRTUnlock (*ft->fNRTUnlock) + +#define BufAlloc (*ft->fBufAlloc) + +#define GroupDeleteAll (*ft->fGroup_DeleteAll) + +#define SndFileFormatInfoFromStrings (*ft->fSndFileFormatInfoFromStrings) + +#define DoAsynchronousCommand (*ft->fDoAsynchronousCommand) + +#define DefineSimpleUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, 0); + +#define DefineDtorUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \ + (UnitDtorFunc)&name##_Dtor, 0); + +#define DefineSimpleCantAliasUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, 0, kUnitDef_CantAliasInputsToOutputs); + +#define DefineDtorCantAliasUnit(name) \ + (*ft->fDefineUnit)(#name, sizeof(name), (UnitCtorFunc)&name##_Ctor, \ + (UnitDtorFunc)&name##_Dtor, kUnitDef_CantAliasInputsToOutputs); + + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Node.h b/sc4pd/headers/plugin_interface/SC_Node.h new file mode 100644 index 0000000..36dd412 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Node.h @@ -0,0 +1,48 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Node_ +#define _SC_Node_ + +#include "SC_Types.h" + +typedef void (*NodeCalcFunc)(struct Node *inNode); + +struct Node +{ + int32 mID; + int32 mHash; + + struct World *mWorld; + struct NodeDef *mDef; + NodeCalcFunc mCalcFunc; + + struct Node *mPrev, *mNext; + struct Group *mParent; + + int32 mIsGroup; +}; +typedef struct Node Node; + +enum { kNode_Go, kNode_End, kNode_On, kNode_Off, kNode_Move, kNode_Info }; + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_PlugIn.h b/sc4pd/headers/plugin_interface/SC_PlugIn.h new file mode 100644 index 0000000..4f01fd3 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_PlugIn.h @@ -0,0 +1,53 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#include "SC_World.h" +#include "SC_Graph.h" +#include "SC_Unit.h" +#include "SC_Wire.h" +#include "SC_InterfaceTable.h" +#include "Unroll.h" +#include "SC_InlineUnaryOp.h" +#include "SC_InlineBinaryOp.h" +#include "SC_BoundsMacros.h" +#include "SC_RGen.h" +#include "SC_DemandUnit.h" +#include "clz.h" +#include "sc_msg_iter.h" +#include "SC_Altivec.h" +#include + +#ifdef SC_WIN32 + +// temporarily override __attribute__ for (unused), later we'll remove it +#ifndef __GCC__ +#define __attribute__(x) +#endif + +// workaround for IN/OUT conflict with Win32 headers. see SC_Unit.h for details +#define IN SC_IN +#define OUT SC_OUT + +#ifdef _MSC_VER +#include +#endif //_MSC_VER + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_RGen.h b/sc4pd/headers/plugin_interface/SC_RGen.h new file mode 100755 index 0000000..c82142b --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_RGen.h @@ -0,0 +1,288 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +//----------------------------------------------------------------------------// +// Ran088: L'Ecuyer's 1996 three-component Tausworthe generator "taus88" +//----------------------------------------------------------------------------// +// +// Returns an integer random number uniformly distributed within [0,4294967295] +// +// The period length is approximately 2^88 (which is 3*10^26). +// This generator is very fast and passes all standard statistical tests. +// +// Reference: +// (1) P. L'Ecuyer, Maximally equidistributed combined Tausworthe generators, +// Mathematics of Computation, 65, 203-213 (1996), see Figure 4. +// (2) recommended in: +// P. L'Ecuyer, Random number generation, chapter 4 of the +// Handbook on Simulation, Ed. Jerry Banks, Wiley, 1997. +// +//----------------------------------------------------------------------------// + +//----------------------------------------------------------------------------// +// I chose this random number generator for the following reasons: +// fast. +// easier and faster to seed than other high quality rng's such as Mersenne Twister. +// the internal state is only 12 bytes. +// the period is long enough for music/audio. +// possible to code in altivec in future if needed. +// - James McCartney +//----------------------------------------------------------------------------// + +#ifndef _SC_RGen_ +#define _SC_RGen_ + +#include "SC_Endian.h" +#include "SC_Types.h" +#include "SC_BoundsMacros.h" +#include "Hash.h" +#include + +struct RGen +{ + void init(uint32 seed); + + uint32 trand(); + + int32 irand(int32 scale); + int32 irand2(int32 scale); + int32 ilinrand(int32 scale); + int32 ibilinrand(int32 scale); + + float fcoin(); + float frand(); + float frand2(); + float frand0(); + float frand8(); + double drand(); + double drand2(double scale); + double linrand(double scale); + double bilinrand(double scale); + double exprandrng(double lo, double hi); + double exprand(double scale); + double biexprand(double scale); + double sum3rand(double scale); + + uint32 s1, s2, s3; // random generator state +}; + +inline void RGen::init(uint32 seed) +{ + // humans tend to use small seeds - mess up the bits + seed = (uint32)Hash((int)seed); + + // initialize seeds using the given seed value taking care of + // the requirements. The constants below are arbitrary otherwise + s1 = 1243598713U ^ seed; if (s1 < 2) s1 = 1243598713U; + s2 = 3093459404U ^ seed; if (s2 < 8) s2 = 3093459404U; + s3 = 1821928721U ^ seed; if (s3 < 16) s3 = 1821928721U; +} + +inline uint32 trand( uint32& s1, uint32& s2, uint32& s3 ) +{ + // This function is provided for speed in inner loops where the + // state variables are loaded into registers. + // Thus updating the instance variables can + // be postponed until the end of the loop. + s1 = ((s1 & -2) << 12) ^ (((s1 << 13) ^ s1) >> 19); + s2 = ((s2 & -8) << 4) ^ (((s2 << 2) ^ s2) >> 25); + s3 = ((s3 & -16) << 17) ^ (((s3 << 3) ^ s3) >> 11); + return s1 ^ s2 ^ s3; +} + +inline uint32 RGen::trand() +{ + // generate a random 32 bit number + s1 = ((s1 & -2) << 12) ^ (((s1 << 13) ^ s1) >> 19); + s2 = ((s2 & -8) << 4) ^ (((s2 << 2) ^ s2) >> 25); + s3 = ((s3 & -16) << 17) ^ (((s3 << 3) ^ s3) >> 11); + return s1 ^ s2 ^ s3; +} + +inline double RGen::drand() +{ + // return a double from 0.0 to 0.999... +#if BYTE_ORDER == BIG_ENDIAN + union { struct { uint32 hi, lo; } i; double f; } du; +#else + union { struct { uint32 lo, hi; } i; double f; } du; +#endif + du.i.hi = 0x41300000; + du.i.lo = trand(); + return du.f - 1048576.; +} + +inline float RGen::frand() +{ + // return a float from 0.0 to 0.999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3F800000 | (trand() >> 9); + return u.f - 1.f; +} + +inline float RGen::frand0() +{ + // return a float from +1.0 to +1.999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3F800000 | (trand() >> 9); + return u.f; +} + +inline float RGen::frand2() +{ + // return a float from -1.0 to +0.999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x40000000 | (trand() >> 9); + return u.f - 3.f; +} + +inline float RGen::frand8() +{ + // return a float from -0.125 to +0.124999... + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3E800000 | (trand() >> 9); + return u.f - 0.375f; +} + +inline float RGen::fcoin() +{ + // only return one of the two values -1.0 or +1.0 + union { uint32 i; float f; } u; // union for floating point conversion of result + u.i = 0x3E000000 | (0x80000000 & trand()); + return u.f; +} + +inline int32 RGen::irand(int32 scale) +{ + // return an int from 0 to scale - 1 + return (int32)floor(scale * drand()); +} + +inline int32 RGen::irand2(int32 scale) +{ + // return a int from -scale to +scale + return (int32)floor((2. * scale + 1.) * drand() - scale); +} + +inline int32 RGen::ilinrand(int32 scale) +{ + int32 a = irand(scale); + int32 b = irand(scale); + return sc_min(a,b); +} + +inline double RGen::linrand(double scale) +{ + double a = drand(); + double b = drand(); + return sc_min(a,b) * scale; +} + +inline int32 RGen::ibilinrand(int32 scale) +{ + int32 a = irand(scale); + int32 b = irand(scale); + return a - b; +} + +inline double RGen::bilinrand(double scale) +{ + double a = drand(); + double b = drand(); + return (a - b) * scale; +} + +inline double RGen::exprandrng(double lo, double hi) +{ + return lo * exp(log(hi / lo) * drand()); +} + +inline double RGen::exprand(double scale) +{ + double z; + while ((z = drand()) == 0.0) {} + return -log(z) * scale; +} + +inline double RGen::biexprand(double scale) +{ + double z; + while ((z = drand2(1.)) == 0.0 || z == -1.0) {} + if (z > 0.0) z = log(z); + else z = -log(-z); + return z * scale; +} + +inline double RGen::sum3rand(double scale) +{ + // larry polansky's poor man's gaussian generator + return (drand() + drand() + drand() - 1.5) * 0.666666667 * scale; +} + +inline double drand( uint32& s1, uint32& s2, uint32& s3 ) +{ + union { struct { uint32 hi, lo; } i; double f; } u; + u.i.hi = 0x41300000; + u.i.lo = trand(s1,s2,s3); + return u.f - 1048576.; +} + +inline float frand( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from 0.0 to 0.999... + union { uint32 i; float f; } u; + u.i = 0x3F800000 | (trand(s1,s2,s3) >> 9); + return u.f - 1.f; +} + +inline float frand0( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from +1.0 to +1.999... + union { uint32 i; float f; } u; + u.i = 0x3F800000 | (trand(s1,s2,s3) >> 9); + return u.f; +} + +inline float frand2( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from -1.0 to +0.999... + union { uint32 i; float f; } u; + u.i = 0x40000000 | (trand(s1,s2,s3) >> 9); + return u.f - 3.f; +} + +inline float frand8( uint32& s1, uint32& s2, uint32& s3 ) +{ + // return a float from -0.125 to +0.124999... + union { uint32 i; float f; } u; + u.i = 0x3E800000 | (trand(s1,s2,s3) >> 9); + return u.f - 0.375f; +} + +inline float fcoin( uint32& s1, uint32& s2, uint32& s3 ) +{ + // only return one of the two values -1.0 or +1.0 + union { uint32 i; float f; } u; + u.i = 0x3F800000 | (0x80000000 & trand(s1,s2,s3)); + return u.f; +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_Rate.h b/sc4pd/headers/plugin_interface/SC_Rate.h new file mode 100644 index 0000000..63c160d --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Rate.h @@ -0,0 +1,42 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _Rate_ +#define _Rate_ + +enum { calc_ScalarRate, calc_BufRate, calc_FullRate, calc_DemandRate }; + +struct Rate +{ + double mSampleRate; // samples per second + double mSampleDur; // seconds per sample + double mBufDuration; // seconds per buffer + double mBufRate; // buffers per second + double mSlopeFactor; // 1. / NumSamples + double mRadiansPerSample; // 2pi / SampleRate + int mBufLength; // length of the buffer + // second order filter loops are often unrolled by 3 + int mFilterLoops, mFilterRemain; + double mFilterSlope; +}; +typedef struct Rate Rate; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_SndBuf.h b/sc4pd/headers/plugin_interface/SC_SndBuf.h new file mode 100644 index 0000000..affd2b9 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_SndBuf.h @@ -0,0 +1,109 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SndBuf_ +#define _SndBuf_ + +#include +#include + +struct SndBuf +{ + double samplerate; + double sampledur; // = 1/ samplerate + float *data; + int channels; + int samples; + int frames; + int mask; // for delay lines + int mask1; // for interpolating oscillators. + int coord; // used by fft ugens + SNDFILE *sndfile; // used by disk i/o +}; +typedef struct SndBuf SndBuf; + +struct SndBufUpdates +{ + int reads; + int writes; +}; +typedef struct SndBufUpdates SndBufUpdates; + +enum { coord_None, coord_Complex, coord_Polar }; + + +inline float PhaseFrac(unsigned long inPhase) + { + union { unsigned long itemp; float ftemp; } u; + u.itemp = 0x3F800000 | (0x007FFF80 & ((inPhase)<<7)); + return u.ftemp - 1.f; + } + +inline float PhaseFrac1(unsigned long inPhase) + { + union { unsigned long itemp; float ftemp; } u; + u.itemp = 0x3F800000 | (0x007FFF80 & ((inPhase)<<7)); + return u.ftemp; + } + +inline float lookup(float *table, int32 phase, int32 mask) +{ + return table[(phase >> 16) & mask]; +} + + +#define xlobits 14 +#define xlobits1 13 + +inline float lookupi(float *table, uint32 phase, uint32 mask) +{ + float frac = PhaseFrac(phase); + float *tbl = table + ((phase >> 16) & mask); + float a = tbl[0]; + float b = tbl[1]; + return a + frac * (b - a); +} + +inline float lookupi2(float *table, uint32 phase, uint32 mask) +{ + float frac = PhaseFrac1(phase); + float *tbl = table + ((phase >> 16) & mask); + float a = tbl[0]; + float b = tbl[1]; + return a + frac * b; +} + +inline float lookupi1(float* table0, float* table1, uint32 pphase, int32 lomask) +{ + float pfrac = PhaseFrac1(pphase); + uint32 index = ((pphase >> xlobits1) & lomask); + float val1 = *(float*)((char*)table0 + index); + float val2 = *(float*)((char*)table1 + index); + return val1 + val2 * pfrac; +} + + +inline float lininterp(float x, float a, float b) +{ + return a + x * (b - a); +} + + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Types.h b/sc4pd/headers/plugin_interface/SC_Types.h new file mode 100755 index 0000000..d635b07 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Types.h @@ -0,0 +1,67 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_Types_ +#define _SC_Types_ + +#include + +typedef int SCErr; + +#ifdef SC_WIN32 +typedef __int64 int64; +typedef unsigned __int64 uint64; +#else +typedef long long int64; +typedef unsigned long long uint64; +#endif + +typedef int int32; +typedef unsigned int uint32; +#ifdef SC_DARWIN +typedef unsigned int ulong; +#endif + +typedef short int16; +typedef unsigned short uint16; + +typedef signed char int8; +typedef unsigned char uint8; + +typedef float float32; +typedef double float64; + +typedef union { + uint32 u; + int32 i; + float32 f; +} elem32; + +typedef union { + uint64 u; + int64 i; + float64 f; +} elem64; + +const unsigned int kSCNameLen = 8; +const unsigned int kSCNameByteLen = kSCNameLen * sizeof(int32); + +#endif + diff --git a/sc4pd/headers/plugin_interface/SC_Unit.h b/sc4pd/headers/plugin_interface/SC_Unit.h new file mode 100644 index 0000000..2ded017 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Unit.h @@ -0,0 +1,101 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Unit_ +#define _SC_Unit_ + +#include "SC_Types.h" + +typedef void (*UnitCtorFunc)(struct Unit* inUnit); +typedef void (*UnitDtorFunc)(struct Unit* inUnit); + +typedef void (*UnitCalcFunc)(struct Unit *inThing, int inNumSamples); + +struct Unit +{ + struct World *mWorld; + struct UnitDef *mUnitDef; + struct Graph *mParent; + uint16 mNumInputs, mNumOutputs; + int16 mCalcRate; + int16 mSpecialIndex; // used by unary and binary ops + int16 mParentIndex; + int16 mDone; + + struct Wire **mInput, **mOutput; + struct Rate *mRate; + struct SC_Dimension *mDimension; + float **mInBuf, **mOutBuf; + + UnitCalcFunc mCalcFunc; + int mBufLength; +}; +typedef struct Unit Unit; + +enum { + kUnitDef_CantAliasInputsToOutputs = 1 +}; + +// easy macros, the unit variable must be named 'unit'. +#ifndef SC_WIN32 + +// These return float* pointers to input and output buffers. +#define IN(index) (unit->mInBuf[index]) +#define OUT(index) (unit->mOutBuf[index]) + +// These return a float value. Used for control rate inputs and outputs. +#define IN0(index) (IN(index)[0]) +#define OUT0(index) (OUT(index)[0]) + +#else + +// Win32 headers (included by C std library headers) define IN and OUT macros +// for their own purposes. To avoid problems we don't define IN and OUT here +// but define SC_IN and SC_OUT instead. Source files that use IN and OUT need +// to include definitions of IN, and OUT referencing SC_IN and SC_OUT after +// all headers have been included. +#define SC_IN(index) (unit->mInBuf[index]) +#define SC_OUT(index) (unit->mOutBuf[index]) +#define IN0(index) (SC_IN(index)[0]) +#define OUT0(index) (SC_OUT(index)[0]) + +#endif + +// get the rate of the input. +#define INRATE(index) (unit->mInput[index]->mCalcRate) + +// set the calculation function +#define SETCALC(func) (unit->mCalcFunc = (UnitCalcFunc)&func) + +// calculate a slope for control rate interpolation to audio rate. +#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor) + +// get useful values +#define SAMPLERATE (unit->mRate->mSampleRate) +#define SAMPLEDUR (unit->mRate->mSampleDur) +#define BUFLENGTH (unit->mBufLength) +#define BUFRATE (unit->mRate->mBufRate) +#define BUFDUR (unit->mRate->mBufDuration) + +typedef void (*UnitCmdFunc)(struct Unit *unit, struct sc_msg_iter *args); +typedef void (*PlugInCmdFunc)(World *inWorld, void* inUserData, struct sc_msg_iter *args, void *replyAddr); + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_Wire.h b/sc4pd/headers/plugin_interface/SC_Wire.h new file mode 100644 index 0000000..f2680ac --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_Wire.h @@ -0,0 +1,36 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Wire_ +#define _SC_Wire_ + +#include "SC_Types.h" + +struct Wire +{ + struct Unit *mFromUnit; + int32 mCalcRate; + float32 *mBuffer; + float32 mScalarValue; +}; +typedef struct Wire Wire; + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_World.h b/sc4pd/headers/plugin_interface/SC_World.h new file mode 100644 index 0000000..8586432 --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_World.h @@ -0,0 +1,105 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_World_ +#define _SC_World_ + +#include "SC_Types.h" +#include "SC_Rate.h" +#include "SC_SndBuf.h" +#include "SC_RGen.h" +#include "SC_Lock.h" + +struct World +{ + // a pointer to private implementation, not available to plug-ins. + struct HiddenWorld *hw; + + // a pointer to the table of function pointers that implement the plug-ins' + // interface to the server. + struct InterfaceTable *ft; + + // data accessible to plug-ins : + double mSampleRate; + int mBufLength; + int mBufCounter; + + uint32 mNumAudioBusChannels; + uint32 mNumControlBusChannels; + uint32 mNumInputs; + uint32 mNumOutputs; + + // vector of samples for all audio busses + float *mAudioBus; + + // vector of samples for all control busses + float *mControlBus; + + // these tell if a buss has been written to during a control period + // if the value is equal to mBufCounter then the buss has been touched + // this control period. + int32 *mAudioBusTouched; + int32 *mControlBusTouched; + + uint32 mNumSndBufs; + SndBuf *mSndBufs; + SndBuf *mSndBufsNonRealTimeMirror; + SndBufUpdates *mSndBufUpdates; + + struct Group *mTopGroup; + + Rate mFullRate, mBufRate; + + uint32 mNumRGens; + RGen *mRGen; + + uint32 mNumUnits, mNumGraphs, mNumGroups; + int mSampleOffset; // offset in the buffer of current event time. + + SC_Lock* mNRTLock; + + uint32 mNumSharedControls; + float *mSharedControls; + + bool mRealTime; + bool mRunning; + int mDumpOSC; +}; + +extern "C" { + int scprintf(const char *fmt, ...); +} + +inline SndBuf* World_GetBuf(struct World *inWorld, uint32 index) +{ + if (index > inWorld->mNumSndBufs) index = 0; + return inWorld->mSndBufs + index; +} + +inline SndBuf* World_GetNRTBuf(struct World *inWorld, uint32 index) +{ + if (index > inWorld->mNumSndBufs) index = 0; + return inWorld->mSndBufsNonRealTimeMirror + index; +} + +typedef void (*LoadPlugInFunc)(struct InterfaceTable *); + +#endif diff --git a/sc4pd/headers/plugin_interface/SC_WorldOptions.h b/sc4pd/headers/plugin_interface/SC_WorldOptions.h new file mode 100644 index 0000000..b04850f --- /dev/null +++ b/sc4pd/headers/plugin_interface/SC_WorldOptions.h @@ -0,0 +1,91 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_WorldOptions_ +#define _SC_WorldOptions_ + +#include +#include "SC_Types.h" + +typedef int (*PrintFunc)(const char *format, va_list ap); + +struct WorldOptions +{ + const char* mPassword; + uint32 mNumBuffers; + uint32 mMaxLogins; + uint32 mMaxNodes; + uint32 mMaxGraphDefs; + uint32 mMaxWireBufs; + uint32 mNumAudioBusChannels; + uint32 mNumInputBusChannels; + uint32 mNumOutputBusChannels; + uint32 mNumControlBusChannels; + uint32 mBufLength; + uint32 mRealTimeMemorySize; + + int mNumSharedControls; + float *mSharedControls; + + bool mRealTime; + + const char *mNonRealTimeCmdFilename; + const char *mNonRealTimeInputFilename; + const char *mNonRealTimeOutputFilename; + const char *mNonRealTimeOutputHeaderFormat; + const char *mNonRealTimeOutputSampleFormat; + + uint32 mPreferredSampleRate; + uint32 mNumRGens; + + uint32 mPreferredHardwareBufferFrameSize; + + uint32 mLoadGraphDefs; + +#ifdef SC_DARWIN + const char *mInputStreamsEnabled; + const char *mOutputStreamsEnabled; +#endif +}; + +const WorldOptions kDefaultWorldOptions = +{ + 0,1024,64,1024,1024,64,128,8,8,4096,64,8192, 0,0, 1, 0,0,0,0,0, 0, 64, 0, 1 +#ifdef SC_DARWIN + ,0,0 +#endif +}; + +#include "SC_Reply.h" + +extern "C" { + void SetPrintFunc(PrintFunc func); + struct World* World_New(WorldOptions *inOptions); + void World_OpenUDP(struct World *inWorld, int inPort); + void World_OpenTCP(struct World *inWorld, int inPort, int inMaxConnections, int inBacklog); + void World_WaitForQuit(struct World *inWorld); + bool World_SendPacket(struct World *inWorld, int inSize, char *inData, ReplyFunc inFunc); + int World_CopySndBuf(World *world, uint32 index, struct SndBuf *outBuf, bool onlyIfChanged, bool &didChange); + int scprintf(const char *fmt, ...); +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/Unroll.h b/sc4pd/headers/plugin_interface/Unroll.h new file mode 100644 index 0000000..12ae864 --- /dev/null +++ b/sc4pd/headers/plugin_interface/Unroll.h @@ -0,0 +1,249 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +These macros allow one to write code which can be compiled optimally depending on +what loop constructs the compiler can best generate code. + +*/ + +#ifndef _Unroll_ +#define _Unroll_ + +#if 1 + +// loop type +#define FOR_IS_FASTER 1 +#define WHILE_IS_FASTER 0 +// indexing type +#define PREINCREMENT_IS_FASTER 1 +#define POSTINCREMENT_IS_FASTER 0 + +#else + +// loop type +#define FOR_IS_FASTER 1 +#define WHILE_IS_FASTER 0 +// indexing type +#define PREINCREMENT_IS_FASTER 0 +#define POSTINCREMENT_IS_FASTER 1 + +#endif + + +// LOOPING MACROS : + +#if FOR_IS_FASTER + +#define LOOP(length, stmt) for (int xxi=0; xxi<(length); ++xxi) { stmt; } + +#elif WHILE_IS_FASTER + +#define LOOP(length, stmt) \ + { int xxn = (length); \ + while (--xxn) { \ + stmt; \ + } \ + } + +#endif + + + +// above macros are not friendly to the debugger +#if FOR_IS_FASTER + +#define LooP(length) for (int xxi=0; xxi<(length); ++xxi) + +#elif WHILE_IS_FASTER + +#define LooP(length) for (int xxi=(length); --xxi;) + +#endif + + +// LOOP INDEXING : + +/* +meanings of the indexing macros: + ZXP = dereference and pre or post increment + ZX = dereference + PZ = preincrement (if applicable) + ZP = postincrement (if applicable) + ZOFF = offset from the pointer of the first element of the array + (preincrement requires a ZOFF of 1 which is pre-subtracted from the + base pointer. For other indexing types ZOFF is zero) +*/ + +#if PREINCREMENT_IS_FASTER +#define ZXP(z) (*++(z)) +#define ZX(z) (*(z)) +#define PZ(z) (++(z)) +#define ZP(z) (z) +#define ZOFF (1) +#elif POSTINCREMENT_IS_FASTER +#define ZXP(z) (*(z)++) +#define ZX(z) (*(z)) +#define PZ(z) (z) +#define ZP(z) ((z)++) +#define ZOFF (0) +#endif + +// ACCESSING INLETS AND OUTLETS : + +// unit inputs +#define ZIN(i) (IN(i) - ZOFF) // get buffer pointer offset for iteration +#define ZIN0(i) (IN(i)[0]) // get first sample + +// unit outputs +#define ZOUT(i) (OUT(i) - ZOFF) // get buffer pointer offset for iteration +#define ZOUT0(i) (OUT(i)[0]) // get first sample + +#include "SC_BoundsMacros.h" + +#ifndef NDEBUG +# define NDEBUG +#endif +#include + +inline void Clear(int numSamples, float *out) +{ + //assert((((long)(out+ZOFF) & 7) == 0)); // pointer must be 8 byte aligned + + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)out - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = 0.; ); + } else { + out -= ZOFF; + LOOP(numSamples, ZXP(out) = 0.f; ); + } +} + +inline void Copy(int numSamples, float *out, float *in) +{ + // pointers must be 8 byte aligned + //assert((((long)(out+ZOFF) & 7) == 0) && (((long)(in+ZOFF) & 7) == 0)); + if (in == out) return; + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)out - ZOFF; + double *ind = (double*)in - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = ZXP(ind); ); + } else { + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) = ZXP(in); ); + } +} + +inline void Fill(int numSamples, float *out, float level) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) = level; ); +} + +inline void Fill(int numSamples, float *out, float level, float slope) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) = level; level += slope; ); +} + +inline void Accum(int numSamples, float *out, float *in) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) += ZXP(in); ); +} + +inline void Scale(int numSamples, float *out, float level) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) *= level;); +} + +inline float Scale(int numSamples, float *out, float level, float slope) +{ + out -= ZOFF; + LOOP(numSamples, ZXP(out) *= level; level += slope;); + return level; +} + +inline float Scale(int numSamples, float *out, float *in, float level, float slope) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) = ZXP(in) * level; level += slope;); + return level; +} + +inline float ScaleMix(int numSamples, float *out, float *in, float level, float slope) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) += ZXP(in) * level; level += slope;); + return level; +} + +inline void Scale(int numSamples, float *out, float *in, float level) +{ + in -= ZOFF; + out -= ZOFF; + LOOP(numSamples, ZXP(out) = ZXP(in) * level; ); +} + +// in these the pointers are assumed to already have been pre-offset. +inline void ZCopy(int numSamples, float *out, float *in) +{ + // pointers must be 8 byte aligned + //assert((((long)(out+ZOFF) & 7) == 0) && (((long)(in+ZOFF) & 7) == 0)); + if (in == out) return; + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)(out + ZOFF) - ZOFF; + double *ind = (double*)(in + ZOFF) - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = ZXP(ind); ); + } else { + LOOP(numSamples, ZXP(out) = ZXP(in); ); + } +} + +inline void ZClear(int numSamples, float *out) +{ + // pointers must be 8 byte aligned + //assert((((long)(out+ZOFF) & 7) == 0) && (((long)(in+ZOFF) & 7) == 0)); + if ((numSamples & 1) == 0) { + // copying doubles is faster on powerpc. + double *outd = (double*)(out + ZOFF) - ZOFF; + LOOP(numSamples >> 1, ZXP(outd) = 0.; ); + } else { + LOOP(numSamples, ZXP(out) = 0.f; ); + } +} + +inline void ZAccum(int numSamples, float *out, float *in) +{ + LOOP(numSamples, ZXP(out) += ZXP(in); ); +} + + + +#endif diff --git a/sc4pd/headers/plugin_interface/clz.h b/sc4pd/headers/plugin_interface/clz.h new file mode 100755 index 0000000..f205c02 --- /dev/null +++ b/sc4pd/headers/plugin_interface/clz.h @@ -0,0 +1,195 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + +count leading zeroes function and those that can be derived from it + +*/ + + +#ifndef _CLZ_ +#define _CLZ_ + +#include "SC_Types.h" + +#ifdef __MWERKS__ + +#define __PPC__ 1 +#define __X86__ 0 + +// powerpc native count leading zeroes instruction: +#define CLZ(x) ((int)__cntlzw((unsigned int)x)) + +#elif defined(SC_WIN32) && !defined(__GCC__) + +static int32 CLZ( int32 arg ) +{ + __asm{ + bsr eax, arg + jnz non_zero + mov arg, 32 + jmp end +non_zero: + xor eax, 31 + mov arg, eax +end: + } + return arg; +} + +#elif defined(__ppc__) || defined(__powerpc__) || defined(__PPC__) + +static __inline__ int32 CLZ(int32 arg) { + __asm__ volatile("cntlzw %0, %1" : "=r" (arg) : "r" (arg)); + return arg; +} + +#elif defined(__i386__) || defined(__x86_64__) +static __inline__ int32 CLZ(int32 arg) { + if (arg) { + __asm__ volatile("bsrl %0, %0\nxorl $31, %0\n" + : "=r" (arg) : "0" (arg)); + } else { + arg = 32; + } + return arg; +} + +#else +# error "clz.h: Unsupported architecture" +#endif + +// count trailing zeroes +inline int32 CTZ(int32 x) +{ + return 32 - CLZ(~x & (x-1)); +} + +// count leading ones +inline int32 CLO(int32 x) +{ + return CLZ(~x); +} + +// count trailing ones +inline int32 CTO(int32 x) +{ + return 32 - CLZ(x & (~x-1)); +} + +// number of bits required to represent x. +inline int32 NUMBITS(int32 x) +{ + return 32 - CLZ(x); +} + +// log2 of the next power of two greater than or equal to x. +inline int32 LOG2CEIL(int32 x) +{ + return 32 - CLZ(x - 1); +} + +// next power of two greater than or equal to x +inline int32 NEXTPOWEROFTWO(int32 x) +{ + return 1L << LOG2CEIL(x); +} + +// is x a power of two +inline bool ISPOWEROFTWO(int32 x) +{ + return (x & (x-1)) == 0; +} + +// input a series of counting integers, outputs a series of gray codes . +inline int32 GRAYCODE(int32 x) +{ + return x & (x>>1); +} + +// find least significant bit +inline int32 LSBit(int32 x) +{ + return x & -x; +} + +// find least significant bit position +inline int32 LSBitPos(int32 x) +{ + return CTZ(x & -x); +} + +// find most significant bit position +inline int32 MSBitPos(int32 x) +{ + return 31 - CLZ(x); +} + +// find most significant bit +inline int32 MSBit(int32 x) +{ + return 1L << MSBitPos(x); +} + +// count number of one bits +inline uint32 ONES(uint32 x) +{ + uint32 t; + x = x - ((x >> 1) & 0x55555555); + t = ((x >> 2) & 0x33333333); + x = (x & 0x33333333) + t; + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x << 8); + x = x + (x << 16); + return x >> 24; +} + +// count number of zero bits +inline uint32 ZEROES(uint32 x) +{ + return ONES(~x); +} + + +// reverse bits in a word +inline uint32 BitReverse(uint32 x) +{ + x = ((x & 0xAAAAAAAA) >> 1) | ((x & 0x55555555) << 1); + x = ((x & 0xCCCCCCCC) >> 2) | ((x & 0x33333333) << 2); + x = ((x & 0xF0F0F0F0) >> 4) | ((x & 0x0F0F0F0F) << 4); + x = ((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8); + return (x >> 16) | (x << 16); +} + +// barrel shifts +inline uint32 RotateRight (uint32 x, uint32 s) +{ + s = s & 31; + return (x << (32-s)) | (x >> s); +} + +inline uint32 RotateLeft (uint32 x, uint32 s) +{ + s = s & 31; + return (x >> (32-s)) | (x << s); +} + +#endif + diff --git a/sc4pd/headers/plugin_interface/sc_msg_iter.h b/sc4pd/headers/plugin_interface/sc_msg_iter.h new file mode 100644 index 0000000..240a30f --- /dev/null +++ b/sc4pd/headers/plugin_interface/sc_msg_iter.h @@ -0,0 +1,264 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _sc_msg_iter_ +#define _sc_msg_iter_ + +#include "SC_Endian.h" +#include "SC_Types.h" +#include + +// return the ptr to the byte after the OSC string. +inline char* OSCstrskip(char *str) +{ +// while (str[3]) { str += 4; } +// return str + 4; + do { str += 4; } while (str[-1]); + return str; +} + +// returns the number of bytes (including padding) for an OSC string. +inline int OSCstrlen(char *strin) +{ + return OSCstrskip(strin) - strin; +} + +// returns a float, converting an int if necessary +inline float32 OSCfloat(char* inData) +{ + elem32* elem = (elem32*)inData; + elem->u = ntohl(elem->u); + return elem->f; +} + +inline int32 OSCint(char* inData) +{ + return (int32)ntohl(*(uint32*)inData); +} + +inline int64 OSCtime(char* inData) +{ + return ((int64)ntohl(*(uint32*)inData) << 32) + (ntohl(*(uint32*)(inData + 4))); +} + +inline float64 OSCdouble(char* inData) +{ + elem64 slot; + slot.i = ((int64)ntohl(*(uint32*)inData) << 32) + (ntohl(*(uint32*)(inData + 4))); + return slot.f; +} + +struct sc_msg_iter +{ + char *data, *rdpos, *endpos, *tags; + int size, count; + + sc_msg_iter(); + sc_msg_iter(int inSize, char* inData); + void init(int inSize, char* inData); + int32 geti(int32 defaultValue = 0); + float32 getf(float32 defaultValue = 0.f); + float64 getd(float64 defaultValue = 0.f); + char *gets(char* defaultValue = 0); + int32 *gets4(char* defaultValue = 0); + size_t getbsize(); + void getb(char* outData, size_t inSize); + void skipb(); + int remain() { return endpos - rdpos; } + + char nextTag(char defaultTag = 'f') { return tags ? tags[count] : defaultTag; } +}; + +inline sc_msg_iter::sc_msg_iter() +{ +} + +inline sc_msg_iter::sc_msg_iter(int inSize, char* inData) +{ + init(inSize, inData); +} + +inline void sc_msg_iter::init(int inSize, char* inData) +{ + data = inData; + size = inSize; + endpos = data + size; + count = 0; + if (data[0] == ',') { + tags = data+1; + rdpos = OSCstrskip(data); + } else { + tags = 0; + rdpos = data; + } +} + +inline int32 sc_msg_iter::geti(int32 defaultValue) +{ + int value; + if (remain() <= 0) return defaultValue; + if (tags) { + if (tags[count] == 'i') { + value = OSCint(rdpos); + rdpos += sizeof(int32); + } else if (tags[count] == 'f') { + value = (int32)OSCfloat(rdpos); + rdpos += sizeof(float32); +/* } else if (tags[count] == 's') { + value = atoi(rdpos); + rdpos = OSCstrskip(rdpos); +*/ + } else { + value = defaultValue; + } + } else { + value = (int)OSCint(rdpos); + rdpos += sizeof(int32); + } + count ++; + return value; +} + +inline float32 sc_msg_iter::getf(float32 defaultValue) +{ + float32 value; + if (remain() <= 0) return defaultValue; + if (tags) { + if (tags[count] == 'f') { + value = OSCfloat(rdpos); + rdpos += sizeof(float32); + } else if (tags[count] == 'd') { + value = (float64)OSCdouble(rdpos); + rdpos += sizeof(float64); + } else if (tags[count] == 'i') { + value = (float32)OSCint(rdpos); + rdpos += sizeof(int32); +/* } else if (tags[count] == 's') { + value = atof(rdpos); + rdpos = OSCstrskip(rdpos); +*/ + } else { + value = defaultValue; + } + } else { + value = OSCfloat(rdpos); + rdpos += sizeof(float32); + } + count ++; + return value; +} + +inline float64 sc_msg_iter::getd(float64 defaultValue) +{ + float64 value; + if (remain() <= 0) return defaultValue; + if (tags) { + if (tags[count] == 'f') { + value = (float64)OSCfloat(rdpos); + rdpos += sizeof(float32); + } else if (tags[count] == 'd') { + value = OSCdouble(rdpos); + rdpos += sizeof(float64); + } else if (tags[count] == 'i') { + value = (float64)OSCint(rdpos); + rdpos += sizeof(int32); +/* } else if (tags[count] == 's') { + value = atof(rdpos); + rdpos = OSCstrskip(rdpos); +*/ + } else { + value = defaultValue; + } + } else { + value = OSCdouble(rdpos); + rdpos += sizeof(float64); + } + count ++; + return value; +} + + +inline char* sc_msg_iter::gets(char* defaultValue) +{ + char* value; + if (remain() <= 0) return 0; + if (tags) { + if (tags[count] == 's') { + value = rdpos; + rdpos = OSCstrskip(rdpos); + } else { + value = defaultValue; + } + } else { + value = rdpos; + rdpos = OSCstrskip(rdpos); + } + count ++; + return value; +} + +inline int32* sc_msg_iter::gets4(char* defaultValue) +{ + int32* value; + if (remain() <= 0) return 0; + if (tags) { + if (tags[count] == 's') { + value = (int32*)rdpos; + rdpos = OSCstrskip(rdpos); + } else { + value = (int32*)defaultValue; + } + } else { + value = (int32*)rdpos; + rdpos = OSCstrskip(rdpos); + } + count ++; + return value; +} + +inline size_t sc_msg_iter::getbsize() +{ + if (remain() <= 0) return 0; + if (tags && tags[count] != 'b') return 0; + return (size_t)OSCint(rdpos); +} + +inline void sc_msg_iter::getb(char* outArray, size_t size) +{ + size_t len = OSCint(rdpos); + if (size < len) return; + rdpos += sizeof(int32); + size_t len4 = (len + 3) & -4; + memcpy(outArray, rdpos, size); + rdpos += len4; + count ++; +} + +inline void sc_msg_iter::skipb() +{ + size_t len = OSCint(rdpos); + rdpos += sizeof(int32); + size_t len4 = (len + 3) & -4; + rdpos += len4; + count ++; +} + +#endif diff --git a/sc4pd/headers/server/HashTable.h b/sc4pd/headers/server/HashTable.h new file mode 100755 index 0000000..85da92c --- /dev/null +++ b/sc4pd/headers/server/HashTable.h @@ -0,0 +1,356 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _HashTable_ +#define _HashTable_ + +#include "SC_Types.h" +#include "SC_BoundsMacros.h" +#include "SC_Str4.h" +#include "Hash.h" +#include +#include +#include + +template +class HashTable +{ + Allocator *mPool; + int32 mNumItems, mMaxItems, mTableSize, mHashMask; + T** mItems; + bool mCanResize; + +public: + + HashTable(Allocator *inPool, int32 inMaxItems, bool inCanResize = true) + : mPool(inPool) + { + mNumItems = 0; + mMaxItems = inMaxItems; + mTableSize = mMaxItems << 1; + mItems = AllocTable(mTableSize); + mHashMask = mTableSize - 1; + mCanResize = inCanResize; + } + + ~HashTable() { + mPool->Free(mItems); + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return mMaxItems; } + int32 NumItems() const { return mNumItems; } + + T** AllocTable(int inTableSize) + { + size_t size = inTableSize * sizeof(T*); + T** items = static_cast(mPool->Alloc(size)); + for (int i=0; i> 1; + mHashMask = mTableSize - 1; + mNumItems = 0; + for (int i=0; iFree(oldItems); + //printf("mMaxItems %d mTableSize %d newSize %d\n", mMaxItems, mTableSize, newSize); + } + + bool Add(T* inItem) + { + //printf("mNumItems %d\n", mNumItems); + //printf("mMaxItems %d\n", mMaxItems); + //printf("mCanResize %d\n", mCanResize); + if (mNumItems >= mMaxItems) { + if (!mCanResize) return false; + Resize(); + } + + //printf("GetHash(inItem) %d\n", GetHash(inItem)); + //printf("GetKey(inItem) %s\n", GetKey(inItem)); + int32 index = IndexFor(GetHash(inItem), (int32*)GetKey(inItem)); + //printf("index %d\n", index); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), (int32*)GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + bool RemoveKey(int32* inKey) + { + T* item = Get(inKey); + if (!item) return false; + return Remove(item); + } + + int32 IndexFor(int32 inHashID, int32* inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID && str4eq(inKey, GetKey(item))) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(int32* inKey) const + { + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, int32* inKey) const + { + //printf("Get hash %d %s\n", inHashID, inKey); + int32 index = IndexFor(inHashID, inKey); + //printf("index %d\n", index); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + +private: + void FixCollisionsFrom(int32 inIndex) + { + int oldIndex = inIndex; + for (;;) { + oldIndex = (oldIndex + 1) & mHashMask; + T *oldItem = mItems[oldIndex]; + if (!oldItem) break; + int newIndex = IndexFor(GetHash(oldItem), (int32*)GetKey(oldItem)); + if (oldIndex != newIndex) { + mItems[oldIndex] = mItems[newIndex]; + mItems[newIndex] = oldItem; + } + } + } +}; + + +template +class IntHashTable +{ + Allocator *mPool; + int32 mNumItems, mMaxItems, mTableSize, mHashMask; + T** mItems; + bool mCanResize; + +public: + + IntHashTable(Allocator *inPool, int32 inMaxItems, bool inCanResize = true) + : mPool(inPool) + { + mNumItems = 0; + mMaxItems = inMaxItems; + mTableSize = mMaxItems << 1; + mItems = AllocTable(mTableSize); + mHashMask = mTableSize - 1; + mCanResize = inCanResize; + } + + ~IntHashTable() { + mPool->Free(mItems); + } + + int32 TableSize() const { return mTableSize; } + int32 MaxItems() const { return mMaxItems; } + int32 NumItems() const { return mNumItems; } + + T** AllocTable(int inTableSize) + { + size_t size = inTableSize * sizeof(T*); + T** items = static_cast(mPool->Alloc(size)); + for (int i=0; i> 1; + mHashMask = mTableSize - 1; + mPool->Free(oldItems); + //printf("mMaxItems %d mTableSize %d newSize %d\n", mMaxItems, mTableSize, newSize); + } + + bool Add(T* inItem) + { + //printf("mNumItems %d\n", mNumItems); + //printf("mMaxItems %d\n", mMaxItems); + //printf("mCanResize %d\n", mCanResize); + if (mNumItems >= mMaxItems) { + if (!mCanResize) return false; + Resize(); + } + + //printf("GetHash(inItem) %d\n", GetHash(inItem)); + //printf("GetKey(inItem) %d\n", GetKey(inItem)); + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + //printf("index %d\n", index); + + T *item = mItems[index]; + if (item) return item == inItem; + + mItems[index] = inItem; + mNumItems++; + return true; + } + + bool Remove(T* inItem) + { + int32 index = IndexFor(GetHash(inItem), GetKey(inItem)); + //printf("rmv index %d hash %d key %d\n", index, GetHash(inItem), GetKey(inItem)); + if (mItems[index] != inItem) return false; + mItems[index] = 0; + + FixCollisionsFrom(index); + mNumItems--; + return true; + } + + bool RemoveKey(int32 inKey) + { + T* item = Get(inKey); + if (!item) return false; + return Remove(item); + } + + int32 IndexFor(int32 inHashID, int32 inKey) const + { + int index = inHashID & mHashMask; + for(;;) { + T *item = mItems[index]; + if (!item) return index; + if (GetHash(item) == inHashID && inKey == GetKey(item)) return index; + index = (index + 1) & mHashMask; + } + } + + T* Get(int32 inKey) const + { + //printf("Get key %d\n", inKey); + return Get(Hash(inKey), inKey); + } + + T* Get(int32 inHashID, int32 inKey) const + { + int32 index = IndexFor(inHashID, inKey); + //printf("Get index %d hash %d key %d\n", index, inHashID, inKey); + return mItems[index]; + } + + bool Includes(T* inItem) const + { + return Get(GetHash(inItem), GetKey(inItem)) == inItem; + } + + T* AtIndex(int32 inIndex) const + { + return mItems[inIndex]; + } + + void Dump() + { + for (int i=0; i +#endif + +template +class IntFifo +{ +public: + IntFifo() + : mMask(N - 1), mReadHead(0), mWriteHead(0) + {} + + void MakeEmpty() { mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + bool HasData() { return mReadHead != mWriteHead; } + + bool Put(int data) + { + long next = NextPos(mWriteHead); + if (next == mReadHead) return false; // fifo is full + mItems[next] = data; +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mWriteHead, next, &mWriteHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mWriteHead),next); +#else + mWriteHead = next; +#endif + return true; + } + + int32 Get() + { + //assert(HasData()); + long next = NextPos(mReadHead); + out = mItems[next].Perform(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mReadHead, next, &mReadHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mReadHead),next); +#else + mReadHead = next; +#endif + } + +private: + int NextPos(int inPos) { return (inPos + 1) & mMask; } + + long mMask; +#ifdef SC_DARWIN + UInt32 mReadHead, mWriteHead; +#else + volatile int mReadHead, mWriteHead; +#endif + int32 mItems[N]; +}; + +#endif + + diff --git a/sc4pd/headers/server/MsgFifo.h b/sc4pd/headers/server/MsgFifo.h new file mode 100755 index 0000000..cdc8578 --- /dev/null +++ b/sc4pd/headers/server/MsgFifo.h @@ -0,0 +1,169 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _MsgFifo_ +#define _MsgFifo_ + +#ifdef SC_DARWIN +# include +#endif + +///////////////////////////////////////////////////////////////////// + +template +class MsgFifo +{ +public: + MsgFifo() + : mReadHead(0), mWriteHead(0), mFreeHead(0) + {} + + void MakeEmpty() { mFreeHead = mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + bool HasData() { return mReadHead != mWriteHead; } + bool NeedsFree() { return mFreeHead != mReadHead; } + + bool Write(MsgType& data) + { + unsigned int next = NextPos(mWriteHead); + if (next == mFreeHead) return false; // fifo is full + mItems[next] = data; +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mWriteHead, next, &mWriteHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mWriteHead),next); +#else + mWriteHead = next; +#endif + return true; + } + + void Perform() // get next and advance + { + while (HasData()) { + unsigned int next = NextPos(mReadHead); + mItems[next].Perform(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mReadHead, next, &mReadHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mReadHead),next); +#else + mReadHead = next; +#endif + } + } + void Free() // reclaim messages + { + while (NeedsFree()) { + unsigned int next = NextPos(mFreeHead); + mItems[next].Free(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mFreeHead, next, &mFreeHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mFreeHead),next); +#else + mFreeHead = next; +#endif + } + } + +private: + int NextPos(int inPos) { return (inPos + 1) & (N - 1); } + +#ifdef SC_DARWIN + UInt32 mReadHead, mWriteHead, mFreeHead; +#else + volatile unsigned int mReadHead, mWriteHead, mFreeHead; +#endif + MsgType mItems[N]; +}; + +///////////////////////////////////////////////////////////////////// + +template +class MsgFifoNoFree +{ +public: + MsgFifoNoFree() + : mReadHead(0), mWriteHead(0) + { + } + + void MakeEmpty() { mReadHead = mWriteHead; } + bool IsEmpty() { return mReadHead == mWriteHead; } + bool HasData() { return mReadHead != mWriteHead; } + + bool Write(MsgType& data) + { + unsigned int next = NextPos(mWriteHead); + if (next == mReadHead) return false; // fifo is full + mItems[next] = data; +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mWriteHead, next, &mWriteHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mWriteHead),next); +#else + mWriteHead = next; +#endif + return true; + } + + void Perform() // get next and advance + { + while (HasData()) { + unsigned int next = NextPos(mReadHead); + mItems[next].Perform(); +#ifdef SC_DARWIN + // we don't really need a compare and swap, but this happens to call + // the PowerPC memory barrier instruction lwsync. + CompareAndSwap(mReadHead, next, &mReadHead); +#elif defined SC_WIN32 + InterlockedExchange(reinterpret_cast(&mReadHead),next); +#else + mReadHead = next; +#endif + } + } + +private: + int NextPos(int inPos) { return (inPos + 1) & (N - 1); } + +#ifdef SC_DARWIN + UInt32 mReadHead, mWriteHead; +#else + volatile unsigned int mReadHead, mWriteHead; +#endif + MsgType mItems[N]; +}; + +///////////////////////////////////////////////////////////////////// + + +#endif + + diff --git a/sc4pd/headers/server/OSC_Packet.h b/sc4pd/headers/server/OSC_Packet.h new file mode 100644 index 0000000..5964e81 --- /dev/null +++ b/sc4pd/headers/server/OSC_Packet.h @@ -0,0 +1,43 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * OSC_Packet.h + * SC3synth + * + * Created by James McCartney on Sat Aug 24 2002. + * Copyright (c) 2001 __MyCompanyName__. All rights reserved. + * + */ + +#ifndef _OSC_Packet_ +#define _OSC_Packet_ + +#include "SC_Reply.h" + +struct OSC_Packet +{ + char *mData; + int32 mSize; + bool mIsBundle; + + ReplyAddress mReplyAddr; +}; + +#endif diff --git a/sc4pd/headers/server/PriorityQueue.h b/sc4pd/headers/server/PriorityQueue.h new file mode 100755 index 0000000..eb1064f --- /dev/null +++ b/sc4pd/headers/server/PriorityQueue.h @@ -0,0 +1,123 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _PriorityQueue_ +#define _PriorityQueue_ + +#include +#include +#include + +#define SANITYCHECK 0 + +#ifdef SC_WIN32 +const int64 kMaxInt64 = 0x7FFFFFFFFFFFFFFF; +#else +const int64 kMaxInt64 = ~(1LL<<63); +#endif + +template +class PriorityQueueT +{ +public: + PriorityQueueT() { + Empty(); + } + + bool Add(Event& inEvent) + { + if (mSize >= N) return false; + long mom = mSize++; + long me = mom; + for (; mom>0;) { /* percolate up heap */ + mom = mom - 1 >> 1; + if (inEvent.mTime < mEvents[mom].mTime) { + mEvents[me] = mEvents[mom]; + me = mom; + } else break; + } + mEvents[me] = inEvent; +#if SANITYCHECK + SanityCheck(); +#endif + return true; + } + void Perform(int64 inTime) + { + while (NextTime() <= inTime) { + Event event = Remove(); + event.Perform(); + } + } + int64 NextTime() { return mEvents[0].mTime; } + bool Ready(int64 inTime) { return NextTime() <= inTime; } + void Flush() { Perform(kMaxInt64); } + void Empty() { mSize = 0; SetEmptyTime(); } + void SetEmptyTime() { mEvents[0].mTime = kMaxInt64; } + int Size() { return mSize; } + + Event Remove() + { + Event event = mEvents[0]; + if (--mSize == 0) SetEmptyTime(); + else { + Event temp = mEvents[mSize]; + long mom = 0; + long me = 1; + for (;me < mSize;) { /* demote heap */ + if (me+1 < mSize && mEvents[me].mTime > mEvents[me+1].mTime) { + me ++; + } + if (temp.mTime > mEvents[me].mTime) { + mEvents[mom] = mEvents[me]; + mom = me; + me = (me << 1) + 1; + } else break; + } + mEvents[mom] = temp; + } +#if SANITYCHECK + SanityCheck(); +#endif + return event; + } + void SanityCheck() + { + for (int i=0; i mEvents[j].mTime) throw std::runtime_error("priority queue unsorted"); + //if (k mEvents[k].mTime) throw std::runtime_error("priority queue unsorted"); + } + } + void DebugDump() + { + for (int i=0; i +#include + +inline void writeData(char *&buf, char *data, int size) +{ + memcpy(buf, data, size); + buf += size; +} + +inline void writeZero(char *&buf, int len) +{ + for (int i=0; i> 8) & 255); + *buf++ = (char)(inInt & 255); +} + +inline void writeInt16_le(char *&buf, int16 inInt) +{ + *buf++ = (char)(inInt & 255); + *buf++ = (char)((inInt >> 8) & 255); +} + +inline void writeInt32_be(char *&buf, int32 inInt) +{ + *buf++ = (char)((inInt >> 24) & 255); + *buf++ = (char)((inInt >> 16) & 255); + *buf++ = (char)((inInt >> 8) & 255); + *buf++ = (char)(inInt & 255); +} + +inline void writeInt32_le(char *&buf, int32 inInt) +{ + *buf++ = (char)(inInt & 255); + *buf++ = (char)((inInt >> 8) & 255); + *buf++ = (char)((inInt >> 16) & 255); + *buf++ = (char)((inInt >> 24) & 255); +} + +inline void writeSymbol(char *&buf, char *inString) +{ + size_t length = strlen(inString); + writeUInt8(buf, (uint8)length); + memcpy(buf, inString, length); + buf += length; +} + +inline void writeString(char *&buf, char *inString, size_t inLength) +{ + writeInt32_be(buf, inLength); + memcpy(buf, inString, inLength); + buf += inLength; +} + +inline void writeString(char *&buf, char *inString) +{ + size_t length = strlen(inString); + writeString(buf, inString, length); +} + + + +inline void writeData(FILE *file, char *data, size_t size) +{ + fwrite(data, 1, size, file); +} + +inline void writeInt8(FILE *file, int8 inInt) +{ + fputc(inInt & 255, file); +} + +inline void writeUInt8(FILE *file, uint8 inInt) +{ + fputc(inInt & 255, file); +} + +inline void writeInt16_be(FILE *file, int16 inInt) +{ + fputc((inInt >> 8) & 255, file); + fputc(inInt & 255, file); +} + +inline void writeInt16_le(FILE *file, int16 inInt) +{ + fputc(inInt & 255, file); + fputc((inInt >> 8) & 255, file); +} + +inline void writeInt32_be(FILE *file, int32 inInt) +{ + fputc((inInt >> 24) & 255, file); + fputc((inInt >> 16) & 255, file); + fputc((inInt >> 8) & 255, file); + fputc(inInt & 255, file); +} + +inline void writeInt64_be(FILE *file, int64 inInt) +{ + writeInt32_be(file, (int32)((inInt >> 32) & 0x00000000FFFFFFFF)); + writeInt32_be(file, (int32)(inInt)); +} + +inline void writeInt32_le(FILE *file, int32 inInt) +{ + fputc(inInt & 255, file); + fputc((inInt >> 8) & 255, file); + fputc((inInt >> 16) & 255, file); + fputc((inInt >> 24) & 255, file); +} + +inline void writeFloat_be(FILE *file, float inFloat) +{ + union { + float f; + int32 i; + } u; + u.f = inFloat; + writeInt32_be(file, u.i); +} + +inline void writeFloat_le(FILE *file, float inFloat) +{ + union { + float f; + int32 i; + } u; + u.f = inFloat; + writeInt32_le(file, u.i); +} + +inline void writeSymbol(FILE *file, char *inString) +{ + size_t length = strlen(inString); + writeUInt8(file, (uint8)length); + fwrite(inString, 1, length, file); +} + +inline void writeString(FILE *file, char *inString, size_t inLength) +{ + writeInt32_be(file, inLength); + fwrite(inString, 1, inLength, file); +} + +inline void writeString(FILE *file, char *inString) +{ + size_t length = strlen(inString); + writeString(file, inString, length); +} + +inline int32 readInt8(FILE *file) +{ + int32 res = fgetc(file); + + return res; +} + +inline uint32 readUInt8(FILE *file) +{ + uint32 res = (uint32)fgetc(file); + return res; +} + +inline int32 readInt16_be(FILE *file) +{ + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt16_le(FILE *file) +{ + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((d & 255) << 8) | (c & 255); + return res; +} + +inline int32 readInt32_be(FILE *file) +{ + int32 a = fgetc(file); + int32 b = fgetc(file); + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((a & 255) << 24) | ((b & 255) << 16) | ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt32_le(FILE *file) +{ + int32 a = fgetc(file); + int32 b = fgetc(file); + int32 c = fgetc(file); + int32 d = fgetc(file); + + int32 res = ((d & 255) << 24) | ((c & 255) << 16) | ((b & 255) << 8) | (a & 255); + return res; +} + +inline int64 readInt64_be(FILE *file) +{ + int64 hi = readInt32_be(file); + int64 lo = readInt32_be(file); + return (hi << 32) | (lo & 0x00000000FFFFFFFF); +} + +inline float readFloat_be(FILE *file) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_be(file); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline float readFloat_le(FILE *file) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_le(file); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline void readString(FILE *file, char *outString, size_t inLength) +{ + fread(outString, 1, inLength, file); + outString[inLength] = 0; +} + +inline void readSymbol(FILE *file, char *outString) +{ + size_t length = (size_t)readUInt8(file); + readString(file, outString, length); +} + +inline void readData(FILE *file, char *outData, size_t inLength) +{ + fread(outData, 1, inLength, file); +} + + +inline int32 readInt8(char *&buf) +{ + int32 res = *buf++; + return res; +} + +inline uint32 readUInt8(char *&buf) +{ + uint32 res = *buf++; + return res; +} + +inline int32 readInt16_be(char *&buf) +{ + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt16_le(char *&buf) +{ + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((d & 255) << 8) | (c & 255); + return res; +} + + +inline int32 readInt32_be(char *&buf) +{ + int32 a = readInt8(buf); + int32 b = readInt8(buf); + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((a & 255) << 24) | ((b & 255) << 16) | ((c & 255) << 8) | (d & 255); + return res; +} + +inline int32 readInt32_le(char *&buf) +{ + int32 a = readInt8(buf); + int32 b = readInt8(buf); + int32 c = readInt8(buf); + int32 d = readInt8(buf); + + int32 res = ((d & 255) << 24) | ((c & 255) << 16) | ((b & 255) << 8) | (a & 255); + return res; +} + +inline float readFloat_be(char *&buf) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_be(buf); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline float readFloat_le(char *&buf) +{ + union { + float f; + int32 i; + } u; + u.i = readInt32_le(buf); + //post("readFloat %g\n", u.f); + return u.f; +} + +inline double readDouble_be(char *&buf) +{ + //post("readDouble\n"); + union { + double f; + uint8 c[8]; + } u; + + u.c[0] = (uint8)readInt8(buf); + u.c[1] = (uint8)readInt8(buf); + u.c[2] = (uint8)readInt8(buf); + u.c[3] = (uint8)readInt8(buf); + u.c[4] = (uint8)readInt8(buf); + u.c[5] = (uint8)readInt8(buf); + u.c[6] = (uint8)readInt8(buf); + u.c[7] = (uint8)readInt8(buf); + //post("readDouble %g %08X %08X\n", u.f, u.f); + return u.f; +} + +inline double readDouble_le(char *&buf) +{ + //post("readDouble\n"); + union { + double f; + uint8 c[8]; + } u; + + u.c[7] = (uint8)readInt8(buf); + u.c[6] = (uint8)readInt8(buf); + u.c[5] = (uint8)readInt8(buf); + u.c[4] = (uint8)readInt8(buf); + u.c[3] = (uint8)readInt8(buf); + u.c[2] = (uint8)readInt8(buf); + u.c[1] = (uint8)readInt8(buf); + u.c[0] = (uint8)readInt8(buf); + + //post("readDouble %g\n", u.f); + return u.f; +} + +inline void readString(char *&buf, char *outString, size_t inLength) +{ + memcpy(outString, buf, inLength); + outString[inLength] = 0; + buf += inLength; +} + +inline void readSymbol(char *&buf, char *outString) +{ + size_t length = (size_t)readUInt8(buf); + readString(buf, outString, length); +} + +inline void readData(char *&buf, char *outData, size_t inLength) +{ + memcpy(outData, buf, inLength); + buf += inLength; +} + + +#endif \ No newline at end of file diff --git a/sc4pd/headers/server/Rendezvous.h b/sc4pd/headers/server/Rendezvous.h new file mode 100644 index 0000000..2067cd2 --- /dev/null +++ b/sc4pd/headers/server/Rendezvous.h @@ -0,0 +1,41 @@ +/* + * Rendezvous.h + * SC3synth + * + * Created by C. Ramakrishnan on Wed Dec 18 2002. + * Illposed Software + * + */ + +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _Rendezvous_ +#define _Rendezvous_ + +typedef enum { + kSCRendezvous_UDP, + kSCRendezvous_TCP +} SCRendezvousProtocol; + +void PublishPortToRendezvous(SCRendezvousProtocol protocol, short portNum); + +#endif + diff --git a/sc4pd/headers/server/SC_ComPort.h b/sc4pd/headers/server/SC_ComPort.h new file mode 100755 index 0000000..3674fd5 --- /dev/null +++ b/sc4pd/headers/server/SC_ComPort.h @@ -0,0 +1,144 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_ComPort_ +#define _SC_ComPort_ + +#if defined (__APPLE__) && defined (__GNUC__) +#define USE_RENDEZVOUS +#endif + +#include +#ifdef SC_WIN32 +# include +#else +# include +#endif +#include "OSC_Packet.h" +#include "SC_Sem.h" + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_CmdPort +{ +protected: + pthread_t mThread; + struct World *mWorld; + + void Start(); + virtual ReplyFunc GetReplyFunc()=0; +public: + SC_CmdPort(struct World *inWorld); + + virtual void* Run()=0; +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_ComPort : public SC_CmdPort +{ +protected: + int mPortNum; + int mSocket; + struct sockaddr_in mBindSockAddr; + +#ifdef USE_RENDEZVOUS + pthread_t mRendezvousThread; +#endif + +public: + SC_ComPort(struct World *inWorld, int inPortNum); + virtual ~SC_ComPort(); + + int Socket() { return mSocket; } + + int PortNum() const { return mPortNum; } +#ifdef USE_RENDEZVOUS + // default implementation does nothing (this is correct for + // SC_TcpConnectionPort). Subclasses may override. + virtual void PublishToRendezvous() { }; +#endif +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_UdpInPort : public SC_ComPort +{ +protected: + struct sockaddr_in mReplySockAddr; + virtual ReplyFunc GetReplyFunc(); + +public: + SC_UdpInPort(struct World *inWorld, int inPortNum); + ~SC_UdpInPort(); + + int PortNum() const { return mPortNum; } + + void* Run(); +#ifdef USE_RENDEZVOUS + virtual void PublishToRendezvous(); +#endif + +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpInPort : public SC_ComPort +{ + SC_Semaphore mConnectionAvailable; + int mBacklog; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpInPort(struct World *inWorld, int inPortNum, int inMaxConnections, int inBacklog); + + virtual void* Run(); + + void ConnectionTerminated(); +#ifdef USE_RENDEZVOUS + virtual void PublishToRendezvous(); +#endif +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +class SC_TcpConnectionPort : public SC_ComPort +{ + SC_TcpInPort *mParent; + +protected: + virtual ReplyFunc GetReplyFunc(); + +public: + SC_TcpConnectionPort(struct World *inWorld, SC_TcpInPort *inParent, int inSocket); + virtual ~SC_TcpConnectionPort(); + + virtual void* Run(); +}; + +const int kPacketBufSize = 8192; // this seems to be the maximum size of a UDP packet + +////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/server/SC_Complex.h b/sc4pd/headers/server/SC_Complex.h new file mode 100644 index 0000000..d4aed20 --- /dev/null +++ b/sc4pd/headers/server/SC_Complex.h @@ -0,0 +1,142 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Complex_ +#define _SC_Complex_ + +#include "SC_Types.h" +#include "float.h" + +//////////////////////////////////////////////////////////////////////////////// + +struct Polar; + +struct Complex +{ + Complex() {} + Complex(float r, float i) : real(r), imag(i) {} + void Set(float r, float i) { real = r; imag = i; } + + Complex& operator=(Complex b) { real = b.real; imag = b.imag; return *this; } + Complex& operator=(float b) { real = b; imag = 0.; return *this; } + + Polar ToPolar(); + Polar ToPolarApx(); + + void ToPolarInPlace(); + void ToPolarApxInPlace(); + + float real, imag; +}; + +struct Polar +{ + Polar() {} + Polar(float m, float p) : mag(m), phase(p) {} + void Set(float m, float p) { mag = m; phase = p; } + + Complex ToComplex(); + Complex ToComplexApx(); + + void ToComplexInPlace(); + void ToComplexApxInPlace(); + + float mag, phase; +}; + +struct ComplexFT +{ + float dc, nyq; + Complex complex[1]; +}; + +struct PolarFT +{ + float dc, nyq; + Polar polar[1]; +}; + +void ToComplex(Polar in, Complex& out); + +inline Complex operator+(Complex a, Complex b) { return Complex(a.real + b.real, a.imag + b.imag); } +inline Complex operator+(Complex a, float b) { return Complex(a.real + b, a.imag); } +inline Complex operator+(float a, Complex b) { return Complex(a + b.real, b.imag); } + +inline Complex& operator+=(Complex& a, const Complex& b) { a.real += b.real, a.imag += b.imag; return a; } +inline Complex& operator+=(Complex& a, float b) { a.real += b; return a; } + +inline Complex operator-(Complex a, Complex b) { return Complex(a.real - b.real, a.imag - b.imag); } +inline Complex operator-(Complex a, float b) { return Complex(a.real - b, a.imag); } +inline Complex operator-(float a, Complex b) { return Complex(a - b.real, b.imag); } + +inline Complex operator-=(Complex a, Complex b) { a.real -= b.real, a.imag -= b.imag; return a; } +inline Complex operator-=(Complex a, float b) { a.real -= b; return a; } + +inline Complex operator*(Complex a, Complex b) +{ + return Complex(a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real); +} + +inline Complex operator*(Complex a, float b) +{ + return Complex(a.real * b, a.imag * b); +} + +inline Complex operator*(float a, Complex b) +{ + return Complex(b.real * a, b.imag * a); +} + +inline Complex operator*=(Complex a, Complex b) +{ + a.Set( + a.real * b.real - a.imag * b.imag, + a.real * b.imag + a.imag * b.real + ); + return a; +} + +inline Complex operator*=(Complex a, float b) +{ + a.real *= b; + a.imag *= b; + return a; +} + + +inline Polar operator*(Polar a, float b) +{ + return Polar(a.mag * b, a.phase); +} + +inline Polar operator*(float a, Polar b) +{ + return Polar(a * b.mag, b.phase); +} + +inline Polar operator*=(Polar a, float b) +{ + a.mag *= b; + return a; +} + + +#endif diff --git a/sc4pd/headers/server/SC_CoreAudio.h b/sc4pd/headers/server/SC_CoreAudio.h new file mode 100755 index 0000000..fba5184 --- /dev/null +++ b/sc4pd/headers/server/SC_CoreAudio.h @@ -0,0 +1,263 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_CoreAudio_ +#define _SC_CoreAudio_ + +#include "MsgFifo.h" +#include "SC_FifoMsg.h" +#include "OSC_Packet.h" +#include "SC_SyncCondition.h" +#include "PriorityQueue.h" +#include "SC_Lock.h" + +#define SC_AUDIO_API_COREAUDIO 1 +#define SC_AUDIO_API_JACK 2 +#define SC_AUDIO_API_PORTAUDIO 3 + +#ifdef SC_WIN32 +# define SC_AUDIO_API SC_AUDIO_API_PORTAUDIO +#endif + +#ifndef SC_AUDIO_API +# define SC_AUDIO_API SC_AUDIO_API_COREAUDIO +#endif // SC_AUDIO_API + +#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO +# include +# include +#endif + +#if SC_AUDIO_API == SC_AUDIO_API_JACK +# include +class SC_JackPortList; +#endif + +#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO +#include "portaudio.h" +#endif + + +struct SC_ScheduledEvent +{ + SC_ScheduledEvent() : mTime(0), mPacket(0) {} + SC_ScheduledEvent(struct World *inWorld, int64 inTime, OSC_Packet *inPacket) + : mTime(inTime), mPacket(inPacket), mWorld(inWorld) {} + + int64 Time() { return mTime; } + void Perform(); + + int64 mTime; + OSC_Packet *mPacket; + struct World *mWorld; +}; + +typedef MsgFifo EngineFifo; + + +class SC_AudioDriver +{ +protected: + int64 mOSCincrement; + struct World *mWorld; + double mOSCtoSamples; + int mSampleTime; + + // Common members + uint32 mHardwareBufferSize; // bufferSize returned by kAudioDevicePropertyBufferSize + EngineFifo mFromEngine, mToEngine; + SC_SyncCondition mAudioSync; + pthread_t mThread; + bool mRunThreadFlag; + uint32 mSafetyOffset; + PriorityQueueT mScheduler; + SC_Lock *mProcessPacketLock; + int mNumSamplesPerCallback; + uint32 mPreferredHardwareBufferFrameSize; + uint32 mPreferredSampleRate; + double mBuffersPerSecond; + double mAvgCPU, mPeakCPU; + int mPeakCounter, mMaxPeakCounter; + double mOSCincrementNumerator; + + double mStartHostSecs; + double mPrevHostSecs; + double mStartSampleTime; + double mPrevSampleTime; + double mSmoothSampleRate; + double mSampleRate; + + // Driver interface methods, implemented by subclasses + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate) = 0; + virtual bool DriverStart() = 0; + virtual bool DriverStop() = 0; + +public: + // Common methods + SC_AudioDriver(struct World *inWorld); + virtual ~SC_AudioDriver(); + + int64 mOSCbuftime; + + bool Setup(); + bool Start(); + bool Stop(); + + void ClearSched() { mScheduler.Empty(); } + + void Lock() { mProcessPacketLock->Lock(); } + void Unlock() { mProcessPacketLock->Unlock(); } + + void RunNonRealTime(float *in, float *out, int numSamples, int64 oscTime); + void* RunThread(); + + int SafetyOffset() const { return mSafetyOffset; } + int NumSamplesPerCallback() const { return mNumSamplesPerCallback; } + void SetPreferredHardwareBufferFrameSize(int inSize) + { + mPreferredHardwareBufferFrameSize = inSize; + } + void SetPreferredSampleRate(int inRate) + { + mPreferredSampleRate = inRate; + } + + bool SendMsgToEngine(FifoMsg& inMsg); + bool SendMsgFromEngine(FifoMsg& inMsg); + + void AddEvent(SC_ScheduledEvent& event) { mScheduler.Add(event); } + + double GetAvgCPU() const { return mAvgCPU; } + double GetPeakCPU() const { return mPeakCPU; } + double GetSampleRate() const { return mSampleRate; } + double GetActualSampleRate() const { return mSmoothSampleRate; } +}; + + +// the following classes should be split out into separate source files. +#if SC_AUDIO_API == SC_AUDIO_API_COREAUDIO +class SC_CoreAudioDriver : public SC_AudioDriver +{ + + AudioBufferList * mInputBufList; + AudioDeviceID mInputDevice; + AudioDeviceID mOutputDevice; + + AudioStreamBasicDescription inputStreamDesc; // info about the default device + AudioStreamBasicDescription outputStreamDesc; // info about the default device + + friend OSStatus appIOProc ( AudioDeviceID inDevice, + const AudioTimeStamp* inNow, + const AudioBufferList* inInputData, + const AudioTimeStamp* inInputTime, + AudioBufferList* outOutputData, + const AudioTimeStamp* inOutputTime, + void* defptr); + +protected: + // Driver interface methods + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate); + virtual bool DriverStart(); + virtual bool DriverStop(); + +public: + SC_CoreAudioDriver(struct World *inWorld); + virtual ~SC_CoreAudioDriver(); + + void Run(const AudioBufferList* inInputData, AudioBufferList* outOutputData, int64 oscTime); + + bool UseInput() { return mInputDevice != kAudioDeviceUnknown; } + bool UseSeparateIO() { return UseInput() && mInputDevice != mOutputDevice; } + AudioDeviceID InputDevice() { return mInputDevice; } + AudioDeviceID OutputDevice() { return mOutputDevice; } + + void SetInputBufferList(AudioBufferList * inBufList) { mInputBufList = inBufList; } + AudioBufferList* GetInputBufferList() const { return mInputBufList; } +}; + +inline SC_AudioDriver* SC_NewAudioDriver(struct World *inWorld) +{ + return new SC_CoreAudioDriver(inWorld); +} +#endif // SC_AUDIO_API_COREAUDIO + + +#if SC_AUDIO_API == SC_AUDIO_API_JACK +class SC_JackDriver : public SC_AudioDriver +{ + jack_client_t *mClient; + SC_JackPortList *mInputList; + SC_JackPortList *mOutputList; + int64 mMaxOutputLatency; + +protected: + // Driver interface methods + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate); + virtual bool DriverStart(); + virtual bool DriverStop(); + +public: + SC_JackDriver(struct World *inWorld); + virtual ~SC_JackDriver(); + + void Run(); + void BufferSizeChanged(int numSamples); + void SampleRateChanged(double sampleRate); + void GraphOrderChanged(); +}; + +inline SC_AudioDriver* SC_NewAudioDriver(struct World *inWorld) +{ + return new SC_JackDriver(inWorld); +} +#endif // SC_AUDIO_API_JACK + + +#if SC_AUDIO_API == SC_AUDIO_API_PORTAUDIO +class SC_PortAudioDriver : public SC_AudioDriver +{ + + int mInputChannelCount, mOutputChannelCount; + PaStream *mStream; + +protected: + // Driver interface methods + virtual bool DriverSetup(int* outNumSamplesPerCallback, double* outSampleRate); + virtual bool DriverStart(); + virtual bool DriverStop(); + +public: + SC_PortAudioDriver(struct World *inWorld); + virtual ~SC_PortAudioDriver(); + + int PortAudioCallback( const void *input, void *output, + unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags ); +}; + +inline SC_AudioDriver* SC_NewAudioDriver(struct World *inWorld) +{ + return new SC_PortAudioDriver(inWorld); +} +#endif // SC_AUDIO_API_PORTAUDIO + + +#endif diff --git a/sc4pd/headers/server/SC_Errors.h b/sc4pd/headers/server/SC_Errors.h new file mode 100755 index 0000000..3d3459a --- /dev/null +++ b/sc4pd/headers/server/SC_Errors.h @@ -0,0 +1,58 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Errors_ +#define _SC_Errors_ + +typedef int SCErr; + +const char *SC_ErrorString(SCErr err); + +enum { + kSCErr_None, + kSCErr_Failed, + kSCErr_NodeNotFound, + kSCErr_TargetNodeNotFound, + kSCErr_GroupNotFound, + kSCErr_SynthDefNotFound, + kSCErr_NoSuchCommand, + kSCErr_WrongArgType, + kSCErr_IndexOutOfRange, + kSCErr_AccessDenied, + kSCErr_NoReplyPort, + kSCErr_InvalidControlIndex, + kSCErr_AlreadyLoggedIn, + kSCErr_NotLoggedIn, + kSCErr_TooManyUsers, + kSCErr_TooManyNodes, + kSCErr_DuplicateNodeID, + kSCErr_ReservedNodeID, + kSCErr_OutOfRealTimeMemory, + + kSCErr_UnsupportedHeaderFormat, + kSCErr_UnsupportedSampleFormat, + + kSCErr_BufGenNotFound, + + kSCErr_NumErrors +}; + +#endif diff --git a/sc4pd/headers/server/SC_GraphDef.h b/sc4pd/headers/server/SC_GraphDef.h new file mode 100644 index 0000000..dca6fd2 --- /dev/null +++ b/sc4pd/headers/server/SC_GraphDef.h @@ -0,0 +1,75 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_GraphDef_ +#define _SC_GraphDef_ + +#include "SC_SynthDef.h" +#include "HashTable.h" + +struct ParamSpec +{ + int32 mName[kSCNameLen]; + int32 mIndex; + int32 mHash; +}; + +typedef HashTable ParamSpecTable; + +struct GraphDef +{ + NodeDef mNodeDef; + + uint32 mNumControls; + + uint32 mNumWires; + uint32 mNumConstants; + uint32 mNumUnitSpecs; + uint32 mNumWireBufs; + uint32 mNumCalcUnits; + + float32 *mInitialControlValues; + float32 *mConstants; + + struct UnitSpec *mUnitSpecs; + + size_t mWiresAllocSize, mUnitsAllocSize, mCalcUnitsAllocSize; + size_t mControlAllocSize, mMapControlsAllocSize; + + uint32 mNumParamSpecs; + ParamSpec *mParamSpecs; + ParamSpecTable *mParamSpecTable; + + int mRefCount; + struct GraphDef* mNext; +}; +typedef struct GraphDef GraphDef; + +GraphDef* GraphDef_Recv(World *inWorld, char *buffer, GraphDef *inList); +GraphDef* GraphDef_Load(struct World *inWorld, const char *filename, GraphDef* inList); +GraphDef* GraphDef_LoadDir(struct World *inWorld, char *dirname, GraphDef* inList); +GraphDef* GraphDef_LoadGlob(World *inWorld, const char *pattern, GraphDef *inList); +void GraphDef_DeleteMsg(struct World *inWorld, GraphDef *inDef); +void GraphDef_Dump(GraphDef *inGraphDef); +int32 GetHash(ParamSpec* inParamSpec); +int32* GetKey(ParamSpec* inParamSpec); + +#endif diff --git a/sc4pd/headers/server/SC_Group.h b/sc4pd/headers/server/SC_Group.h new file mode 100644 index 0000000..5a104a7 --- /dev/null +++ b/sc4pd/headers/server/SC_Group.h @@ -0,0 +1,34 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Group_ +#define _SC_Group_ + +#include "SC_Graph.h" + +struct Group { + Node mNode; + + Node *mHead, *mTail; +}; +typedef struct Group Group; + +#endif diff --git a/sc4pd/headers/server/SC_HiddenWorld.h b/sc4pd/headers/server/SC_HiddenWorld.h new file mode 100644 index 0000000..7776874 --- /dev/null +++ b/sc4pd/headers/server/SC_HiddenWorld.h @@ -0,0 +1,113 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_HiddenWorld_ +#define _SC_HiddenWorld_ + +#include "SC_Types.h" +#include "SC_Sem.h" +#include "SC_Rate.h" +#include "SC_SndBuf.h" +#include "SC_RGen.h" +#include "HashTable.h" +#include "SC_World.h" +#include "SC_Reply.h" +#include "MsgFifo.h" + +extern HashTable *gUnitDefLib; + + +struct TriggerMsg { + World *mWorld; + int32 mNodeID; + int32 mTriggerID; + float mValue; + + void Perform(); +}; + +struct NodeEndMsg { + World *mWorld; + int32 mNodeID; + int32 mGroupID; + int32 mPrevNodeID; + int32 mNextNodeID; + int32 mIsGroup; + int32 mHeadID; + int32 mTailID; + int32 mState; + + void Perform(); +}; + +struct DeleteGraphDefMsg { + struct GraphDef* mDef; + + void Perform(); +}; + + +typedef MsgFifoNoFree TriggersFifo; +typedef MsgFifoNoFree NodeEndsFifo; +typedef MsgFifoNoFree DeleteGraphDefsFifo; + +struct HiddenWorld +{ + + class AllocPool *mAllocPool; + IntHashTable *mNodeLib; + HashTable *mGraphDefLib; + uint32 mNumUsers, mMaxUsers; + ReplyAddress *mUsers; + + class SC_AudioDriver *mAudioDriver; + char mPassword[32]; + + uint32 mMaxWireBufs; + float *mWireBufSpace; + + TriggersFifo mTriggers; + NodeEndsFifo mNodeEnds; + DeleteGraphDefsFifo mDeleteGraphDefs; + + SC_Semaphore* mQuitProgram; + + SNDFILE *mNRTInputFile; + SNDFILE *mNRTOutputFile; + FILE *mNRTCmdFile; + + int32 mHiddenID; + int32 mRecentID; + +#ifdef SC_DARWIN + const char* mInputStreamsEnabled; + const char* mOutputStreamsEnabled; +#endif +}; + +typedef struct HiddenWorld HiddenWorld; + +inline SC_AudioDriver *AudioDriver(World *inWorld) +{ + return inWorld->hw->mAudioDriver; +} + +#endif diff --git a/sc4pd/headers/server/SC_Lib.h b/sc4pd/headers/server/SC_Lib.h new file mode 100755 index 0000000..552a231 --- /dev/null +++ b/sc4pd/headers/server/SC_Lib.h @@ -0,0 +1,62 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Lib_ +#define _SC_Lib_ + +#include "SC_Errors.h" +#include "SC_Lock.h" +#include "SC_Types.h" +#include "Hash.h" +#include "HashTable.h" +#include +#include + +class SC_NamedObj +{ +public: + SC_NamedObj(); + virtual ~SC_NamedObj(); + + const int32* Name() const { return mName; } + void SetName(const char *inName); + void SetName(const int32 *inName); + +private: + friend int32 GetHash(const SC_NamedObj *inObj); + friend const int32* GetKey(const SC_NamedObj *inObj); + + int32 mName[kSCNameLen]; + int32 mHash; +}; + +inline int32 GetHash(const SC_NamedObj *inObj) +{ + return inObj->mHash; +} + +inline const int32 *GetKey(const SC_NamedObj *inObj) +{ + return inObj->mName; +} + +#endif + diff --git a/sc4pd/headers/server/SC_Lib_Cintf.h b/sc4pd/headers/server/SC_Lib_Cintf.h new file mode 100755 index 0000000..64eda5e --- /dev/null +++ b/sc4pd/headers/server/SC_Lib_Cintf.h @@ -0,0 +1,124 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Lib_Cintf_ +#define _SC_Lib_Cintf_ + +#include "SC_Lib.h" +#include "SC_Reply.h" + +typedef SCErr (*SC_CommandFunc)(struct World *inWorld, int inSize, char *inData, ReplyAddress *inReply); + +class SC_LibCmd : public SC_NamedObj +{ +public: + SC_LibCmd(SC_CommandFunc inFunc); + + SCErr Perform(struct World *inWorld, int inSize, char *inData, ReplyAddress *inReply); + +private: + SC_CommandFunc mFunc; +}; + +extern Malloc gMalloc; +extern HashTable *gCmdLib; + +void initialize_library(); +SCErr NewCommand(const char *inPath, uint32 inCommandNumber, SC_CommandFunc inFunc); + +// command numbers: +enum { + cmd_none = 0, + + cmd_notify = 1, + cmd_status = 2, + cmd_quit = 3, + cmd_cmd = 4, + + cmd_d_recv = 5, + cmd_d_load = 6, + cmd_d_loadDir = 7, + cmd_d_freeAll = 8, + + cmd_s_new = 9, + + cmd_n_trace = 10, + cmd_n_free = 11, + cmd_n_run = 12, + cmd_n_cmd = 13, + cmd_n_map = 14, + cmd_n_set = 15, + cmd_n_setn = 16, + cmd_n_fill = 17, + cmd_n_before = 18, + cmd_n_after = 19, + + cmd_u_cmd = 20, + + cmd_g_new = 21, + cmd_g_head = 22, + cmd_g_tail = 23, + cmd_g_freeAll = 24, + + cmd_c_set = 25, + cmd_c_setn = 26, + cmd_c_fill = 27, + + cmd_b_alloc = 28, + cmd_b_allocRead = 29, + cmd_b_read = 30, + cmd_b_write = 31, + cmd_b_free = 32, + cmd_b_close = 33, + cmd_b_zero = 34, + cmd_b_set = 35, + cmd_b_setn = 36, + cmd_b_fill = 37, + cmd_b_gen = 38, + + cmd_dumpOSC = 39, + + cmd_c_get = 40, + cmd_c_getn = 41, + cmd_b_get = 42, + cmd_b_getn = 43, + cmd_s_get = 44, + cmd_s_getn = 45, + + cmd_n_query = 46, + cmd_b_query = 47, + + cmd_n_mapn = 48, + cmd_s_noid = 49, + + cmd_g_deepFree = 50, + cmd_clearSched = 51, + + cmd_sync = 52, + + NUMBER_OF_COMMANDS = 53 +}; + +extern SC_LibCmd* gCmdArray[NUMBER_OF_COMMANDS]; + + +#endif + diff --git a/sc4pd/headers/server/SC_List.h b/sc4pd/headers/server/SC_List.h new file mode 100755 index 0000000..d5bed41 --- /dev/null +++ b/sc4pd/headers/server/SC_List.h @@ -0,0 +1,229 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + +A doubly linked list template. + +*/ + +#ifndef _SC_List_ +#define _SC_List_ + +#include +#ifndef NDEBUG +# define NDEBUG +#endif +#include + + +// A Link can be a node in a list or a list itself. + +template +class Link +{ +public: + Link() : mNext(this), mPrev(this) {} + + T* Prev() { return static_cast(mPrev); } + T* Next() { return static_cast(mNext); } + + void RemoveLeaveDangling() + { + mPrev->mNext = mNext; + mNext->mPrev = mPrev; + } + + void Remove() + { + RemoveLeaveDangling(); + mNext = mPrev = this; + } + + void InsertAfter(T *inLink) + { + mPrev = inLink; + mNext = inLink->mNext; + mNext->mPrev = this; + mPrev->mNext = this; + } + + void InsertBefore(T *inLink) + { + mNext = inLink; + mPrev = inLink->mPrev; + mNext->mPrev = this; + mPrev->mNext = this; + } + + T* Head() { return static_cast(mNext); } + T* Tail() { return static_cast(mPrev); } + + T* PopHead(); + T* PopTail(); + void PushHead(T* inBuf); + void PushTail(T* inBuf); + + bool ContainsBuf(T* inBuf); + bool IsEmpty() { return mNext == this; } + void BeEmpty() { mNext = mPrev = this; } + + void Cat(T* inLink); + + bool SanityCheck(); + void DebugDump(); + +//private: +// Codewarrior refuses to inline Next() in some places.. + Link *mNext, *mPrev; +}; + +template +void MakeListEmpty(Link *inLink, Alloc* inAlloc) +{ + Link* link = inLink->mNext; + while (link != inLink) { + Link* nextlink = link->mNext; + // SC uses placement new extensively, so here we do a 'placement delete'. + // Using DestructSelf allows me to have either virtual + // or non virtual destructors in subclasses at the discretion of the subclass. + ((T*)(link))->DestructSelf(); + inAlloc->Free(static_cast(link)); + link = nextlink; + } + inLink->mNext = inLink->mPrev = inLink; +} + +template +void Link::PushHead(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertAfter(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopHead() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mNext; + + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::PushTail(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + link->InsertBefore(static_cast(this)); + + assert(SanityCheck()); +} + +template +T* Link::PopTail() +{ + assert(SanityCheck()); + if (IsEmpty()) return 0; + + Link* link = mPrev; + link->Remove(); + + assert(SanityCheck()); + return static_cast(link); +} + +template +void Link::Cat(T* inLink) +{ + assert(SanityCheck()); + + Link* link = static_cast*>(inLink); + + if (link->IsEmpty()) return; + if (IsEmpty()) { + mNext = link->mNext; + mPrev = link->mPrev; + link->mNext->mPrev = this; + link->mPrev->mNext = this; + } else { + link->mNext->mPrev = mPrev; + link->mPrev->mNext = this; + mPrev->mNext = link->mNext; + mPrev = link->mPrev; + } + link->mPrev = link; + link->mNext = link; + + assert(SanityCheck()); +} + +template +bool Link::ContainsBuf(T* inLink) +{ + Link* link = static_cast*>(inLink); + Link* curLink = mNext; + while (curLink != this) { + if (curLink == link) return true; + curLink = curLink->mNext; + } + return false; +} + +template +void Link::DebugDump() +{ + Link* link = mNext; + while (link != this) { + //postbuf("Link-> %08X next %08X prev %08X\n", + // link, link->mNext, link->mPrev); + link = link->mNext; + } +} + +template +bool Link::SanityCheck() +{ + Link* link = mNext; + while (link != this) { + if (link->mPrev->mNext != link) { + throw std::runtime_error("Link: bad link <-,->"); + } + if (link->mNext->mPrev != link) { + throw std::runtime_error("Link: bad link ->,<-"); + } + link = link->mNext; + } + return true; +} + + + +#endif diff --git a/sc4pd/headers/server/SC_Lock.h b/sc4pd/headers/server/SC_Lock.h new file mode 100755 index 0000000..57635fe --- /dev/null +++ b/sc4pd/headers/server/SC_Lock.h @@ -0,0 +1,38 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Lock_ +#define _SC_Lock_ + +#include + +class SC_Lock +{ +public: + SC_Lock() { pthread_mutex_init (&mutex, NULL); } + ~SC_Lock() { pthread_mutex_destroy (&mutex); } + void Lock() { pthread_mutex_lock (&mutex); } + void Unlock() { pthread_mutex_unlock (&mutex); } +private: + pthread_mutex_t mutex; +}; + +#endif diff --git a/sc4pd/headers/server/SC_Prototypes.h b/sc4pd/headers/server/SC_Prototypes.h new file mode 100644 index 0000000..c2f353e --- /dev/null +++ b/sc4pd/headers/server/SC_Prototypes.h @@ -0,0 +1,213 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Prototypes_ +#define _SC_Prototypes_ + +#include // for size_t + +#include "SC_Types.h" + +//////////////////////////////////////////////////////////////////////// + +// replacement for calloc. +// calloc lazily zeroes memory on first touch. This is good for most purposes, but bad for realtime audio. +void* zalloc(size_t n, size_t size); + +//////////////////////////////////////////////////////////////////////// + +void World_Run(struct World *inWorld); +void World_Start(World *inWorld); +void World_Cleanup(World *inWorld); +void World_SetSampleRate(struct World *inWorld, double inSampleRate); + +extern "C" { +void* World_Alloc(struct World *inWorld, size_t inByteSize); +void* World_Realloc(struct World *inWorld, void *inPtr, size_t inByteSize); +void World_Free(struct World *inWorld, void *inPtr); +void World_NRTLock(World *world); +void World_NRTUnlock(World *world); +} + +size_t World_TotalFree(struct World *inWorld); +size_t World_LargestFreeChunk(struct World *inWorld); + + +int32 GetKey(struct Node *inNode); +int32 GetHash(struct Node *inNode); +bool World_AddNode(struct World *inWorld, struct Node* inNode); +bool World_RemoveNode(struct World *inWorld, struct Node* inNode); + +extern "C" { +struct Node* World_GetNode(struct World *inWorld, int32 inID); +struct Graph* World_GetGraph(struct World *inWorld, int32 inID); +} + +struct Group* World_GetGroup(struct World *inWorld, int32 inID); + +int32 *GetKey(struct UnitDef *inUnitDef); +int32 GetHash(struct UnitDef *inUnitDef); +bool AddUnitDef(struct UnitDef* inUnitDef); +bool RemoveUnitDef(struct UnitDef* inUnitDef); +struct UnitDef* GetUnitDef(int32* inKey); + +int32 *GetKey(struct BufGen *inBufGen); +int32 GetHash(struct BufGen *inBufGen); +bool AddBufGen(struct BufGen* inBufGen); +bool RemoveBufGen(struct BufGen* inBufGen); +struct BufGen* GetBufGen(int32* inKey); + +int32 *GetKey(struct PlugInCmd *inPlugInCmd); +int32 GetHash(struct PlugInCmd *inPlugInCmd); +bool AddPlugInCmd(struct PlugInCmd* inPlugInCmd); +bool RemovePlugInCmd(struct PlugInCmd* inPlugInCmd); +struct PlugInCmd* GetPlugInCmd(int32* inKey); +int PlugIn_DoCmd(struct World *inWorld, int inSize, char *inArgs, struct ReplyAddress *inReply); + +int32 *GetKey(struct GraphDef *inGraphDef); +int32 GetHash(struct GraphDef *inGraphDef); +bool World_AddGraphDef(struct World *inWorld, struct GraphDef* inGraphDef); +bool World_FreeGraphDef(struct World *inWorld, struct GraphDef* inGraphDef); +bool World_RemoveGraphDef(struct World *inWorld, struct GraphDef* inGraphDef); +struct GraphDef* World_GetGraphDef(struct World *inWorld, int32* inKey); +void World_FreeAllGraphDefs(World *inWorld); +void GraphDef_Free(GraphDef *inGraphDef); +void GraphDef_Define(World *inWorld, GraphDef *inList); +void GraphDef_FreeOverwritten(World *inWorld); + +SCErr bufAlloc(struct SndBuf* buf, int numChannels, int numFrames, double sampleRate); + +//////////////////////////////////////////////////////////////////////// + +void Rate_Init(struct Rate *inRate, double inSampleRate, int inBufLength); + +void Dimension_Init(struct SC_Dimension *inDimension, int inWidth, int inHeight); + +//////////////////////////////////////////////////////////////////////// + +#define GRAPHDEF(inGraph) ((GraphDef*)((inGraph)->mNode.mDef)) +#define GRAPH_PARAM_TABLE(inGraph) (GRAPHDEF(inGraph)->mParamSpecTable) + +int Graph_New(struct World *inWorld, struct GraphDef *def, int32 inID, struct sc_msg_iter* args, struct Graph** outGraph); +void Graph_Ctor(struct World *inWorld, struct GraphDef *inGraphDef, struct Graph *graph, struct sc_msg_iter *msg); +void Graph_Dtor(struct Graph *inGraph); +int Graph_GetControl(struct Graph* inGraph, uint32 inIndex, float& outValue); +int Graph_GetControl(struct Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float& outValue); +void Graph_SetControl(struct Graph* inGraph, uint32 inIndex, float inValue); +void Graph_SetControl(struct Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, float inValue); +void Graph_MapControl(Graph* inGraph, uint32 inIndex, uint32 inBus); +void Graph_MapControl(Graph* inGraph, int32 inHash, int32 *inName, uint32 inIndex, uint32 inBus); +void Graph_Trace(Graph *inGraph); +void Graph_RemoveID(World* inWorld, Graph *inGraph); + +//////////////////////////////////////////////////////////////////////// + +int Node_New(struct World *inWorld, struct NodeDef *def, int32 inID, struct Node **outNode); +void Node_Dtor(struct Node *inNode); +void Node_Remove(struct Node* s); +void Node_Delete(struct Node* inNode); +void Node_AddAfter(struct Node* s, struct Node *afterThisOne); +void Node_AddBefore(struct Node* s, struct Node *beforeThisOne); +void Node_Replace(struct Node* s, struct Node *replaceThisOne); +void Node_SetControl(Node* inNode, int inIndex, float inValue); +void Node_SetControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, float inValue); +void Node_MapControl(Node* inNode, int inIndex, int inBus); +void Node_MapControl(Node* inNode, int32 inHash, int32 *inName, int inIndex, int inBus); +void Node_StateMsg(Node* inNode, int inState); +void Node_Trace(Node* inNode); + +extern "C" { +void Node_SetRun(Node* inNode, int inRun); +void Node_SendTrigger(Node* inNode, int triggerID, float value); +void Node_End(struct Node* inNode); +void Node_NullCalc(struct Node* inNode); +void Unit_DoneAction(int doneAction, struct Unit* unit); +} + +//////////////////////////////////////////////////////////////////////// + +extern "C" { +void Group_Calc(Group *inGroup); +void Graph_Calc(struct Graph *inGraph); +} + +int Group_New(World *inWorld, int32 inID, Group** outGroup); +void Group_Dtor(Group *inGroup); +void Group_DeleteAll(Group *inGroup); +void Group_DeepFreeGraphs(Group *inGroup); +void Group_AddHead (Group *s, Node *child); +void Group_AddTail (Group *s, Node *child); +void Group_Insert(Group *s, Node *child, int inIndex); +void Group_SetControl(struct Group* inGroup, uint32 inIndex, float inValue); +void Group_SetControl(struct Group *inGroup, int32 inHash, int32 *inName, uint32 inIndex, float inValue); +void Group_MapControl(Group* inGroup, uint32 inIndex, uint32 inBus); +void Group_MapControl(Group* inGroup, int32 inHash, int32 *inName, uint32 inIndex, uint32 inBus); +void Group_Trace(Group* inGroup); + +//////////////////////////////////////////////////////////////////////// + +struct Unit* Unit_New(struct World *inWorld, struct UnitSpec *inUnitSpec, char*& memory); +void Unit_EndCalc(struct Unit *inUnit, int inNumSamples); +void Unit_End(struct Unit *inUnit); + +void Unit_Dtor(struct Unit *inUnit); + +extern "C" { +void Unit_ZeroOutputs(struct Unit *inUnit, int inNumSamples); +} + +//////////////////////////////////////////////////////////////////////// + +void SendDone(struct ReplyAddress *inReply, char *inCommandName); +void SendFailure(struct ReplyAddress *inReply, char *inCommandName, char *errString); +void ReportLateness(struct ReplyAddress *inReply, float32 seconds); +void DumpReplyAddress(struct ReplyAddress *inReplyAddress); +int32 Hash(struct ReplyAddress *inReplyAddress); + +//////////////////////////////////////////////////////////////////////// + +extern "C" { +int32 timeseed(); +} + +//////////////////////////////////////////////////////////////////////// + +typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData); +typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData); + +int PerformAsynchronousCommand + ( + World *inWorld, + void* replyAddr, + const char* cmdName, + void *cmdData, + AsyncStageFn stage2, // stage2 is non real time + AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true + AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true + AsyncFreeFn cleanup, + int completionMsgSize, + void* completionMsgData + ); + +//////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/server/SC_Reply.h b/sc4pd/headers/server/SC_Reply.h new file mode 100755 index 0000000..0400747 --- /dev/null +++ b/sc4pd/headers/server/SC_Reply.h @@ -0,0 +1,55 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Msg_ +#define _SC_Msg_ + +#include +#include +#ifdef SC_WIN32 +# include +#else +#include +#endif +#include "sc_msg_iter.h" + +typedef void (*ReplyFunc)(struct ReplyAddress *inReplyAddr, char* inBuf, int inSize); + +void null_reply_func(struct ReplyAddress* addr, char* msg, int size); + +struct ReplyAddress +{ + struct sockaddr_in mSockAddr; + int mSockAddrLen; + int mSocket; + ReplyFunc mReplyFunc; +}; + +bool operator==(const ReplyAddress& a, const ReplyAddress& b); + +inline void SendReply(ReplyAddress *inReplyAddr, char* inBuf, int inSize) +{ + (inReplyAddr->mReplyFunc)(inReplyAddr, inBuf, inSize); +} + +#endif + + diff --git a/sc4pd/headers/server/SC_Samp.h b/sc4pd/headers/server/SC_Samp.h new file mode 100644 index 0000000..dde9159 --- /dev/null +++ b/sc4pd/headers/server/SC_Samp.h @@ -0,0 +1,38 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_Samp_ +#define _SC_Samp_ + +#include "SC_Types.h" + +const int kSineSize = 8192; +const int kSineMask = kSineSize - 1; + +extern float32 gSine[kSineSize+1]; +extern float32 gPMSine[kSineSize+1]; +extern float32 gInvSine[kSineSize+1]; +extern float32 gSineWavetable[2*kSineSize]; + +void SignalAsWavetable(float32* signal, float32* wavetable, long inSize); +void WavetableAsSignal(float32* wavetable, float32* signal, long inSize); + +#endif \ No newline at end of file diff --git a/sc4pd/headers/server/SC_SequencedCommand.h b/sc4pd/headers/server/SC_SequencedCommand.h new file mode 100644 index 0000000..d1a7fb5 --- /dev/null +++ b/sc4pd/headers/server/SC_SequencedCommand.h @@ -0,0 +1,481 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Having SequencedCommands allows performing actions that might otherwise require + * taking a mutex, which is undesirable in a real time thread. + * Some commands require several stages of processing at both the real time + * and non real time levels. This class does the messaging between levels for you + * so that you only need to write the functions. + */ + +#ifndef _SC_SequencedCommand_ +#define _SC_SequencedCommand_ + +#include "OSC_Packet.h" +#include "SC_World.h" +#include "SC_BufGen.h" +#include "sc_msg_iter.h" +#include +#include + +#define CallSequencedCommand(T, inWorld, inSize, inData, inReply) \ + void* space = World_Alloc(inWorld, sizeof(T)); \ + T *cmd = new (space) T(inWorld, inReply); \ + if (!cmd) return kSCErr_Failed; \ + int err = cmd->Init(inData, inSize); \ + if (err) { \ + cmd->~T(); \ + World_Free(inWorld, space); \ + return err; \ + } \ + if (inWorld->mRealTime) cmd->CallNextStage(); \ + else cmd->CallEveryStage(); + + +class SC_SequencedCommand +{ +public: + SC_SequencedCommand(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~SC_SequencedCommand(); + + void Delete(); + + void CallEveryStage(); + void CallNextStage(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage1(); // real time + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + + void SendDone(char *inCommandName); + +protected: + int mNextStage; + ReplyAddress mReplyAddress; + World *mWorld; + + int mMsgSize; + char *mMsgData; + + virtual void CallDestructor()=0; +}; + +/////////////////////////////////////////////////////////////////////////// + +class SyncCmd : public SC_SequencedCommand +{ +public: + SyncCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + virtual void CallDestructor(); + int mID; +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufGenCmd : public SC_SequencedCommand +{ +public: + BufGenCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufGenCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + BufGen *mBufGen; + sc_msg_iter mMsg; + char *mData; + int mSize; + SndBuf mSndBuf; + float *mFreeData; + + virtual void CallDestructor(); + +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufAllocCmd : public SC_SequencedCommand +{ +public: + BufAllocCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + SndBuf mSndBuf; + int mNumChannels, mNumFrames; + float *mFreeData; + + virtual void CallDestructor(); + +}; + +/////////////////////////////////////////////////////////////////////////// + + +class BufFreeCmd : public SC_SequencedCommand +{ +public: + BufFreeCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + float *mFreeData; + + virtual void CallDestructor(); +}; + + +/////////////////////////////////////////////////////////////////////////// + + +class BufCloseCmd : public SC_SequencedCommand +{ +public: + BufCloseCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + + virtual void CallDestructor(); +}; + + +/////////////////////////////////////////////////////////////////////////// + + +class BufZeroCmd : public SC_SequencedCommand +{ +public: + BufZeroCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufAllocReadCmd : public SC_SequencedCommand +{ +public: + BufAllocReadCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufAllocReadCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + float *mFreeData; + SndBuf mSndBuf; + char *mFilename; + int mFileOffset, mNumFrames; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufReadCmd : public SC_SequencedCommand +{ +public: + BufReadCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufReadCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + char *mFilename; + int mFileOffset, mNumFrames, mBufOffset; + bool mLeaveFileOpen; + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class BufWriteCmd : public SC_SequencedCommand +{ +public: + BufWriteCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~BufWriteCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + int mBufIndex; + char *mFilename; + SF_INFO mFileInfo; + int mNumFrames, mBufOffset; + bool mLeaveFileOpen; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class AudioQuitCmd : public SC_SequencedCommand +{ +public: + AudioQuitCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class AudioStatusCmd : public SC_SequencedCommand +{ +public: + AudioStatusCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual bool Stage2(); // non real time + +protected: + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class NotifyCmd : public SC_SequencedCommand +{ +public: + NotifyCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + +protected: + + virtual void CallDestructor(); + + int mOnOff; + int mID; +}; + + +/////////////////////////////////////////////////////////////////////////// + +#define CallSendFailureCommand(inWorld, inCmdName, inErrString, inReply) \ + void* space = World_Alloc(inWorld, sizeof(SendFailureCmd)); \ + SendFailureCmd *cmd = new (space) SendFailureCmd(inWorld, inReply); \ + if (!cmd) return kSCErr_Failed; \ + cmd->InitSendFailureCmd(inCmdName, inErrString); \ + if (inWorld->mRealTime) cmd->CallNextStage(); \ + else cmd->CallEveryStage(); \ + +class SendFailureCmd : public SC_SequencedCommand +{ +public: + SendFailureCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~SendFailureCmd(); + + virtual void InitSendFailureCmd(const char *inCmdName, const char* inErrString); + + virtual bool Stage2(); // non real time + +protected: + char *mCmdName, *mErrString; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +#include "SC_GraphDef.h" + +class LoadSynthDefCmd : public SC_SequencedCommand +{ +public: + LoadSynthDefCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~LoadSynthDefCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + char *mFilename; + GraphDef *mDefs; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +#include "SC_GraphDef.h" + +class RecvSynthDefCmd : public SC_SequencedCommand +{ +public: + RecvSynthDefCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~RecvSynthDefCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + char *mBuffer; + GraphDef *mDefs; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class LoadSynthDefDirCmd : public SC_SequencedCommand +{ +public: + LoadSynthDefDirCmd(World *inWorld, ReplyAddress *inReplyAddress); + virtual ~LoadSynthDefDirCmd(); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + char *mFilename; + GraphDef *mDefs; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +class SendReplyCmd : public SC_SequencedCommand +{ +public: + SendReplyCmd(World *inWorld, ReplyAddress *inReplyAddress); + + virtual int Init(char *inData, int inSize); + + virtual bool Stage2(); // non real time + +protected: + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + + +typedef bool (*AsyncStageFn)(World *inWorld, void* cmdData); +typedef void (*AsyncFreeFn)(World *inWorld, void* cmdData); + +class AsyncPlugInCmd : public SC_SequencedCommand +{ +public: + AsyncPlugInCmd(World *inWorld, ReplyAddress *inReplyAddress, + const char* cmdName, + void *cmdData, + AsyncStageFn stage2, // stage2 is non real time + AsyncStageFn stage3, // stage3 is real time - completion msg performed if stage3 returns true + AsyncStageFn stage4, // stage4 is non real time - sends done if stage4 returns true + AsyncFreeFn cleanup, + int completionMsgSize, + void* completionMsgData); + + virtual ~AsyncPlugInCmd(); + + virtual bool Stage2(); // non real time + virtual bool Stage3(); // real time + virtual void Stage4(); // non real time + +protected: + const char *mCmdName; + void *mCmdData; + AsyncStageFn mStage2, mStage3, mStage4; + AsyncFreeFn mCleanup; + + virtual void CallDestructor(); +}; + +/////////////////////////////////////////////////////////////////////////// + +#endif + diff --git a/sc4pd/headers/server/SC_Str4.h b/sc4pd/headers/server/SC_Str4.h new file mode 100644 index 0000000..306b823 --- /dev/null +++ b/sc4pd/headers/server/SC_Str4.h @@ -0,0 +1,103 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* a 4 byte aligned and zero padded string allows faster string operations. */ + +#ifndef _SC_Str4_ +#define _SC_Str4_ + +#include "Hash.h" +#include +#include + +#ifndef _LASTCHAR_ +#define _LASTCHAR_ +#if BYTE_ORDER == LITTLE_ENDIAN +const int32 kLASTCHAR = 0xFF000000; +#else +const int32 kLASTCHAR = 0x000000FF; +#endif +#endif + + +void str4cpy(int32 *dst, const char *src); +void mem4cpy(int32 *dst, const char *src, int charlen); + +// returns the number of pad bytes to add to a string of a given length +inline int str4padbytes(int charlen) +{ + return 4 - (charlen & 3); +} + +// converts length in bytes to length in words +inline int str4len(int charlen) +{ + return (charlen + 4) >> 2; +} + +// returns length in words of a char * +inline int str4len(const char *src) +{ + const char *src0 = src; + while (*src) { src++; } + return str4len(src - src0); +} + +// returns length in words of a int32 * +inline int str4len(const int32 *src) +{ + const int32 *src0 = src; + while (*src++ & kLASTCHAR) {} + int wordlen = src - src0; + return wordlen; +} + +// returns length in words of a int32 * +inline bool str4eq(const int32 *a, const int32 *b) +{ + while(true) { + if (*a != *b) return false; + if ((*a & kLASTCHAR) == 0) return true; + a++; b++; + } +} + +// copy an int32 * +inline void str4cpy(int32 *dst, const int32 *src) +{ + int32 c; + do { + *dst++ = c = *src++; + } while (c & kLASTCHAR); +} + +inline int sc_atoi(char *string) +{ + int value = 0; + if (*string == 0) return -1; + uint32 c; + while ((c = *string++ - '0') <= 9) { + value = value * 10 + c; + } + return value; +} + + +#endif diff --git a/sc4pd/headers/server/SC_SyncCondition.h b/sc4pd/headers/server/SC_SyncCondition.h new file mode 100755 index 0000000..a75fbaa --- /dev/null +++ b/sc4pd/headers/server/SC_SyncCondition.h @@ -0,0 +1,45 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SC_SyncCondition_ +#define _SC_SyncCondition_ + +#include + +class SC_SyncCondition +{ +public: + SC_SyncCondition(); + ~SC_SyncCondition(); + + void WaitEach(); + void WaitOnce(); + void WaitNext(); + void Signal(); + +private: + pthread_cond_t available; + pthread_mutex_t mutex; + int read, write; +}; + +#endif + diff --git a/sc4pd/headers/server/SC_SynthDef.h b/sc4pd/headers/server/SC_SynthDef.h new file mode 100644 index 0000000..89d5e47 --- /dev/null +++ b/sc4pd/headers/server/SC_SynthDef.h @@ -0,0 +1,43 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SynthDef_ +#define _SynthDef_ + +#include "SC_Types.h" +#include "sc_msg_iter.h" + +typedef void (*NodeDtorFunc)(struct Node* inNode); + +struct NodeDef +{ + int32 mName[kSCNameLen]; + int32 mHash; + + size_t mAllocSize; +}; +typedef struct NodeDef NodeDef; + +extern NodeDef gGroupNodeDef; + +void GroupNodeDef_Init(); +void NodeDef_Dump(NodeDef *inNodeDef); + +#endif diff --git a/sc4pd/headers/server/SC_UnitDef.h b/sc4pd/headers/server/SC_UnitDef.h new file mode 100644 index 0000000..0f75490 --- /dev/null +++ b/sc4pd/headers/server/SC_UnitDef.h @@ -0,0 +1,69 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _UnitDef_ +#define _UnitDef_ + +#include "SC_Types.h" +#include "SC_Unit.h" +#include "HashTable.h" + +struct PlugInCmd +{ + int32 mCmdName[kSCNameLen]; + int32 mHash; + PlugInCmdFunc mFunc; + void *mUserData; +}; + +struct UnitCmd +{ + int32 mCmdName[kSCNameLen]; + int32 mHash; + UnitCmdFunc mFunc; +}; + +struct UnitDef +{ + int32 mUnitDefName[kSCNameLen]; + int32 mHash; + + size_t mAllocSize; + UnitCtorFunc mUnitCtorFunc; + UnitDtorFunc mUnitDtorFunc; + + HashTable* mCmds; + uint32 mFlags; +}; + +extern "C" { +bool UnitDef_Create(char *inName, size_t inAllocSize, + UnitCtorFunc inCtor, UnitDtorFunc inDtor, uint32 inFlags); +bool UnitDef_AddCmd(char *inUnitDefName, char *inCmdName, UnitCmdFunc inFunc); +bool PlugIn_DefineCmd(char *inCmdName, PlugInCmdFunc inFunc, void *inUserData); +} + +int Unit_DoCmd(World *inWorld, int inSize, char *inData); + +inline int32* GetKey(UnitCmd *inCmd) { return inCmd->mCmdName; } +inline int32 GetHash(UnitCmd *inCmd) { return inCmd->mHash; } + + +#endif diff --git a/sc4pd/headers/server/SC_UnitSpec.h b/sc4pd/headers/server/SC_UnitSpec.h new file mode 100644 index 0000000..c72e103 --- /dev/null +++ b/sc4pd/headers/server/SC_UnitSpec.h @@ -0,0 +1,41 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_UnitSpec_ +#define _SC_UnitSpec_ + +#include // for size_t + +#include "SC_Unit.h" + +struct UnitSpec +{ + struct UnitDef* mUnitDef; + int16 mCalcRate; + uint16 mNumInputs, mNumOutputs; + int16 mSpecialIndex; + struct InputSpec* mInputSpec; + struct OutputSpec* mOutputSpec; + struct Rate* mRateInfo; + size_t mAllocSize; +}; +typedef struct UnitSpec UnitSpec; + +#endif diff --git a/sc4pd/headers/server/SC_WireSpec.h b/sc4pd/headers/server/SC_WireSpec.h new file mode 100644 index 0000000..33ea15c --- /dev/null +++ b/sc4pd/headers/server/SC_WireSpec.h @@ -0,0 +1,47 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _SC_WireSpec_ +#define _SC_WireSpec_ + +#include "SC_Types.h" + +struct InputSpec +{ + // read from file: + int16 mFromUnitIndex; + int16 mFromOutputIndex; + // computed: + int16 mWireIndex; +}; +typedef struct InputSpec InputSpec; + +struct OutputSpec +{ + // read from file: + int16 mCalcRate; + // computed: + int16 mWireIndex; + int16 mBufferIndex; + int16 mNumConsumers; +}; +typedef struct OutputSpec OutputSpec; + +#endif diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt new file mode 100755 index 0000000..2125a06 --- /dev/null +++ b/sc4pd/make-files.txt @@ -0,0 +1,6 @@ +# all the source files from the package +SRCDIR = source +SRCS= \ + main.cpp Dust.cpp MantissaMask.cpp Hasher.cpp Median.cpp \ + BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ + PinkNoise.cpp Dust2.cpp Crackle.cpp \ No newline at end of file diff --git a/sc4pd/makefile.max-msvc b/sc4pd/makefile.max-msvc new file mode 100644 index 0000000..8a1225f --- /dev/null +++ b/sc4pd/makefile.max-msvc @@ -0,0 +1,77 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for MSVC++ 6 and .NET +# +# usage: +# to build run "make -f makefile.max-msvc" +# + +!include config-max-msvc.txt + +# includes +INCPATH=/I$(MAXSDKPATH)\max-includes /I$(MAXSDKPATH)\msp-includes /I$(FLEXTPATH) /I./headers/plugin_interface /I./headers/common /I./headers/server /I./headers/app /I./headers/lang +LDFLAGS=/LIBPATH:$(FLEXTPATH) + +!ifdef MSVCPATH +INCPATH=$(INCPATH) /I$(MSVCPATH)\include +LDFLAGS=$(LDFLAGS) /LIBPATH:$(MSVCPATH)\lib +!endif + +!ifdef _DEBUG +LIBS=flext_d-maxwin.lib +!else +LIBS=flext-maxwin.lib +!endif + +LDFLAGS=$(LDFLAGS) /LIBPATH:$(MAXSDKPATH)\max-includes /LIBPATH:$(MAXSDKPATH)\msp-includes + +LIBS=$(LIBS) maxapi.lib maxaudio.lib + +# compiler definitions and flags +DEFS=/DFLEXT_SYS=1 $(UFLAGS) + +CFLAGS=/ML /GR- /GD /Ox /GX /Zp2 + +# the rest can stay untouched +# ---------------------------------------------- + +# all the source files from the package +!include make-files.txt + +# ----------------------------------------------- + +NAME=sc4pd +EXT=mxe +DIR=source + +all: $(OUTPATH) $(OUTPATH)\$(NAME).$(EXT) + +# remove build +clean: + -del /q $(OUTPATH) > nul + -rmdir $(OUTPATH) > nul + +OBJS= $(SRCS:.c=.obj) +OBJS= $(OBJS:.objpp=.obj) + + +$(OUTPATH): + -mkdir $(OUTPATH) > nul + +{$(DIR)}.cpp{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)/$@ + +{$(DIR)}.c{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)/$@ + + +$(OUTPATH)\$(NAME).$(EXT): $(OBJS) + cd $(OUTPATH) + link /DLL $(LDFLAGS) /out:$(NAME).$(EXT) /INCREMENTAL:NO $** $(LIBS) $(LIBPATH) + @-del *.exp + @-del *.lib + cd .. +!ifdef INSTPATH + @-if not exist $(INSTPATH) mkdir $(INSTPATH) + copy $@ $(INSTPATH) > nul +!endif diff --git a/sc4pd/makefile.pd-bcc b/sc4pd/makefile.pd-bcc new file mode 100644 index 0000000..41c06c2 --- /dev/null +++ b/sc4pd/makefile.pd-bcc @@ -0,0 +1,73 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for BorlandC++ +# +# usage: make -f makefile.pd-bcc +# +# --------------------------------------------- + +!include config-pd-bcc.txt + +# all the source files from the package +!include make-files.txt + +SETUPFUNCTION=$(NAME)_setup + +# flext stuff +TARGET=pdwin + +# includes, libs +INCPATH=-I$(BCCPATH)\include -I$(PDPATH)\src -I$(FLEXTPATH) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang +LIBPATH=-L$(BCCPATH)\lib -L$(PDPATH)\lib +LIBS=cw32.lib import32.lib C0D32.OBJ + +# compiler definitions and flags +DEFS=-DFLEXT_SYS=2 +CFLAGS=-tWD $(UFLAGS) + + +# the rest can stay untouched +# ---------------------------------------------- + +# default target +all: $(OUTPATH)\$(NAME).dll + +# remove build +clean: + -del /s /q $(OUTPATH) > nul + rmdir $(OUTPATH) + + +install: + cp $(OUTPATH)\$(NAME).dll $(INSTDIR) + +# ---------------------------------------------- + +OBJS= $(SRCS:.cpp=.obj) + +#.PATH.OBJ=$(OUTPATH) + +#$(SRCS): $(HDRS) +# -touch $< + +{$(SRCDIR)}.cpp.obj: + bcc32 -c $(CFLAGS) $(DEFS) $(INCPATH) -n$(OUTPATH) $< + +$(OUTPATH): + -@if not exist $< mkdir $< + +$(OUTPATH)\pd.lib: $(PDPATH)\bin\pd.dll + implib -a $< $** + +$(OUTPATH)\$(NAME).def: + @echo EXPORTS $(SETUPFUNCTION) = _$(SETUPFUNCTION) > $< +# this next line fixes a strange problem with implib - lacking underscore?! + @echo IMPORTS _rtext_retext=PD.rtext_retext >> $< + +$(OUTPATH)\$(NAME).dll :: $(OUTPATH) $(OUTPATH)\$(NAME).def $(OUTPATH)\pd.lib + +$(OUTPATH)\$(NAME).dll :: $(OBJS) + cd $(OUTPATH) + ilink32 -C -Tpd $(LIBPATH) $** ,..\$<,,$(LIBS) pd.lib $(FLEXTPATH)\flext-$(TARGET).lib ,$(NAME).def + cd .. + \ No newline at end of file diff --git a/sc4pd/makefile.pd-cygwin b/sc4pd/makefile.pd-cygwin new file mode 100644 index 0000000..a04569d --- /dev/null +++ b/sc4pd/makefile.pd-cygwin @@ -0,0 +1,86 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ cygwin +# +# usage: +# to build run "make -f makefile.pd-cygwin" +# to install (as root), do "make -f makefile.pd-cygwin install" +# + +CONFIG=config-pd-cygwin.txt +MAKEFILE=makefile.pd-cygwin + +include ${CONFIG} + + +# compiler stuff +# /usr/include holds the cygwin pthread headers and must be first! +INCLUDES=/usr/include $(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang + +FLAGS=-DFLEXT_SYS=2 +CFLAGS=-O2 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions ${UFLAGS} + +PDLIBS=$(PD)/bin/pd.dll $(PD)/bin/pthreadVC.dll + + +ifdef FLEXT_SHARED + +CFLAGS+=-DFLEXT_SHARED +FLEXTLIB=$(FLEXTPATH)/flext.dll + +else + +FLEXTLIB=$(FLEXTPATH)/flext-pdwin.lib + +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +include make-files.txt + +TARGET=$(TARGDIR)/$(NAME).dll + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) -shared $(LDFLAGS) $^ ${PDLIBS} $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) +# chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) diff --git a/sc4pd/makefile.pd-darwin b/sc4pd/makefile.pd-darwin new file mode 100755 index 0000000..04a3779 --- /dev/null +++ b/sc4pd/makefile.pd-darwin @@ -0,0 +1,77 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ OSX (darwin) +# +# usage: +# to build run "make -f makefile.pd-darwin" +# to install (as root), do "make -f makefile.pd-darwin install" +# to install help, do "make -f makefile.pd-darwin install-help" +# + +CONFIG=config-pd-darwin.txt + +include ${CONFIG} + +FLEXTLIB=$(FLEXTPATH)/libflext.a + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang +FLAGS=-DFLEXT_SYS=2 +CFLAGS=${UFLAGS} -dynamic -O2 -Wno-unused -Wno-parentheses -Wno-switch -Wstrict-prototypes -funroll-loops -fmove-all-movables -frerun-loop-opt -fno-rtti -fno-exceptions +LIBS=m gcc +LDFLAGS=$(FLEXTLIB) -bundle -bundle_loader $(PDBIN) +FRAMEWORKS=Carbon veclib + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4dp + +include make-files.txt + +MAKEFILE=makefile.pd-darwin +TARGET=$(TARGDIR)/$(NAME).pd_darwin + + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) + $(CXX) $(LDFLAGS) $^ $(patsubst %,-framework %,$(FRAMEWORKS)) $(patsubst %,-L%,$(LIBPATH)) $(patsubst %,-l%,$(LIBS)) -o $@ + chmod 755 $@ + + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp -R $^ $(INSTDIR) +# chown -R root.root $(INSTDIR) + + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + cp $^/*.* $(HELPDIR) +# chown -R root.root $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) + diff --git a/sc4pd/makefile.pd-linux b/sc4pd/makefile.pd-linux new file mode 100644 index 0000000..994141c --- /dev/null +++ b/sc4pd/makefile.pd-linux @@ -0,0 +1,94 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ linux +# +# usage: +# to build run "make -f makefile.pd-linux" +# to install (as root), do "make -f makefile.pd-linux install" +# + +CONFIG=config-pd-linux.txt + +include ${CONFIG} + +FLEXTLIB=$(FLEXTPATH)/flext.a + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common \ + ./headers/server ./headers/app ./headers/lang +FLAGS=-DFLEXT_SYS=2 +CFLAGS=${UFLAGS} -O3 -I/home/tim/pd/externals/grill/flext/source -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions + +LIBS=m + +ifdef FLEXT_SHARED +CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS +LDFLAGS+=-Bdynamic +LINKFLEXT=-lflext +else +LINKFLEXT=$(FLEXTLIB) +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +include make-files.txt + +MAKEFILE=makefile.pd-linux +TARGET=$(TARGDIR)/$(NAME).pd_linux + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) + touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) + $(CXX) $(LDFLAGS) -shared $^ $(patsubst %,-l%,$(LIBS)) -L$(FLEXTPATH) $(LINKFLEXT) -o $@ + #strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) + chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) + + + + + + + + + + + + diff --git a/sc4pd/makefile.pd-mingw b/sc4pd/makefile.pd-mingw new file mode 100644 index 0000000..62cf1ae --- /dev/null +++ b/sc4pd/makefile.pd-mingw @@ -0,0 +1,85 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for gcc @ minGW +# +# usage: +# to build run "make -f makefile.pd-mingw" +# to install (as root), do "make -f makefile.pd-mingw install" +# + +CONFIG=config-pd-mingw.txt +MAKEFILE=makefile.pd-mingw + +include ${CONFIG} + + +# compiler stuff +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang + +FLAGS=-DFLEXT_SYS=2 +CFLAGS=-O2 -funroll-loops -fmove-all-movables -frerun-loop-opt -finline-functions -fno-rtti -fno-exceptions ${UFLAGS} + +PDLIBS=$(PD)/bin/pd.dll $(PD)/bin/pthreadVC.dll + + +ifdef FLEXT_SHARED + +CFLAGS+=-DFLEXT_SHARED +FLEXTLIB=$(FLEXTPATH)/flext.dll + +else + +FLEXTLIB=$(FLEXTPATH)/flext-pdwin.lib + +endif + + +# ---------------------------------------------- +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +include make-files.txt + +TARGET=$(TARGDIR)/$(NAME).dll + +# default target +all: $(TARGDIR) $(TARGET) + +$(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) +# echo touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) # minGW has no touch + +$(TARGDIR): + -mkdir $(TARGDIR) + +$(TARGDIR)/%.o : $(SRCDIR)/%.cpp + $(CXX) -c $(CFLAGS) $(FLAGS) $(patsubst %,-I%,$(INCLUDES) $(FLEXTPATH)) $< -o $@ + +$(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(FLEXTLIB) + $(CXX) -shared $(LDFLAGS) $^ ${PDLIBS} $(patsubst %,-l%,$(LIBS)) -o $@ + strip --strip-unneeded $@ + chmod 755 $@ + +$(INSTDIR): + -mkdir $(INSTDIR) + +install:: $(INSTDIR) + +install:: $(TARGET) + cp $^ $(INSTDIR) +# chown root.root $(patsubst %,$(INSTDIR)/%,$(notdir $^)) + +$(HELPDIR): + -mkdir $(HELPDIR) + +install-help:: $(HELPDIR) + +install-help:: ./pd + chmod 644 $^/*.* + cp $^/*.* $(HELPDIR) + + +.PHONY: clean +clean: + rm -f $(TARGDIR)/*.o $(TARGET) diff --git a/sc4pd/makefile.pd-msvc b/sc4pd/makefile.pd-msvc new file mode 100644 index 0000000..11ccda9 --- /dev/null +++ b/sc4pd/makefile.pd-msvc @@ -0,0 +1,53 @@ +# makefile adapted from thomas grill's xsample makefile +# +# Makefile for MSVC++ 6 +# +# usage: +# to build run "make -f makefile.pd-msvc" +# + +!include config-pd-msvc.txt + +# includes +INCPATH=/I"$(MSVCPATH)\include" /I"$(PDPATH)\src" /I"$(FLEXTPATH)" /I"./headers/plugin_interface" /I"./headers/common" /I"/headers/server" /I"./headers/app" /I"./headers/lang +LIBPATH=/LIBPATH:"$(MSVCPATH)\lib" /LIBPATH:"$(PDPATH)\bin" /LIBPATH:"$(FLEXTPATH)" +LIBS=pd.lib pthreadVC.lib flext-pdwin.lib + +# compiler definitions and flags +DEFS=/DFLEXT_SYS=2 + +CFLAGS=/GR- /GX- /GD /G6 /Ox /EHsc /ML + +# the rest can stay untouched +# ---------------------------------------------- + +NAME=sc4pd + +!include make-files.txt + + +all: $(OUTPATH) $(OUTPATH)\$(NAME).dll + +# remove build +clean: + -del /q $(OUTPATH) > nul + -rmdir $(OUTPATH) > nul + +OBJS= $(SRCS:.cpp=.obj) + +$(OUTPATH): + -mkdir $(OUTPATH) > nul + +{$(SRCDIR)}.cpp{}.obj: + cl /c /LD $(CFLAGS) $(DEFS) $(INCPATH) $** /Fo$(OUTPATH)\$@ + +$(OUTPATH)\$(NAME).dll: $(OBJS) + cd $(OUTPATH) + link /DLL /out:$(NAME).dll /INCREMENTAL:NO $** $(LIBS) $(LIBPATH) + @-del *.exp + @-del *.lib + cd .. +!ifdef INSTPATH + @-if not exist $(INSTPATH) mkdir $(INSTPATH) + copy $@ $(INSTPATH) > nul +!endif diff --git a/sc4pd/pd/crackle.pd b/sc4pd/pd/crackle.pd new file mode 100644 index 0000000..7cbb5a0 --- /dev/null +++ b/sc4pd/pd/crackle.pd @@ -0,0 +1,10 @@ +#N canvas 0 0 450 300 10; +#X obj 266 210 dac~; +#X obj 279 128 Crackle~ 2; +#X obj 369 196 print~; +#X obj 378 161 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 1 0 2 0; +#X connect 3 0 2 0; diff --git a/sc4pd/pd/dust.pd b/sc4pd/pd/dust.pd new file mode 100644 index 0000000..6a709ec --- /dev/null +++ b/sc4pd/pd/dust.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X obj 96 130 dac~; +#X floatatom 264 119 5 0 0 0 - - -; +#X obj 123 109 Median~ 20; +#X obj 72 51 Dust~ 600; +#X obj 123 82 Dust~ 1000; +#X obj 264 82 Dust 1; +#X connect 2 0 0 1; +#X connect 3 0 0 0; +#X connect 4 0 2 0; +#X connect 5 0 1 0; diff --git a/sc4pd/pd/hasher.pd b/sc4pd/pd/hasher.pd new file mode 100644 index 0000000..532f032 --- /dev/null +++ b/sc4pd/pd/hasher.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 18 28 osc~ 441; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 266 78 Hasher; +#X obj 18 86 Hasher~; +#X connect 0 0 7 0; +#X connect 3 0 2 0; +#X connect 4 0 6 0; +#X connect 6 0 5 0; +#X connect 7 0 2 0; +#X connect 7 0 1 0; +#X connect 7 0 1 1; diff --git a/sc4pd/pd/mantissamask.pd b/sc4pd/pd/mantissamask.pd new file mode 100644 index 0000000..5e2d3ed --- /dev/null +++ b/sc4pd/pd/mantissamask.pd @@ -0,0 +1,21 @@ +#N canvas 0 0 450 300 10; +#X obj 18 28 osc~ 441; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 18 86 MantissaMask~ 3; +#X floatatom 112 20 5 0 0 0 - - -; +#X msg 89 60 set \$1; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 266 78 MantissaMask 0; +#X connect 0 0 4 0; +#X connect 3 0 2 0; +#X connect 4 0 2 0; +#X connect 4 0 1 0; +#X connect 4 0 1 1; +#X connect 5 0 6 0; +#X connect 6 0 4 0; +#X connect 7 0 9 0; +#X connect 9 0 8 0; diff --git a/sc4pd/readme.txt b/sc4pd/readme.txt new file mode 100644 index 0000000..7372555 --- /dev/null +++ b/sc4pd/readme.txt @@ -0,0 +1,23 @@ +sc4pd: SuperCollider for PureData +(c) 2004 Tim Blechmann + +sc4pd includes the SuperCollider header files and is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + +Both SuperCollider and sc4pd are released under the GPL + + +sc4pd is a port of some SuperCollider UGens to PD objects. If you want to link +both applications, it's better to use jack. +sc4pd is using thomas grill's flext and should be portable to max/msp. + + +thanks to: + James McCartney for SuperCollider + Miller Puckette for PureData + Thomas Grill for Flext + three great pieces of software... + +bugs, suggestions, complains to: TimBlechmann@gmx.de \ No newline at end of file diff --git a/sc4pd/source/BrownNoise.cpp b/sc4pd/source/BrownNoise.cpp new file mode 100644 index 0000000..39cbc26 --- /dev/null +++ b/sc4pd/source/BrownNoise.cpp @@ -0,0 +1,150 @@ +/* sc4pd + BrownNoise, BrownNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: AMM: Laminal + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ BrownNoise~ -------------------------------*/ + +class BrownNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(BrownNoise_ar,flext_dsp); + +public: + BrownNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + float m_level; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("BrownNoise~",BrownNoise_ar); + +BrownNoise_ar::BrownNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + m_level=rgen.frand2(); + + AddOutSignal(); +} + + +void BrownNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + + float z = m_level; + + for (int i = 0; i!= n;++i) + { + z += frand8(s1, s2, s3); + if (z > 1.f) + z = 2.f - z; + else + if (z < -1.f) + z = -2.f - z; + (*(nout)++) = z; + } + m_level = z; + + RPUT; +} + + +/* ------------------------ BrownNoise ---------------------------------*/ + +class BrownNoise_kr: + public flext_base +{ + FLEXT_HEADER(BrownNoise_kr,flext_base); + +public: + BrownNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + float m_level; + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("BrownNoise",BrownNoise_kr); + +BrownNoise_kr::BrownNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + m_level=rgen.frand2(); + + AddOutFloat(); +} + +void BrownNoise_kr::m_perform() +{ + float z = m_level + rgen.frand8(); + if (z > 1.f) + z = 2.f - z; + else + if (z < -1.f) + z = -2.f - z; + ToOutFloat(0,z); + m_level = z; +} diff --git a/sc4pd/source/ClipNoise.cpp b/sc4pd/source/ClipNoise.cpp new file mode 100644 index 0000000..14b5101 --- /dev/null +++ b/sc4pd/source/ClipNoise.cpp @@ -0,0 +1,130 @@ +/* sc4pd + ClipNoise, ClipNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Henry Threadgill: Everybodys Mouth's A Book + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ ClipNoise~ -------------------------------*/ + +class ClipNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(ClipNoise_ar,flext_dsp); + +public: + ClipNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + RGen rgen; +}; + +FLEXT_LIB_DSP_V("ClipNoise~",ClipNoise_ar); + +ClipNoise_ar::ClipNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + + +void ClipNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = fcoin(s1, s2, s3); + } + + RPUT; +} + + +/* ------------------------ ClipNoise ---------------------------------*/ + +class ClipNoise_kr: + public flext_base +{ + FLEXT_HEADER(ClipNoise_kr,flext_base); + +public: + ClipNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("ClipNoise",ClipNoise_kr); + +ClipNoise_kr::ClipNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutFloat(); +} + +void ClipNoise_kr::m_perform() +{ + ToOutFloat(0,rgen.fcoin()); +} diff --git a/sc4pd/source/Crackle.cpp b/sc4pd/source/Crackle.cpp new file mode 100644 index 0000000..a86ea18 --- /dev/null +++ b/sc4pd/source/Crackle.cpp @@ -0,0 +1,161 @@ +/* sc4pd + Crackle, Crackle~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: David S. Ware: Threads + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ Crackle~ -------------------------------*/ + +class Crackle_ar: + public flext_dsp +{ + FLEXT_HEADER(Crackle_ar,flext_dsp); + +public: + Crackle_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_paramf = f; + } + +private: + FLEXT_CALLBACK_F(m_set); + float m_paramf; + float m_y1, m_y2; +}; + +FLEXT_LIB_DSP_V("Crackle~",Crackle_ar); + +Crackle_ar::Crackle_ar(int argc, t_atom *argv) + : m_y1(0.3f),m_y2(0.f) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + //parse arguments + AtomList Args(argc,argv); + m_paramf=sc_getfloatarg(Args,0); + + if (m_paramf == 0) + m_paramf = 1; + + AddOutSignal(); +} + + +void Crackle_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float paramf = m_paramf; + float y1 = m_y1; + float y2 = m_y2; + float y0; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = y0 = fabs(y1 * paramf - y2 - 0.05f); + y2 = y1; + y1 = y0; + } + + m_y1=y1; + m_y2=y2; +} + + +/* ------------------------ Crackle ---------------------------------*/ + +class Crackle_kr: + public flext_base +{ + FLEXT_HEADER(Crackle_kr,flext_base); + +public: + Crackle_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_set(float f) + { + m_paramf = f; + } + +private: + float m_paramf; + float m_y1, m_y2; + FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("Crackle",Crackle_kr); + +Crackle_kr::Crackle_kr(int argc, t_atom *argv) + : m_y1(0.3f),m_y2(0.f) +{ + FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + m_paramf=sc_getfloatarg(Args,0); + + if (m_paramf == 0) + m_paramf = 1; + + AddOutFloat(); +} + +void Crackle_kr::m_perform() +{ + float y0 = fabs(m_y1 * m_paramf - m_y2 - 0.05f); + m_y2 = m_y1; + m_y1 = y0; + + ToOutFloat(0,y0); +} diff --git a/sc4pd/source/Dust.cpp b/sc4pd/source/Dust.cpp new file mode 100644 index 0000000..19b6312 --- /dev/null +++ b/sc4pd/source/Dust.cpp @@ -0,0 +1,179 @@ +/* sc4pd: + Dust, Dust~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Assif Tsahar & Tatsuya Nakatani: Come Sunday +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Dust~ -------------------------------------*/ + +class Dust_ar: + public flext_dsp +{ + FLEXT_HEADER(Dust_ar,flext_dsp); + +public: + Dust_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_density = f; + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; + } + +private: + FLEXT_CALLBACK_F(m_set); + float m_density, m_thresh, m_scale; + RGen rgen; + +}; + +FLEXT_LIB_DSP_V("Dust~",Dust_ar); + +Dust_ar::Dust_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + +void Dust_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; +} + +void Dust_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + float thresh = m_thresh; + float scale = m_scale; + + for (int i = 0; i!= n;++i) + { + float z = frand(s1,s2,s3); + if (z < thresh) + (*(nout)++) = z * scale; + else + (*(nout)++) = 0.f; + } + + RPUT; +} + + +/* ------------------------ Dust ---------------------------------------*/ + +class Dust_kr: + public flext_base +{ + FLEXT_HEADER(Dust_kr,flext_base); + +public: + Dust_kr(int argc, t_atom *argv); + +protected: + void m_set(float f); + Timer Dust_timer; + void m_doit(); + +private: + float m_density, m_scale; + float mtbt; //medium time between trigger + RGen rgen; + FLEXT_CALLBACK_1(m_set,float); + FLEXT_CALLBACK_T(m_doit); +}; + +FLEXT_LIB_V("Dust",Dust_kr); + +Dust_kr::Dust_kr(int argc, t_atom *argv) + : Dust_timer(false) +{ + FLEXT_ADDMETHOD(0,m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + AddOutFloat(); + + FLEXT_ADDTIMER(Dust_timer,m_doit); + + m_set(m_density); +} + +void Dust_kr::m_set(float f) +{ + Dust_timer.Reset(); + + if(f==0) + { + return; + } + m_density = f; + mtbt = 1/f*1000; + + Dust_timer.Delay(mtbt * 0.002 * rgen.frand()); +} + +void Dust_kr::m_doit() +{ + ToOutFloat(0,rgen.frand()); + + Dust_timer.Delay(mtbt * 0.002 * rgen.frand()); +} diff --git a/sc4pd/source/Dust2.cpp b/sc4pd/source/Dust2.cpp new file mode 100644 index 0000000..a8cbbc3 --- /dev/null +++ b/sc4pd/source/Dust2.cpp @@ -0,0 +1,180 @@ +/* sc4pd: + Dust2, Dust2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Herbert Eimert: Epitaph für Aikichi Kuboyama + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Dust2~ -------------------------------------*/ + +class Dust2_ar: + public flext_dsp +{ + FLEXT_HEADER(Dust2_ar,flext_dsp); + +public: + Dust2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_density = f; + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; + } + +private: + FLEXT_CALLBACK_F(m_set); + float m_density, m_thresh, m_scale; + RGen rgen; + +}; + +FLEXT_LIB_DSP_V("Dust2~",Dust2_ar); + +Dust2_ar::Dust2_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + +void Dust2_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + m_thresh = m_density/Samplerate(); + m_scale = m_thresh > 0.f ? 2.f / m_thresh : 0.f; +} + +void Dust2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + float thresh = m_thresh; + float scale = m_scale; + + for (int i = 0; i!= n;++i) + { + float z = frand(s1,s2,s3); + if (z < thresh) + (*(nout)++) = z * scale - 1.f; + else + (*(nout)++) = 0.f; + } + + RPUT; +} + + +/* ------------------------ Dust2 ---------------------------------------*/ + +class Dust2_kr: + public flext_base +{ + FLEXT_HEADER(Dust2_kr,flext_base); + +public: + Dust2_kr(int argc, t_atom *argv); + +protected: + void m_set(float f); + Timer Dust2_timer; + void m_doit(); + +private: + float m_density, m_scale; + float mtbt; //medium time between trigger + RGen rgen; + FLEXT_CALLBACK_1(m_set,float); + FLEXT_CALLBACK_T(m_doit); +}; + +FLEXT_LIB_V("Dust2",Dust2_kr); + +Dust2_kr::Dust2_kr(int argc, t_atom *argv) + : Dust2_timer(false) +{ + FLEXT_ADDMETHOD(0,m_set); + + //parse arguments + AtomList Args(argc,argv); + m_density=sc_getfloatarg(Args,0); + + rgen.init(0); //set seed to 0 + AddOutFloat(); + + FLEXT_ADDTIMER(Dust2_timer,m_doit); + + m_set(m_density); +} + +void Dust2_kr::m_set(float f) +{ + Dust2_timer.Reset(); + + if(f==0) + { + return; + } + m_density = f; + mtbt = 1/f*1000; + + Dust2_timer.Delay(mtbt * 0.002 * rgen.frand()); +} + +void Dust2_kr::m_doit() +{ + ToOutFloat(0,2*rgen.frand() - 1 ); + + Dust2_timer.Delay(mtbt * 0.002 * rgen.frand()); +} diff --git a/sc4pd/source/GrayNoise.cpp b/sc4pd/source/GrayNoise.cpp new file mode 100644 index 0000000..8628bca --- /dev/null +++ b/sc4pd/source/GrayNoise.cpp @@ -0,0 +1,137 @@ +/* sc4pd + GrayNoise, GrayNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe: Harsh + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ GrayNoise~ -------------------------------*/ + +class GrayNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(GrayNoise_ar,flext_dsp); + +public: + GrayNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + int m_counter; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("GrayNoise~",GrayNoise_ar); + +GrayNoise_ar::GrayNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + + +void GrayNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + int counter = m_counter; + + for (int i = 0; i!= n;++i) + { + counter ^= 1L << (trand(s1,s2,s3) & 31); + (*(nout)++) = counter * 4.65661287308e-10f; + } + + m_counter=counter; + RPUT; +} + + +/* ------------------------ GrayNoise ---------------------------------*/ + +class GrayNoise_kr: + public flext_base +{ + FLEXT_HEADER(GrayNoise_kr,flext_base); + +public: + GrayNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + int m_counter; + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("GrayNoise",GrayNoise_kr); + +GrayNoise_kr::GrayNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutFloat(); +} + +void GrayNoise_kr::m_perform() +{ + m_counter ^= 1L << (rgen.trand() & 31); + m_counter * 4.65661287308e-10f; + ToOutFloat(0,m_counter * 4.65661287308e-10f); +} diff --git a/sc4pd/source/Hasher.cpp b/sc4pd/source/Hasher.cpp new file mode 100644 index 0000000..9fc2f48 --- /dev/null +++ b/sc4pd/source/Hasher.cpp @@ -0,0 +1,122 @@ +/* sc4pd + Hasher~, Hasher + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Philip Jeck: Stoke + +*/ + +#include +#include "support.hpp" +#include "SC_PlugIn.h" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Hasher~ -----------------------------------*/ + +class Hasher_ar + :public flext_dsp +{ + FLEXT_HEADER(Hasher_ar,flext_dsp); + +public: + Hasher_ar(); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); +private: + +}; + +FLEXT_LIB_DSP("Hasher~",Hasher_ar); + +Hasher_ar::Hasher_ar() +{ + AddOutSignal(); +} + +void Hasher_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + int32 *nin = (int32*)*in; + t_sample *nout = *out; + + for (int i = 0; i!= n;++i) + { + union { float f; int i; } u; + int z = (*(nin)++); + u.i = 0x40000000 | ((uint32)Hash(z) >> 9); + (*(nout)++) = u.f -3.f; + } +} + + +/* ------------------------ Hasher ------------------------------------*/ + +class Hasher_kr + :public flext_base +{ + FLEXT_HEADER(Hasher_kr,flext_base); + +public: + Hasher_kr(); + +protected: + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB("Hasher",Hasher_kr); + +Hasher_kr::Hasher_kr() +{ + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); +} + +void Hasher_kr::m_perform(float f) +{ + int32 * fi = (int32*) &f; + + union { float f; int i; } u; + int z = *fi; + u.i = 0x40000000 | ((uint32)Hash(z) >> 9); + + ToOutFloat(0,u.f -3.f); +} diff --git a/sc4pd/source/MantissaMask.cpp b/sc4pd/source/MantissaMask.cpp new file mode 100644 index 0000000..d3a867d --- /dev/null +++ b/sc4pd/source/MantissaMask.cpp @@ -0,0 +1,160 @@ +/* sc4pd + MantissaMask~, MantissaMask + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Wolfgang Mitterer: Amusie + +*/ + +#include +#include "support.hpp" +#include "SC_PlugIn.h" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ MantissaMask~ -----------------------------*/ + +class MantissaMask_ar + :public flext_dsp +{ + FLEXT_HEADER(MantissaMask_ar,flext_dsp); + +public: + MantissaMask_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + int32 mask; + +}; + +FLEXT_LIB_DSP_V("MantissaMask~",MantissaMask_ar); + +MantissaMask_ar::MantissaMask_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + AtomList Args(argc,argv); + int bits = sc_getfloatarg(Args,0); + + AddOutSignal(); + + mask = -1 << (23 - bits); + +} + +void MantissaMask_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + int32 *nout = (int32*)*out; + int32 *nin = (int32*)*in; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = mask & (*(nin)++); + } +} + +void MantissaMask_ar::m_set(float f) +{ + int bits = (int) f; + if ( bits < 0 || bits > 23) + { + post("value doesn't make sense"); + return; + } + mask = -1 << (23 - bits); +} + +/* ------------------------ MantissaMask ------------------------------*/ + +class MantissaMask_kr + :public flext_base +{ + FLEXT_HEADER(MantissaMask_kr,flext_base); + +public: + MantissaMask_kr(int argc,t_atom * argv); + +protected: + void m_set(float f); + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); + int32 mask; +}; + +FLEXT_LIB_V("MantissaMask",MantissaMask_kr); + +MantissaMask_kr::MantissaMask_kr(int argc,t_atom * argv) +{ + + AtomList Args(argc,argv); + int bits = sc_getfloatarg(Args,0); + + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"set",m_set); + mask = -1 << (23 - bits); +} + +void MantissaMask_kr::m_perform(float f) +{ + float g; + int32 *gp = (int32*) &g; + + *(gp) = mask & *((int32*) &f); + + ToOutFloat(0,g); +} + +void MantissaMask_kr::m_set(float f) +{ + int bits = (int) f; + if ( bits < 0 || bits > 23) + { + post("value doesn't make sense"); + return; + } + mask = -1 << (23 - bits); +} diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp new file mode 100644 index 0000000..77b0a5d --- /dev/null +++ b/sc4pd/source/Median.cpp @@ -0,0 +1,220 @@ +/* sc4pd + Median, Median~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Morton Feldman: For John Cage + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Median(~) ---------------------------------*/ + + +const int kMAXMEDIANSIZE = 32; + +class median_shared +{ +public: + + inline void Init(long size, float value); + inline float Insert(float value); + +private: + float m_medianValue[kMAXMEDIANSIZE]; + long m_medianAge[kMAXMEDIANSIZE]; + long m_medianSize, m_medianIndex; +}; + +void median_shared::Init(long size, float value) +{ + // initialize the arrays with the first value + m_medianSize = size; + for (int i=0; i>1] + + last = m_medianSize - 1; + // find oldest bin and age the other bins. + for (i=0; i m_medianValue[pos+1]) { + m_medianValue[pos] = m_medianValue[pos+1]; + m_medianAge[pos] = m_medianAge[pos+1]; + pos++; + } + m_medianValue[pos] = value; + m_medianAge[pos] = 0; // this is the newest bin, age = 0 + return m_medianValue[m_medianSize>>1]; +} + + +/* ------------------------ Median~ -----------------------------------*/ + +class Median_ar + :public flext_dsp +{ + FLEXT_HEADER(Median_ar,flext_dsp); + +public: + Median_ar(int argc, t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp (int n,t_signalvec const * insigs, + t_signalvec const * outsigs); + + void m_set(float f) + { + m_size=(int)f; + Median.Init(m_size,Median.Insert(0)); /* this is not beautiful, but i'm not + aware of a nicer way */ + } + +private: + FLEXT_CALLBACK_F(m_set); + + median_shared Median; //median + int m_size; //median size +}; + +FLEXT_LIB_DSP_V("Median~",Median_ar); + +Median_ar::Median_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + + AtomList Args(argc,argv); + m_size=sc_getfloatarg(Args,0); + + AddOutSignal(); +} + +void Median_ar::m_dsp(int n,t_signalvec const * insigs, + t_signalvec const * outsigs) +{ + Median.Init(m_size,0); //how is this done in SuperCollider? +} + +void Median_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = Median.Insert(*(nin)++); + } +} + + +/* ------------------------ Median ------------------------------------*/ + +class Median_kr + :public flext_dsp +{ + FLEXT_HEADER(Median_kr,flext_dsp); + +public: + Median_kr(int argc, t_atom * argv); + +protected: + void m_set(float f) + { + m_size=(int)f; + Median.Init(m_size,Median.Insert(0)); /* this is not beautiful, but i'm not + aware of a nicer way */ + } + void m_perform(float f); + +private: + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); + + median_shared Median; //median + int m_size; //median size +}; + +FLEXT_LIB_V("Median",Median_kr); + +Median_kr::Median_kr(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD(0,m_perform); + + + AtomList Args(argc,argv); + m_size=sc_getfloatarg(Args,0); + + float m_set=sc_getfloatarg(Args,1); + + Median.Init(m_size,m_set); + AddOutSignal(); +} + +void Median_kr::m_perform(float f) +{ + ToOutFloat(0,Median.Insert(f)); +} diff --git a/sc4pd/source/PinkNoise.cpp b/sc4pd/source/PinkNoise.cpp new file mode 100644 index 0000000..bf6db62 --- /dev/null +++ b/sc4pd/source/PinkNoise.cpp @@ -0,0 +1,168 @@ +/* sc4pd + PinkNoise, PinkNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Gottfried Michael Koenig: Klangfiguren II + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ PinkNoise~ -------------------------------*/ + +class PinkNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(PinkNoise_ar,flext_dsp); + +public: + PinkNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + uint32 m_dice[16]; + int32 m_total; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("PinkNoise~",PinkNoise_ar); + +PinkNoise_ar::PinkNoise_ar(int argc, t_atom *argv) + : m_total(0) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + for (int i=0; i<16; ++i) + { + uint32 newrand = rgen.trand() >> 13; + m_total += newrand; + m_dice[i] = newrand; + } + + AddOutSignal(); +} + + +void PinkNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + uint32 total = m_total; + uint32 *dice = m_dice; + + for (int i = 0; i!= n;++i) + { + uint32 counter = trand(s1,s2,s3); // Magnus Jonsson's suggestion. + uint32 newrand = counter >> 13; + int k = (CTZ(counter)) & 15; + uint32 prevrand = dice[k]; + dice[k] = newrand; + total += (newrand - prevrand); + newrand = trand(s1,s2,s3) >> 13; + uint32 ifval = (total + newrand) | 0x40000000; + (*(nout)++) = ((*(float*)&ifval) - 3.0f); + } + RPUT; +} + + +/* ------------------------ PinkNoise ---------------------------------*/ + +class PinkNoise_kr: + public flext_base +{ + FLEXT_HEADER(PinkNoise_kr,flext_base); + +public: + PinkNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + uint32 m_dice[16]; + int32 m_total; + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("PinkNoise",PinkNoise_kr); + +PinkNoise_kr::PinkNoise_kr(int argc, t_atom *argv) + : m_total(0) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + for (int i=0; i<16; ++i) + { + uint32 newrand = rgen.trand() >> 13; + m_total += newrand; + m_dice[i] = newrand; + } + + AddOutFloat(); +} + +void PinkNoise_kr::m_perform() +{ + uint32 counter = rgen.trand(); // Magnus Jonsson's suggestion. + uint32 newrand = counter >> 13; + int k = (CTZ(counter)) & 15; + uint32 prevrand = m_dice[k]; + m_dice[k] = newrand; + m_total += (newrand - prevrand); + newrand = rgen.trand() >> 13; + uint32 ifval = (m_total + newrand) | 0x40000000; + + ToOutFloat(0,((*(float*)&ifval) - 3.0f)); +} diff --git a/sc4pd/source/WhiteNoise.cpp b/sc4pd/source/WhiteNoise.cpp new file mode 100644 index 0000000..ecedf3d --- /dev/null +++ b/sc4pd/source/WhiteNoise.cpp @@ -0,0 +1,130 @@ +/* sc4pd + WhiteNoise, WhiteNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Otomo Yoshihide: Ensemble Cathode + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ WhiteNoise~ -------------------------------*/ + +class WhiteNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(WhiteNoise_ar,flext_dsp); + +public: + WhiteNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + RGen rgen; +}; + +FLEXT_LIB_DSP_V("WhiteNoise~",WhiteNoise_ar); + +WhiteNoise_ar::WhiteNoise_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutSignal(); +} + + +void WhiteNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + RGET; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = frand2(s1, s2, s3); + } + + RPUT +} + + +/* ------------------------ WhiteNoise ---------------------------------*/ + +class WhiteNoise_kr: + public flext_base +{ + FLEXT_HEADER(WhiteNoise_kr,flext_base); + +public: + WhiteNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + +private: + RGen rgen; + FLEXT_CALLBACK(m_perform); +}; + +FLEXT_LIB_V("WhiteNoise",WhiteNoise_kr); + +WhiteNoise_kr::WhiteNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(0); //set seed to 0 + + AddOutFloat(); +} + +void WhiteNoise_kr::m_perform() +{ + ToOutFloat(0,rgen.frand2()); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp new file mode 100644 index 0000000..d7b187b --- /dev/null +++ b/sc4pd/source/main.cpp @@ -0,0 +1,91 @@ +/* sc4pd library initialization + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phosphor + +*/ + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +#define SC4PD_VERSION "0.01" + +void sc4pd_library_setup() +{ + post("\nsc4pd: by tim blechmann"); + post("based on SuperCollider by James McCartney"); + post("version "SC4PD_VERSION); + post("compiled on "__DATE__); + post("contains: Dust(~), MantissaMask(~), Hasher(~), Median(~), " + "BrownNoise(~),"); + post(" ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " + "PinkNoise(~)\n"); + + //initialize objects + FLEXT_DSP_SETUP(Dust_ar); + FLEXT_SETUP(Dust_kr); + + FLEXT_DSP_SETUP(MantissaMask_ar); + FLEXT_SETUP(MantissaMask_kr); + + FLEXT_DSP_SETUP(Hasher_ar); + FLEXT_SETUP(Hasher_kr); + + FLEXT_DSP_SETUP(Median_ar); + FLEXT_SETUP(Median_kr); + + FLEXT_DSP_SETUP(BrownNoise_ar); + FLEXT_SETUP(BrownNoise_kr); + + FLEXT_DSP_SETUP(ClipNoise_ar); + FLEXT_SETUP(ClipNoise_kr); + + FLEXT_DSP_SETUP(GrayNoise_ar); + FLEXT_SETUP(GrayNoise_kr); + + FLEXT_DSP_SETUP(WhiteNoise_ar); + FLEXT_SETUP(WhiteNoise_kr); + + FLEXT_DSP_SETUP(PinkNoise_ar); + FLEXT_SETUP(PinkNoise_kr); + + FLEXT_DSP_SETUP(Dust2_ar); + FLEXT_SETUP(Dust2_kr); + + FLEXT_DSP_SETUP(Crackle_ar); + FLEXT_SETUP(Crackle_kr); +} + +FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp new file mode 100644 index 0000000..8456f4d --- /dev/null +++ b/sc4pd/source/support.hpp @@ -0,0 +1,80 @@ +/* sc4pd: + support functions + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phosphor + +*/ + +#include +#include + +#include +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline bool sc_add (flext::AtomList a) +{ + for (int i = 0; i!=a.Count();++i) + { + if ( flext::IsSymbol(a[i]) ) + { + const char * teststring; + teststring = flext::GetString(a[i]); + if((strcmp(teststring,"add"))==0) + return true; + } + } + return false; +} + +inline float sc_getfloatarg (flext::AtomList a,int i) +{ + if (a.Count() >0 || a.Count() + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + -- cgit v1.2.1 From c51398d4fcc43ac9d72888191d65f44609f7eb5f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 18:29:52 +0000 Subject: update & bugfix svn path=/trunk/externals/tb/; revision=1859 --- sc4pd/source/Dust.cpp | 4 ++-- sc4pd/source/Dust2.cpp | 4 ++-- sc4pd/source/main.cpp | 10 +++++++--- sc4pd/source/support.hpp | 16 +++++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/sc4pd/source/Dust.cpp b/sc4pd/source/Dust.cpp index 19b6312..58decd8 100644 --- a/sc4pd/source/Dust.cpp +++ b/sc4pd/source/Dust.cpp @@ -128,7 +128,7 @@ public: protected: void m_set(float f); Timer Dust_timer; - void m_doit(); + void m_doit(void*); private: float m_density, m_scale; @@ -171,7 +171,7 @@ void Dust_kr::m_set(float f) Dust_timer.Delay(mtbt * 0.002 * rgen.frand()); } -void Dust_kr::m_doit() +void Dust_kr::m_doit(void*) { ToOutFloat(0,rgen.frand()); diff --git a/sc4pd/source/Dust2.cpp b/sc4pd/source/Dust2.cpp index a8cbbc3..ef41d9a 100644 --- a/sc4pd/source/Dust2.cpp +++ b/sc4pd/source/Dust2.cpp @@ -129,7 +129,7 @@ public: protected: void m_set(float f); Timer Dust2_timer; - void m_doit(); + void m_doit(void*); private: float m_density, m_scale; @@ -172,7 +172,7 @@ void Dust2_kr::m_set(float f) Dust2_timer.Delay(mtbt * 0.002 * rgen.frand()); } -void Dust2_kr::m_doit() +void Dust2_kr::m_doit(void*) { ToOutFloat(0,2*rgen.frand() - 1 ); diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index d7b187b..d9198db 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -49,9 +49,9 @@ void sc4pd_library_setup() post("version "SC4PD_VERSION); post("compiled on "__DATE__); post("contains: Dust(~), MantissaMask(~), Hasher(~), Median(~), " - "BrownNoise(~),"); - post(" ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " - "PinkNoise(~)\n"); + "BrownNoise(~),\n" + " ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " + "PinkNoise(~), \n Crackle(~), Rand(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -86,6 +86,10 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Crackle_ar); FLEXT_SETUP(Crackle_kr); + + FLEXT_DSP_SETUP(Rand_ar); + FLEXT_SETUP(Rand_kr); + } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index 8456f4d..b6d67a8 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -60,12 +60,26 @@ inline bool sc_add (flext::AtomList a) inline float sc_getfloatarg (flext::AtomList a,int i) { - if (a.Count() >0 || a.Count() 0 && a.Count() > i) return flext::GetAFloat(a[i]); else return 0; } +inline bool sc_ar(flext::AtomList a) +{ + for (int i = 0; i!=a.Count();++i) + { + if ( flext::IsSymbol(a[i]) ) + { + const char * teststring; + teststring = flext::GetString(a[i]); + if((strcmp(teststring,"ar"))==0) + return true; + } + } + return false; +} // macros to put rgen state in registers #define RGET \ -- cgit v1.2.1 From 6745d3a2fe6e45e54587bec5afe86fc7c171bb85 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 18:34:35 +0000 Subject: checking in svn path=/trunk/externals/tb/; revision=1860 --- sc4pd/source/Rand.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 sc4pd/source/Rand.cpp diff --git a/sc4pd/source/Rand.cpp b/sc4pd/source/Rand.cpp new file mode 100644 index 0000000..1601be9 --- /dev/null +++ b/sc4pd/source/Rand.cpp @@ -0,0 +1,151 @@ +/* sc4pd + Rand, Rand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: the sounds coming through my open window + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ Rand~ -------------------------------*/ + +class Rand_ar: + public flext_dsp +{ + FLEXT_HEADER(Rand_ar,flext_dsp); + +public: + Rand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + +private: + float m_sample; + float lo; + float hi; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("Rand~",Rand_ar); + +Rand_ar::Rand_ar(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + + rgen.init(0); //this should be changed + + AddOutSignal(); +} + +void Rand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + float range = hi - lo; + m_sample = rgen.frand() * range + lo; +} + + +void Rand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + + +/* ------------------------ Rand ---------------------------------*/ + +class Rand_kr: + public flext_base +{ + FLEXT_HEADER(Rand_kr,flext_base); + +public: + Rand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + +private: + float lo; + float hi; + RGen rgen; +}; + +FLEXT_LIB_V("Rand",Rand_kr); + +Rand_kr::Rand_kr(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + + rgen.init(0); + + AddOutFloat(); +} + +void Rand_kr::m_loadbang() +{ + float range = hi - lo; + + ToOutFloat(0,rgen.frand() * range + lo); +} -- cgit v1.2.1 From ff2ee8fd80cce2c7102799169c6e272457b011ba Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 22:07:27 +0000 Subject: check in svn path=/trunk/externals/tb/; revision=1862 --- sc4pd/source/IRand.cpp | 151 ++++++++++++++++++++++++++++++++++ sc4pd/source/TExpRand.cpp | 203 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/TIRand.cpp | 204 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/TRand.cpp | 204 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 762 insertions(+) create mode 100644 sc4pd/source/IRand.cpp create mode 100644 sc4pd/source/TExpRand.cpp create mode 100644 sc4pd/source/TIRand.cpp create mode 100644 sc4pd/source/TRand.cpp diff --git a/sc4pd/source/IRand.cpp b/sc4pd/source/IRand.cpp new file mode 100644 index 0000000..05cc5f0 --- /dev/null +++ b/sc4pd/source/IRand.cpp @@ -0,0 +1,151 @@ +/* sc4pd + IRand, IRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Assif Tsahar: Open Systems + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ IRand~ -------------------------------*/ + +class IRand_ar: + public flext_dsp +{ + FLEXT_HEADER(IRand_ar,flext_dsp); + +public: + IRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + +private: + float m_sample; + int lo; + int hi; + RGen rgen; +}; + +FLEXT_LIB_DSP_V("IRand~",IRand_ar); + +IRand_ar::IRand_ar(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=int(sc_getfloatarg(Args,0)); + hi=int(sc_getfloatarg(Args,1)); + + rgen.init(0); //this should be changed + + AddOutSignal(); +} + +void IRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + int range = hi - lo; + m_sample = float(rgen.irand(range) + lo); +} + + +void IRand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + + +/* ------------------------ IRand ---------------------------------*/ + +class IRand_kr: + public flext_base +{ + FLEXT_HEADER(IRand_kr,flext_base); + +public: + IRand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + +private: + int lo; + int hi; + RGen rgen; +}; + +FLEXT_LIB_V("IRand",IRand_kr); + +IRand_kr::IRand_kr(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=int(sc_getfloatarg(Args,0)); + hi=int(sc_getfloatarg(Args,1)); + + rgen.init(0); + + AddOutInt(); +} + +void IRand_kr::m_loadbang() +{ + int range = hi - lo; + + ToOutInt(0,rgen.irand(range) + lo); +} diff --git a/sc4pd/source/TExpRand.cpp b/sc4pd/source/TExpRand.cpp new file mode 100644 index 0000000..806fba1 --- /dev/null +++ b/sc4pd/source/TExpRand.cpp @@ -0,0 +1,203 @@ +/* sc4pd + TExpRand, TExpRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Assif Tsahar: Open Systems + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ TExpRand~ -------------------------------*/ + +class TExpRand_ar: + public flext_dsp +{ + FLEXT_HEADER(TExpRand_ar,flext_dsp); + +public: + TExpRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_bang(); + + void m_sethi(float f) + { + hi = f; + ratio = hi / lo; + } + + void m_setlo(float f) + { + lo = f; + ratio = hi / lo; + } + +private: + float m_sample; + float lo; + float hi; + float ratio; + RGen rgen; + + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_F(m_setlo); + FLEXT_CALLBACK_F(m_sethi); +}; + +FLEXT_LIB_DSP_V("TExpRand~",TExpRand_ar); + +TExpRand_ar::TExpRand_ar(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + ratio = hi / lo; + + rgen.init(0); //this should be changed + + AddOutSignal(); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"setlo",m_setlo); + FLEXT_ADDMETHOD_(0,"sethi",m_sethi); +} + +void TExpRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + m_sample = pow(ratio, rgen.frand()) * lo; +} + + +void TExpRand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + +void TExpRand_ar::m_bang() +{ + m_sample = pow(ratio, rgen.frand()) * lo; +} + +/* ------------------------ TExpRand ---------------------------------*/ + +class TExpRand_kr: + public flext_base +{ + FLEXT_HEADER(TExpRand_kr,flext_base); + +public: + TExpRand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + void m_bang(); + + void m_sethi(float f) + { + hi = f; + ratio = hi / lo; + } + + void m_setlo(float f) + { + lo = f; + ratio = hi / lo; + } + +private: + float lo; + float hi; + float ratio; + RGen rgen; + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_F(m_setlo); + FLEXT_CALLBACK_F(m_sethi); +}; + +FLEXT_LIB_V("TExpRand",TExpRand_kr); + +TExpRand_kr::TExpRand_kr(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + ratio = hi / lo; + + rgen.init(0); + + AddOutFloat(); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"setlo",m_setlo); + FLEXT_ADDMETHOD_(0,"sethi",m_sethi); +} + +void TExpRand_kr::m_loadbang() +{ + ToOutFloat(0,pow(ratio, rgen.frand()) * lo); +} + +void TExpRand_kr::m_bang() +{ + ToOutFloat(0,pow(ratio, rgen.frand()) * lo); +} diff --git a/sc4pd/source/TIRand.cpp b/sc4pd/source/TIRand.cpp new file mode 100644 index 0000000..b68278e --- /dev/null +++ b/sc4pd/source/TIRand.cpp @@ -0,0 +1,204 @@ +/* sc4pd + TIRand, TIRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Sachiko M: Debris + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ TIRand~ -------------------------------*/ + +class TIRand_ar: + public flext_dsp +{ + FLEXT_HEADER(TIRand_ar,flext_dsp); + +public: + TIRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_bang(); + + void m_sethi(int i) + { + hi = i; + range = hi - lo; + } + + void m_setlo(int i) + { + lo = i; + range = hi - lo; + } + + +private: + float m_sample; + int lo; + int hi; + int range; + RGen rgen; + + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_I(m_setlo); + FLEXT_CALLBACK_I(m_sethi); +}; + +FLEXT_LIB_DSP_V("TIRand~",TIRand_ar); + +TIRand_ar::TIRand_ar(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=int(sc_getfloatarg(Args,0)); + hi=int(sc_getfloatarg(Args,1)); + range = hi - lo; + + rgen.init(0); //this should be changed + + AddOutSignal(); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"setlo",m_setlo); + FLEXT_ADDMETHOD_(0,"sethi",m_sethi); +} + +void TIRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + m_sample = float(rgen.irand(range) + lo); +} + + +void TIRand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + +void TIRand_ar::m_bang() +{ + m_sample = float(rgen.irand(range) + lo); +} + +/* ------------------------ TIRand ---------------------------------*/ + +class TIRand_kr: + public flext_base +{ + FLEXT_HEADER(TIRand_kr,flext_base); + +public: + TIRand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + void m_bang(); + + void m_sethi(int i) + { + hi = i; + range = hi - lo; + } + + void m_setlo(int i) + { + lo = i; + range = hi - lo; + } + +private: + int lo; + int hi; + int range; + RGen rgen; + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_I(m_setlo); + FLEXT_CALLBACK_I(m_sethi); +}; + +FLEXT_LIB_V("TIRand",TIRand_kr); + +TIRand_kr::TIRand_kr(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=int(sc_getfloatarg(Args,0)); + hi=int(sc_getfloatarg(Args,1)); + range = hi - lo; + + rgen.init(0); + + AddOutInt(); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"setlo",m_setlo); + FLEXT_ADDMETHOD_(0,"sethi",m_sethi); +} + +void TIRand_kr::m_loadbang() +{ + ToOutInt(0,rgen.irand(range) + lo); +} + +void TIRand_kr::m_bang() +{ + ToOutInt(0,rgen.irand(range) + lo); +} diff --git a/sc4pd/source/TRand.cpp b/sc4pd/source/TRand.cpp new file mode 100644 index 0000000..f1ca9b2 --- /dev/null +++ b/sc4pd/source/TRand.cpp @@ -0,0 +1,204 @@ +/* sc4pd + TRand, TRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Annette Krebs & Taku Sugimoto: A Duo In Berlin + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ TRand~ -------------------------------*/ + +class TRand_ar: + public flext_dsp +{ + FLEXT_HEADER(TRand_ar,flext_dsp); + +public: + TRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_bang(); + + void m_sethi(float f) + { + hi = f; + range = hi - lo; + } + + void m_setlo(float f) + { + lo = f; + range = hi - lo; + } + + +private: + float m_sample; + float lo; + float hi; + float range; + RGen rgen; + + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_F(m_setlo); + FLEXT_CALLBACK_F(m_sethi); +}; + +FLEXT_LIB_DSP_V("TRand~",TRand_ar); + +TRand_ar::TRand_ar(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + range = hi - lo; + + rgen.init(0); //this should be changed + + AddOutSignal(); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"setlo",m_setlo); + FLEXT_ADDMETHOD_(0,"sethi",m_sethi); +} + +void TRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + m_sample = rgen.frand() * range + lo; +} + + +void TRand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + +void TRand_ar::m_bang() +{ + m_sample = rgen.frand() * range + lo; +} + +/* ------------------------ TRand ---------------------------------*/ + +class TRand_kr: + public flext_base +{ + FLEXT_HEADER(TRand_kr,flext_base); + +public: + TRand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + void m_bang(); + + void m_sethi(float f) + { + hi = f; + range = hi - lo; + } + + void m_setlo(float f) + { + lo = f; + range = hi - lo; + } + +private: + float lo; + float hi; + float range; + RGen rgen; + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_F(m_setlo); + FLEXT_CALLBACK_F(m_sethi); +}; + +FLEXT_LIB_V("TRand",TRand_kr); + +TRand_kr::TRand_kr(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + range = hi - lo; + + rgen.init(0); + + AddOutFloat(); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"setlo",m_setlo); + FLEXT_ADDMETHOD_(0,"sethi",m_sethi); +} + +void TRand_kr::m_loadbang() +{ + ToOutFloat(0,rgen.frand() * range + lo); +} + +void TRand_kr::m_bang() +{ + ToOutFloat(0,rgen.frand() * range + lo); +} -- cgit v1.2.1 From 7efe253bff93c1214cc84ef16255af39351a7606 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 22:09:37 +0000 Subject: some more ugens svn path=/trunk/externals/tb/; revision=1863 --- sc4pd/make-files.txt | 3 ++- sc4pd/source/main.cpp | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 2125a06..be5dcbc 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -3,4 +3,5 @@ SRCDIR = source SRCS= \ main.cpp Dust.cpp MantissaMask.cpp Hasher.cpp Median.cpp \ BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ - PinkNoise.cpp Dust2.cpp Crackle.cpp \ No newline at end of file + PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ + IRand.cpp TIRand.cpp \ No newline at end of file diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index d9198db..3ae9108 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -1,4 +1,5 @@ -/* sc4pd library initialization +/* sc4pd + library initialization Copyright (c) 2004 Tim Blechmann. @@ -51,7 +52,8 @@ void sc4pd_library_setup() post("contains: Dust(~), MantissaMask(~), Hasher(~), Median(~), " "BrownNoise(~),\n" " ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " - "PinkNoise(~), \n Crackle(~), Rand(~)\n"); + "PinkNoise(~), \n Crackle(~), Rand(~), TRand(~), " + "TExpRand(~), IRand(~), TIRand(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -90,6 +92,17 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Rand_ar); FLEXT_SETUP(Rand_kr); + FLEXT_DSP_SETUP(TRand_ar); + FLEXT_SETUP(TRand_kr); + + FLEXT_DSP_SETUP(TExpRand_ar); + FLEXT_SETUP(TExpRand_kr); + + FLEXT_DSP_SETUP(IRand_ar); + FLEXT_SETUP(IRand_kr); + + FLEXT_DSP_SETUP(TIRand_ar); + FLEXT_SETUP(TIRand_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From e00233cb28aaf909f03f3f9a83f08b5174b65d51 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 22:12:46 +0000 Subject: check in svn path=/trunk/externals/tb/; revision=1864 --- sc4pd/pd/trand.pd | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sc4pd/pd/trand.pd diff --git a/sc4pd/pd/trand.pd b/sc4pd/pd/trand.pd new file mode 100644 index 0000000..3f9cbde --- /dev/null +++ b/sc4pd/pd/trand.pd @@ -0,0 +1,16 @@ +#N canvas 0 0 450 300 10; +#X obj 277 115 TRand 2 3; +#X floatatom 280 143 6 0 0 0 - - -; +#X obj 275 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 144 74 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 144 96 t b b; +#X obj 144 154 print~; +#X obj 174 118 TRand~ 1 3; +#X connect 0 0 1 0; +#X connect 2 0 0 0; +#X connect 3 0 4 0; +#X connect 4 0 5 0; +#X connect 4 1 6 0; +#X connect 6 0 5 0; -- cgit v1.2.1 From 0f1258611b064b215d1dd877f69e694fedf0d109 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 15 Jul 2004 19:03:22 +0000 Subject: further checkins svn path=/trunk/externals/tb/; revision=1866 --- sc4pd/pd/LinRand.pd | 4 + sc4pd/source/CoinGate.cpp | 92 +++++++++++++++++++++++ sc4pd/source/LinRand.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/NRand.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/support.cpp | 102 +++++++++++++++++++++++++ 5 files changed, 562 insertions(+) create mode 100644 sc4pd/pd/LinRand.pd create mode 100644 sc4pd/source/CoinGate.cpp create mode 100644 sc4pd/source/LinRand.cpp create mode 100644 sc4pd/source/NRand.cpp create mode 100644 sc4pd/source/support.cpp diff --git a/sc4pd/pd/LinRand.pd b/sc4pd/pd/LinRand.pd new file mode 100644 index 0000000..30c610f --- /dev/null +++ b/sc4pd/pd/LinRand.pd @@ -0,0 +1,4 @@ +#N canvas 0 0 450 300 10; +#X obj 226 70 LinRand 1 2 3; +#X floatatom 226 95 5 0 0 0 - - -; +#X connect 0 0 1 0; diff --git a/sc4pd/source/CoinGate.cpp b/sc4pd/source/CoinGate.cpp new file mode 100644 index 0000000..27961c2 --- /dev/null +++ b/sc4pd/source/CoinGate.cpp @@ -0,0 +1,92 @@ +/* sc4pd + CoinGate + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: the sounds coming through my open window + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ CoinGate ---------------------------------*/ + +class CoinGate_kr: + public flext_base +{ + FLEXT_HEADER(CoinGate_kr,flext_base); + +public: + CoinGate_kr(int argc, t_atom *argv); + +protected: + void m_bang(); + + void m_seed(int i) + { + rgen.init(i); + } + +private: + float prob; + FLEXT_CALLBACK(m_bang); + FLEXT_CALLBACK_I(m_seed); + RGen rgen; +}; + +FLEXT_LIB_V("CoinGate",CoinGate_kr); + +CoinGate_kr::CoinGate_kr(int argc, t_atom *argv) +{ + AtomList Args(argc,argv); + + rgen.init(timeseed()); + + prob = sc_getfloatarg(Args,0); + + FLEXT_ADDBANG(0,m_bang); + FLEXT_ADDMETHOD_(0,"seed",m_seed); + AddOutBang(); +} + +void CoinGate_kr::m_bang() +{ + if(rgen.frand() < prob) + ToOutBang(0); +} diff --git a/sc4pd/source/LinRand.cpp b/sc4pd/source/LinRand.cpp new file mode 100644 index 0000000..3ebc458 --- /dev/null +++ b/sc4pd/source/LinRand.cpp @@ -0,0 +1,184 @@ +/* sc4pd + LinRand, LinRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Jim O'Rourke & Loren Mazzacane Connors: In Bern + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LinRand~ -------------------------------*/ + +class LinRand_ar: + public flext_dsp +{ + FLEXT_HEADER(LinRand_ar,flext_dsp); + +public: + LinRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + +private: + float m_sample; + float lo; + float hi; + int sc_n; + RGen rgen; + FLEXT_CALLBACK_I(m_seed); +}; + +FLEXT_LIB_DSP_V("LinRand~",LinRand_ar); + +LinRand_ar::LinRand_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + sc_n=sc_getfloatarg(Args,2); + + rgen.init(timeseed()); + + AddOutSignal(); +} + +void LinRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + float range = hi - lo; + float a, b; + a = rgen.frand(); + b = rgen.frand(); + if (sc_n <= 0) { + m_sample = sc_min(a, b) * range + lo; + } else { + m_sample = sc_max(a, b) * range + lo; + } +} + + +void LinRand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + + +/* ------------------------ LinRand ---------------------------------*/ + +class LinRand_kr: + public flext_base +{ + FLEXT_HEADER(LinRand_kr,flext_base); + +public: + LinRand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + + void m_seed(int i) + { + rgen.init(i); + } + +private: + float lo; + float hi; + int sc_n; + RGen rgen; + FLEXT_CALLBACK_I(m_seed); +}; + +FLEXT_LIB_V("LinRand",LinRand_kr); + +LinRand_kr::LinRand_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + + AtomList Args(argc,argv); + if (Args.Count() != 3) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + sc_n=sc_getfloatarg(Args,2); + + rgen.init(timeseed()); + + AddOutFloat(); +} + +void LinRand_kr::m_loadbang() +{ + float range = hi - lo; + float a, b; + a = rgen.frand(); + b = rgen.frand(); + if (sc_n <= 0) { + ToOutFloat(0,sc_min(a, b) * range + lo); + } else { + ToOutFloat(0,sc_max(a, b) * range + lo); + } +} diff --git a/sc4pd/source/NRand.cpp b/sc4pd/source/NRand.cpp new file mode 100644 index 0000000..9921c82 --- /dev/null +++ b/sc4pd/source/NRand.cpp @@ -0,0 +1,180 @@ +/* sc4pd + NRand, NRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Jim O'Rourke & Loren Mazzacane Connors: In Bern + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ NRand~ -------------------------------*/ + +class NRand_ar: + public flext_dsp +{ + FLEXT_HEADER(NRand_ar,flext_dsp); + +public: + NRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + +private: + float m_sample; + float lo; + float hi; + int sc_n; + RGen rgen; + FLEXT_CALLBACK_I(m_seed); +}; + +FLEXT_LIB_DSP_V("NRand~",NRand_ar); + +NRand_ar::NRand_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + sc_n=sc_getfloatarg(Args,2); + + rgen.init(timeseed()); + + AddOutSignal(); +} + +void NRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + float range = hi - lo; + float sum = 0; + for (int i=0; i +#include "SC_PlugIn.h" + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +bool sc_add (flext::AtomList a) +{ + for (int i = 0; i!=a.Count();++i) + { + if ( flext::IsSymbol(a[i]) ) + { + const char * teststring; + teststring = flext::GetString(a[i]); + if((strcmp(teststring,"add"))==0) + return true; + } + } + return false; +} + +float sc_getfloatarg (flext::AtomList a,int i) +{ + if (a.Count() > 0 && a.Count() > i) + return flext::GetAFloat(a[i]); + else + return 0; +} + +bool sc_ar(flext::AtomList a) +{ + for (int i = 0; i!=a.Count();++i) + { + if ( flext::IsSymbol(a[i]) ) + { + const char * teststring; + teststring = flext::GetString(a[i]); + if((strcmp(teststring,"ar"))==0) + return true; + } + } + return false; +} + +// macros to put rgen state in registers +#define RGET \ + uint32 s1 = rgen.s1; \ + uint32 s2 = rgen.s2; \ + uint32 s3 = rgen.s3; + +#define RPUT \ + rgen.s1 = s1; \ + rgen.s2 = s2; \ + rgen.s3 = s3; + +int32 timeseed() +{ + static int32 count = 0; + struct timeval tv; + gettimeofday(&tv, 0); + return (int32)tv.tv_sec ^ (int32)tv.tv_usec ^ count--; +} -- cgit v1.2.1 From 9ecfff90135ec05498f9f55a39cd386c855a8571 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 15 Jul 2004 19:05:05 +0000 Subject: rng have setable seed and other changes svn path=/trunk/externals/tb/; revision=1867 --- sc4pd/make-files.txt | 3 +- sc4pd/source/BrownNoise.cpp | 22 ++++-- sc4pd/source/ClipNoise.cpp | 19 ++++- sc4pd/source/Dust.cpp | 19 ++++- sc4pd/source/Dust2.cpp | 18 ++++- sc4pd/source/ExpRand.cpp | 168 ++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/GrayNoise.cpp | 18 ++++- sc4pd/source/IRand.cpp | 20 +++++- sc4pd/source/PinkNoise.cpp | 18 ++++- sc4pd/source/Rand.cpp | 22 +++++- sc4pd/source/TExpRand.cpp | 18 ++++- sc4pd/source/TIRand.cpp | 17 ++++- sc4pd/source/TRand.cpp | 17 ++++- sc4pd/source/WhiteNoise.cpp | 18 ++++- sc4pd/source/main.cpp | 16 ++++- sc4pd/source/support.hpp | 48 +++---------- 16 files changed, 393 insertions(+), 68 deletions(-) create mode 100644 sc4pd/source/ExpRand.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index be5dcbc..7bd3221 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -4,4 +4,5 @@ SRCS= \ main.cpp Dust.cpp MantissaMask.cpp Hasher.cpp Median.cpp \ BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ - IRand.cpp TIRand.cpp \ No newline at end of file + IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ + \ No newline at end of file diff --git a/sc4pd/source/BrownNoise.cpp b/sc4pd/source/BrownNoise.cpp index 39cbc26..b9bc138 100644 --- a/sc4pd/source/BrownNoise.cpp +++ b/sc4pd/source/BrownNoise.cpp @@ -58,22 +58,29 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + void m_seed(int i) + { + rgen.init(i); + } + private: float m_level; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("BrownNoise~",BrownNoise_ar); BrownNoise_ar::BrownNoise_ar(int argc, t_atom *argv) { - //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); m_level=rgen.frand2(); - + + FLEXT_ADDMETHOD_(0,"seed",m_seed); + AddOutSignal(); } @@ -115,11 +122,17 @@ public: protected: void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } private: float m_level; RGen rgen; FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("BrownNoise",BrownNoise_kr); @@ -127,11 +140,12 @@ FLEXT_LIB_V("BrownNoise",BrownNoise_kr); BrownNoise_kr::BrownNoise_kr(int argc, t_atom *argv) { FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); m_level=rgen.frand2(); AddOutFloat(); diff --git a/sc4pd/source/ClipNoise.cpp b/sc4pd/source/ClipNoise.cpp index 14b5101..891342c 100644 --- a/sc4pd/source/ClipNoise.cpp +++ b/sc4pd/source/ClipNoise.cpp @@ -57,20 +57,27 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } private: RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("ClipNoise~",ClipNoise_ar); ClipNoise_ar::ClipNoise_ar(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutSignal(); } @@ -104,10 +111,16 @@ public: protected: void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } private: RGen rgen; FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("ClipNoise",ClipNoise_kr); @@ -115,11 +128,11 @@ FLEXT_LIB_V("ClipNoise",ClipNoise_kr); ClipNoise_kr::ClipNoise_kr(int argc, t_atom *argv) { FLEXT_ADDBANG(0,m_perform); - + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutFloat(); } diff --git a/sc4pd/source/Dust.cpp b/sc4pd/source/Dust.cpp index 58decd8..0acd45f 100644 --- a/sc4pd/source/Dust.cpp +++ b/sc4pd/source/Dust.cpp @@ -63,9 +63,15 @@ protected: m_thresh = m_density/Samplerate(); m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; } + + void m_seed(int i) + { + rgen.init(i); + } private: FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_I(m_seed); float m_density, m_thresh, m_scale; RGen rgen; @@ -76,12 +82,14 @@ FLEXT_LIB_DSP_V("Dust~",Dust_ar); Dust_ar::Dust_ar(int argc, t_atom *argv) { FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); m_density=sc_getfloatarg(Args,0); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); + AddOutSignal(); } @@ -129,6 +137,11 @@ protected: void m_set(float f); Timer Dust_timer; void m_doit(void*); + + void m_seed(int i) + { + rgen.init(i); + } private: float m_density, m_scale; @@ -136,6 +149,7 @@ private: RGen rgen; FLEXT_CALLBACK_1(m_set,float); FLEXT_CALLBACK_T(m_doit); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("Dust",Dust_kr); @@ -144,12 +158,13 @@ Dust_kr::Dust_kr(int argc, t_atom *argv) : Dust_timer(false) { FLEXT_ADDMETHOD(0,m_set); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); m_density=sc_getfloatarg(Args,0); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutFloat(); FLEXT_ADDTIMER(Dust_timer,m_doit); diff --git a/sc4pd/source/Dust2.cpp b/sc4pd/source/Dust2.cpp index ef41d9a..cb5d509 100644 --- a/sc4pd/source/Dust2.cpp +++ b/sc4pd/source/Dust2.cpp @@ -64,9 +64,15 @@ protected: m_thresh = m_density/Samplerate(); m_scale = m_thresh > 0.f ? 1.f / m_thresh : 0.f; } + + void m_seed(int i) + { + rgen.init(i); + } private: FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_I(m_seed); float m_density, m_thresh, m_scale; RGen rgen; @@ -77,12 +83,13 @@ FLEXT_LIB_DSP_V("Dust2~",Dust2_ar); Dust2_ar::Dust2_ar(int argc, t_atom *argv) { FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); m_density=sc_getfloatarg(Args,0); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutSignal(); } @@ -130,12 +137,18 @@ protected: void m_set(float f); Timer Dust2_timer; void m_doit(void*); + + void m_seed(int i) + { + rgen.init(i); + } private: float m_density, m_scale; float mtbt; //medium time between trigger RGen rgen; FLEXT_CALLBACK_1(m_set,float); + FLEXT_CALLBACK_I(m_seed); FLEXT_CALLBACK_T(m_doit); }; @@ -145,12 +158,13 @@ Dust2_kr::Dust2_kr(int argc, t_atom *argv) : Dust2_timer(false) { FLEXT_ADDMETHOD(0,m_set); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); m_density=sc_getfloatarg(Args,0); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutFloat(); FLEXT_ADDTIMER(Dust2_timer,m_doit); diff --git a/sc4pd/source/ExpRand.cpp b/sc4pd/source/ExpRand.cpp new file mode 100644 index 0000000..e0718c8 --- /dev/null +++ b/sc4pd/source/ExpRand.cpp @@ -0,0 +1,168 @@ +/* sc4pd + ExpRand, ExpRand~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Jim O'Rourke & Loren Mazzacane Connors: In Bern + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ ExpRand~ -------------------------------*/ + +class ExpRand_ar: + public flext_dsp +{ + FLEXT_HEADER(ExpRand_ar,flext_dsp); + +public: + ExpRand_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + +private: + float m_sample; + float lo; + float hi; + int sc_n; + RGen rgen; + FLEXT_CALLBACK_I(m_seed); +}; + +FLEXT_LIB_DSP_V("ExpRand~",ExpRand_ar); + +ExpRand_ar::ExpRand_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + + rgen.init(timeseed()); + + AddOutSignal(); +} + +void ExpRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + float ratio = hi / lo; + m_sample = pow(ratio,rgen.frand()) * lo); +} + + +void ExpRand_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float sample = m_sample; + + for (int i = 0; i!= n;++i) + { + (*(nout)++) = sample; + } +} + + +/* ------------------------ ExpRand ---------------------------------*/ + +class ExpRand_kr: + public flext_base +{ + FLEXT_HEADER(ExpRand_kr,flext_base); + +public: + ExpRand_kr(int argc, t_atom *argv); + +protected: + void m_loadbang(); + + void m_seed(int i) + { + rgen.init(i); + } + +private: + float lo; + float hi; + int sc_n; + RGen rgen; + FLEXT_CALLBACK_I(m_seed); +}; + +FLEXT_LIB_V("ExpRand",ExpRand_kr); + +ExpRand_kr::ExpRand_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + + AtomList Args(argc,argv); + if (Args.Count() != 2) + { + post("not enough arguments"); + return; + } + lo=sc_getfloatarg(Args,0); + hi=sc_getfloatarg(Args,1); + + rgen.init(timeseed()); + + AddOutFloat(); +} + +void ExpRand_kr::m_loadbang() +{ + float ratio = hi / lo; + ToOutFloat(0,pow(ratio,rgen.frand()) * lo); +} diff --git a/sc4pd/source/GrayNoise.cpp b/sc4pd/source/GrayNoise.cpp index 8628bca..6c76217 100644 --- a/sc4pd/source/GrayNoise.cpp +++ b/sc4pd/source/GrayNoise.cpp @@ -57,21 +57,28 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } private: int m_counter; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("GrayNoise~",GrayNoise_ar); GrayNoise_ar::GrayNoise_ar(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutSignal(); } @@ -108,11 +115,17 @@ public: protected: void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } private: int m_counter; RGen rgen; FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("GrayNoise",GrayNoise_kr); @@ -120,11 +133,12 @@ FLEXT_LIB_V("GrayNoise",GrayNoise_kr); GrayNoise_kr::GrayNoise_kr(int argc, t_atom *argv) { FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutFloat(); } diff --git a/sc4pd/source/IRand.cpp b/sc4pd/source/IRand.cpp index 05cc5f0..095df92 100644 --- a/sc4pd/source/IRand.cpp +++ b/sc4pd/source/IRand.cpp @@ -58,18 +58,26 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } private: float m_sample; int lo; int hi; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("IRand~",IRand_ar); IRand_ar::IRand_ar(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); + AtomList Args(argc,argv); if (Args.Count() != 2) @@ -80,7 +88,7 @@ IRand_ar::IRand_ar(int argc, t_atom *argv) lo=int(sc_getfloatarg(Args,0)); hi=int(sc_getfloatarg(Args,1)); - rgen.init(0); //this should be changed + rgen.init(timeseed()); AddOutSignal(); } @@ -119,16 +127,24 @@ public: protected: void m_loadbang(); + void m_seed(int i) + { + rgen.init(i); + } + private: int lo; int hi; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("IRand",IRand_kr); IRand_kr::IRand_kr(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); + AtomList Args(argc,argv); if (Args.Count() != 2) { @@ -138,7 +154,7 @@ IRand_kr::IRand_kr(int argc, t_atom *argv) lo=int(sc_getfloatarg(Args,0)); hi=int(sc_getfloatarg(Args,1)); - rgen.init(0); + rgen.init(timeseed()); AddOutInt(); } diff --git a/sc4pd/source/PinkNoise.cpp b/sc4pd/source/PinkNoise.cpp index bf6db62..9a1c5bc 100644 --- a/sc4pd/source/PinkNoise.cpp +++ b/sc4pd/source/PinkNoise.cpp @@ -57,11 +57,17 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } private: uint32 m_dice[16]; int32 m_total; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("PinkNoise~",PinkNoise_ar); @@ -69,11 +75,12 @@ FLEXT_LIB_DSP_V("PinkNoise~",PinkNoise_ar); PinkNoise_ar::PinkNoise_ar(int argc, t_atom *argv) : m_total(0) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); for (int i=0; i<16; ++i) { @@ -123,12 +130,18 @@ public: protected: void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } private: uint32 m_dice[16]; int32 m_total; RGen rgen; FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("PinkNoise",PinkNoise_kr); @@ -137,11 +150,12 @@ PinkNoise_kr::PinkNoise_kr(int argc, t_atom *argv) : m_total(0) { FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); for (int i=0; i<16; ++i) { diff --git a/sc4pd/source/Rand.cpp b/sc4pd/source/Rand.cpp index 1601be9..243cc5e 100644 --- a/sc4pd/source/Rand.cpp +++ b/sc4pd/source/Rand.cpp @@ -58,18 +58,26 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } private: float m_sample; float lo; float hi; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("Rand~",Rand_ar); Rand_ar::Rand_ar(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); + AtomList Args(argc,argv); if (Args.Count() != 2) @@ -80,7 +88,7 @@ Rand_ar::Rand_ar(int argc, t_atom *argv) lo=sc_getfloatarg(Args,0); hi=sc_getfloatarg(Args,1); - rgen.init(0); //this should be changed + rgen.init(timeseed()); AddOutSignal(); } @@ -119,16 +127,24 @@ public: protected: void m_loadbang(); + void m_seed(int i) + { + rgen.init(i); + } + private: float lo; float hi; RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("Rand",Rand_kr); Rand_kr::Rand_kr(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); + AtomList Args(argc,argv); if (Args.Count() != 2) { @@ -138,8 +154,8 @@ Rand_kr::Rand_kr(int argc, t_atom *argv) lo=sc_getfloatarg(Args,0); hi=sc_getfloatarg(Args,1); - rgen.init(0); - + rgen.init(timeseed()); + AddOutFloat(); } diff --git a/sc4pd/source/TExpRand.cpp b/sc4pd/source/TExpRand.cpp index 806fba1..b7ee16e 100644 --- a/sc4pd/source/TExpRand.cpp +++ b/sc4pd/source/TExpRand.cpp @@ -72,6 +72,11 @@ protected: lo = f; ratio = hi / lo; } + + void m_seed(int i) + { + rgen.init(i); + } private: float m_sample; @@ -83,6 +88,7 @@ private: FLEXT_CALLBACK(m_bang); FLEXT_CALLBACK_F(m_setlo); FLEXT_CALLBACK_F(m_sethi); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("TExpRand~",TExpRand_ar); @@ -100,13 +106,14 @@ TExpRand_ar::TExpRand_ar(int argc, t_atom *argv) hi=sc_getfloatarg(Args,1); ratio = hi / lo; - rgen.init(0); //this should be changed + rgen.init(timeseed()); AddOutSignal(); FLEXT_ADDBANG(0,m_bang); FLEXT_ADDMETHOD_(0,"setlo",m_setlo); FLEXT_ADDMETHOD_(0,"sethi",m_sethi); + FLEXT_ADDMETHOD_(0,"seed",m_seed); } void TExpRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) @@ -159,6 +166,11 @@ protected: ratio = hi / lo; } + void m_seed(int i) + { + rgen.init(i); + } + private: float lo; float hi; @@ -167,6 +179,7 @@ private: FLEXT_CALLBACK(m_bang); FLEXT_CALLBACK_F(m_setlo); FLEXT_CALLBACK_F(m_sethi); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("TExpRand",TExpRand_kr); @@ -183,13 +196,14 @@ TExpRand_kr::TExpRand_kr(int argc, t_atom *argv) hi=sc_getfloatarg(Args,1); ratio = hi / lo; - rgen.init(0); + rgen.init(timeseed()); AddOutFloat(); FLEXT_ADDBANG(0,m_bang); FLEXT_ADDMETHOD_(0,"setlo",m_setlo); FLEXT_ADDMETHOD_(0,"sethi",m_sethi); + FLEXT_ADDMETHOD_(0,"seed",m_seed); } void TExpRand_kr::m_loadbang() diff --git a/sc4pd/source/TIRand.cpp b/sc4pd/source/TIRand.cpp index b68278e..93fdd09 100644 --- a/sc4pd/source/TIRand.cpp +++ b/sc4pd/source/TIRand.cpp @@ -73,6 +73,10 @@ protected: range = hi - lo; } + void m_seed(int i) + { + rgen.init(i); + } private: float m_sample; @@ -84,6 +88,7 @@ private: FLEXT_CALLBACK(m_bang); FLEXT_CALLBACK_I(m_setlo); FLEXT_CALLBACK_I(m_sethi); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("TIRand~",TIRand_ar); @@ -101,13 +106,14 @@ TIRand_ar::TIRand_ar(int argc, t_atom *argv) hi=int(sc_getfloatarg(Args,1)); range = hi - lo; - rgen.init(0); //this should be changed + rgen.init(timeseed()); AddOutSignal(); FLEXT_ADDBANG(0,m_bang); FLEXT_ADDMETHOD_(0,"setlo",m_setlo); FLEXT_ADDMETHOD_(0,"sethi",m_sethi); + FLEXT_ADDMETHOD_(0,"seed",m_seed); } void TIRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) @@ -160,6 +166,11 @@ protected: range = hi - lo; } + void m_seed(int i) + { + rgen.init(i); + } + private: int lo; int hi; @@ -168,6 +179,7 @@ private: FLEXT_CALLBACK(m_bang); FLEXT_CALLBACK_I(m_setlo); FLEXT_CALLBACK_I(m_sethi); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("TIRand",TIRand_kr); @@ -184,13 +196,14 @@ TIRand_kr::TIRand_kr(int argc, t_atom *argv) hi=int(sc_getfloatarg(Args,1)); range = hi - lo; - rgen.init(0); + rgen.init(timeseed()); AddOutInt(); FLEXT_ADDBANG(0,m_bang); FLEXT_ADDMETHOD_(0,"setlo",m_setlo); FLEXT_ADDMETHOD_(0,"sethi",m_sethi); + FLEXT_ADDMETHOD_(0,"seed",m_seed); } void TIRand_kr::m_loadbang() diff --git a/sc4pd/source/TRand.cpp b/sc4pd/source/TRand.cpp index f1ca9b2..b18704f 100644 --- a/sc4pd/source/TRand.cpp +++ b/sc4pd/source/TRand.cpp @@ -73,6 +73,10 @@ protected: range = hi - lo; } + void m_seed(int i) + { + rgen.init(i); + } private: float m_sample; @@ -84,6 +88,7 @@ private: FLEXT_CALLBACK(m_bang); FLEXT_CALLBACK_F(m_setlo); FLEXT_CALLBACK_F(m_sethi); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("TRand~",TRand_ar); @@ -101,13 +106,14 @@ TRand_ar::TRand_ar(int argc, t_atom *argv) hi=sc_getfloatarg(Args,1); range = hi - lo; - rgen.init(0); //this should be changed + rgen.init(timeseed()); AddOutSignal(); FLEXT_ADDBANG(0,m_bang); FLEXT_ADDMETHOD_(0,"setlo",m_setlo); FLEXT_ADDMETHOD_(0,"sethi",m_sethi); + FLEXT_ADDMETHOD_(0,"seed",m_seed); } void TRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) @@ -160,6 +166,11 @@ protected: range = hi - lo; } + void m_seed(int i) + { + rgen.init(i); + } + private: float lo; float hi; @@ -168,6 +179,7 @@ private: FLEXT_CALLBACK(m_bang); FLEXT_CALLBACK_F(m_setlo); FLEXT_CALLBACK_F(m_sethi); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("TRand",TRand_kr); @@ -184,13 +196,14 @@ TRand_kr::TRand_kr(int argc, t_atom *argv) hi=sc_getfloatarg(Args,1); range = hi - lo; - rgen.init(0); + rgen.init(timeseed()); AddOutFloat(); FLEXT_ADDBANG(0,m_bang); FLEXT_ADDMETHOD_(0,"setlo",m_setlo); FLEXT_ADDMETHOD_(0,"sethi",m_sethi); + FLEXT_ADDMETHOD_(0,"seed",m_seed); } void TRand_kr::m_loadbang() diff --git a/sc4pd/source/WhiteNoise.cpp b/sc4pd/source/WhiteNoise.cpp index ecedf3d..6d308db 100644 --- a/sc4pd/source/WhiteNoise.cpp +++ b/sc4pd/source/WhiteNoise.cpp @@ -57,20 +57,27 @@ public: protected: virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } private: RGen rgen; + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_DSP_V("WhiteNoise~",WhiteNoise_ar); WhiteNoise_ar::WhiteNoise_ar(int argc, t_atom *argv) { + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutSignal(); } @@ -104,10 +111,16 @@ public: protected: void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } private: RGen rgen; FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_I(m_seed); }; FLEXT_LIB_V("WhiteNoise",WhiteNoise_kr); @@ -115,11 +128,12 @@ FLEXT_LIB_V("WhiteNoise",WhiteNoise_kr); WhiteNoise_kr::WhiteNoise_kr(int argc, t_atom *argv) { FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDMETHOD_(0,"seed",m_seed); //parse arguments AtomList Args(argc,argv); - rgen.init(0); //set seed to 0 + rgen.init(timeseed()); AddOutFloat(); } diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 3ae9108..2de28fa 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -36,6 +36,7 @@ */ #include +#include "SC_PlugIn.h" #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) #error You need at least FLEXT version 0.4.6 @@ -43,6 +44,7 @@ #define SC4PD_VERSION "0.01" + void sc4pd_library_setup() { post("\nsc4pd: by tim blechmann"); @@ -53,7 +55,8 @@ void sc4pd_library_setup() "BrownNoise(~),\n" " ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " "PinkNoise(~), \n Crackle(~), Rand(~), TRand(~), " - "TExpRand(~), IRand(~), TIRand(~)\n"); + "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " + "LinRand(~), NRand(~), ExpRand(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -103,6 +106,17 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(TIRand_ar); FLEXT_SETUP(TIRand_kr); + + FLEXT_SETUP(CoinGate_kr); + + FLEXT_DSP_SETUP(LinRand_ar); + FLEXT_SETUP(LinRand_kr); + + FLEXT_DSP_SETUP(NRand_ar); + FLEXT_SETUP(NRand_kr); + + FLEXT_DSP_SETUP(ExpRand_ar); + FLEXT_SETUP(ExpRand_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index b6d67a8..79faff5 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -35,51 +35,22 @@ */ #include -#include +//#include +#include "SC_PlugIn.h" -#include + +//#include #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) #error You need at least FLEXT version 0.4.6 #endif +/* for argument parsing */ +bool sc_add (flext::AtomList a); +float sc_getfloatarg (flext::AtomList a,int i); +bool sc_ar(flext::AtomList a); -inline bool sc_add (flext::AtomList a) -{ - for (int i = 0; i!=a.Count();++i) - { - if ( flext::IsSymbol(a[i]) ) - { - const char * teststring; - teststring = flext::GetString(a[i]); - if((strcmp(teststring,"add"))==0) - return true; - } - } - return false; -} - -inline float sc_getfloatarg (flext::AtomList a,int i) -{ - if (a.Count() > 0 && a.Count() > i) - return flext::GetAFloat(a[i]); - else - return 0; -} -inline bool sc_ar(flext::AtomList a) -{ - for (int i = 0; i!=a.Count();++i) - { - if ( flext::IsSymbol(a[i]) ) - { - const char * teststring; - teststring = flext::GetString(a[i]); - if((strcmp(teststring,"ar"))==0) - return true; - } - } - return false; -} +/* for rngs */ // macros to put rgen state in registers #define RGET \ @@ -92,3 +63,4 @@ inline bool sc_ar(flext::AtomList a) rgen.s2 = s2; \ rgen.s3 = s3; +int32 timeseed(); -- cgit v1.2.1 From 2bc701fec065db8d399498a8c2f4f4145acf3369 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 15 Jul 2004 21:34:12 +0000 Subject: the work of this evening ... svn path=/trunk/externals/tb/; revision=1868 --- sc4pd/headers/plugin_interface/SC_RGen.h | 2 +- sc4pd/make-files.txt | 2 +- sc4pd/pd/clipnoise.pd | 13 ++ sc4pd/pd/lfclipnoise.pd | 10 ++ sc4pd/pd/lfnoise0.pd | 10 ++ sc4pd/source/ClipNoise.cpp | 4 +- sc4pd/source/ExpRand.cpp | 2 +- sc4pd/source/LFClipNoise.cpp | 202 +++++++++++++++++++++++++++++++ sc4pd/source/LFNoise0.cpp | 202 +++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 9 +- sc4pd/source/support.cpp | 18 ++- 11 files changed, 463 insertions(+), 11 deletions(-) create mode 100644 sc4pd/pd/clipnoise.pd create mode 100644 sc4pd/pd/lfclipnoise.pd create mode 100644 sc4pd/pd/lfnoise0.pd create mode 100644 sc4pd/source/LFClipNoise.cpp create mode 100644 sc4pd/source/LFNoise0.cpp diff --git a/sc4pd/headers/plugin_interface/SC_RGen.h b/sc4pd/headers/plugin_interface/SC_RGen.h index c82142b..11f8c9a 100755 --- a/sc4pd/headers/plugin_interface/SC_RGen.h +++ b/sc4pd/headers/plugin_interface/SC_RGen.h @@ -165,7 +165,7 @@ inline float RGen::fcoin() { // only return one of the two values -1.0 or +1.0 union { uint32 i; float f; } u; // union for floating point conversion of result - u.i = 0x3E000000 | (0x80000000 & trand()); + u.i = 0x3F800000 | (0x80000000 & trand()); return u.f; } diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 7bd3221..4f7f78a 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -5,4 +5,4 @@ SRCS= \ BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ - \ No newline at end of file + ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp \ No newline at end of file diff --git a/sc4pd/pd/clipnoise.pd b/sc4pd/pd/clipnoise.pd new file mode 100644 index 0000000..5a685b0 --- /dev/null +++ b/sc4pd/pd/clipnoise.pd @@ -0,0 +1,13 @@ +#N canvas 0 0 450 300 10; +#X obj 89 48 ClipNoise~; +#X obj 89 115 print~; +#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 246 55 ClipNoise; +#X floatatom 246 97 5 0 0 0 - - -; +#X obj 251 27 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 0 0 1 0; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 5 0 3 0; diff --git a/sc4pd/pd/lfclipnoise.pd b/sc4pd/pd/lfclipnoise.pd new file mode 100644 index 0000000..a4c3496 --- /dev/null +++ b/sc4pd/pd/lfclipnoise.pd @@ -0,0 +1,10 @@ +#N canvas 0 0 450 300 10; +#X obj 89 115 print~; +#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 246 97 5 0 0 0 - - -; +#X obj 89 48 LFClipNoise~ 1000; +#X obj 246 55 LFClipNoise 10; +#X connect 1 0 0 0; +#X connect 3 0 0 0; +#X connect 4 0 2 0; diff --git a/sc4pd/pd/lfnoise0.pd b/sc4pd/pd/lfnoise0.pd new file mode 100644 index 0000000..882d0dd --- /dev/null +++ b/sc4pd/pd/lfnoise0.pd @@ -0,0 +1,10 @@ +#N canvas 0 0 450 300 10; +#X obj 89 115 print~; +#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 246 97 5 0 0 0 - - -; +#X obj 246 55 LFNoise0 10; +#X obj 89 48 LFNoise0~ 1000; +#X connect 1 0 0 0; +#X connect 3 0 2 0; +#X connect 4 0 0 0; diff --git a/sc4pd/source/ClipNoise.cpp b/sc4pd/source/ClipNoise.cpp index 891342c..761fbb6 100644 --- a/sc4pd/source/ClipNoise.cpp +++ b/sc4pd/source/ClipNoise.cpp @@ -134,10 +134,10 @@ ClipNoise_kr::ClipNoise_kr(int argc, t_atom *argv) rgen.init(timeseed()); - AddOutFloat(); + AddOutInt(); } void ClipNoise_kr::m_perform() { - ToOutFloat(0,rgen.fcoin()); + ToOutInt(0,rgen.fcoin()); } diff --git a/sc4pd/source/ExpRand.cpp b/sc4pd/source/ExpRand.cpp index e0718c8..3b17aef 100644 --- a/sc4pd/source/ExpRand.cpp +++ b/sc4pd/source/ExpRand.cpp @@ -97,7 +97,7 @@ ExpRand_ar::ExpRand_ar(int argc, t_atom *argv) void ExpRand_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) { float ratio = hi / lo; - m_sample = pow(ratio,rgen.frand()) * lo); + m_sample = pow(ratio,rgen.frand()) * lo; } diff --git a/sc4pd/source/LFClipNoise.cpp b/sc4pd/source/LFClipNoise.cpp new file mode 100644 index 0000000..9aa6dfc --- /dev/null +++ b/sc4pd/source/LFClipNoise.cpp @@ -0,0 +1,202 @@ +/* sc4pd + LFClipNoise, LFClipNoise~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Elliott Sharp: Revenge Of The Stuttering Child + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LFClipNoise~ -------------------------------*/ + +class LFClipNoise_ar: + public flext_dsp +{ + FLEXT_HEADER(LFClipNoise_ar,flext_dsp); + +public: + LFClipNoise_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_level; + int m_counter; + int m_sr; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFClipNoise~",LFClipNoise_ar); + +LFClipNoise_ar::LFClipNoise_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + m_counter=0; + m_level=0; + + rgen.init(timeseed()); + + AddOutSignal(); +} + +void LFClipNoise_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_sr = Samplerate(); +} + + +void LFClipNoise_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float level = m_level; + int32 counter = m_counter; + + RGET; + + int remain = n; + do + { + if (counter<=0) + { + counter = (int)(m_sr / sc_max(m_freq, .001f)); + counter = sc_max(1, counter); + level = fcoin(s1,s2,s3); + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + (*(nout)++)=level; + } + } + while(remain); + + m_level = level; + m_counter = counter; + + RPUT; +} + + +/* ------------------------ LFClipNoise ---------------------------------*/ + +class LFClipNoise_kr: + public flext_base +{ + FLEXT_HEADER(LFClipNoise_kr,flext_base); + +public: + LFClipNoise_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + double dt = sc_min(1/f, .001f); + m_timer.Reset(); + m_timer.Periodic(1000*dt); + } + +private: + RGen rgen; + Timer m_timer; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_T(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("LFClipNoise",LFClipNoise_kr); + +LFClipNoise_kr::LFClipNoise_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDTIMER(m_timer,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + double dt = sc_min(1/sc_getfloatarg(Args,0), .001f); + + rgen.init(timeseed()); + + m_timer.Periodic(1000*dt); + + AddOutFloat(); +} + +void LFClipNoise_kr::m_perform() +{ + ToOutFloat(0,rgen.fcoin()); +} diff --git a/sc4pd/source/LFNoise0.cpp b/sc4pd/source/LFNoise0.cpp new file mode 100644 index 0000000..6e9c5bb --- /dev/null +++ b/sc4pd/source/LFNoise0.cpp @@ -0,0 +1,202 @@ +/* sc4pd + LFNoise0, LFNoise0~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Elliott Sharp: Revenge Of The Stuttering Child + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LFNoise0~ -------------------------------*/ + +class LFNoise0_ar: + public flext_dsp +{ + FLEXT_HEADER(LFNoise0_ar,flext_dsp); + +public: + LFNoise0_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_level; + int m_counter; + int m_sr; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFNoise0~",LFNoise0_ar); + +LFNoise0_ar::LFNoise0_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + m_counter=0; + m_level=0; + + rgen.init(timeseed()); + + AddOutSignal(); +} + +void LFNoise0_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_sr = Samplerate(); +} + + +void LFNoise0_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float level = m_level; + int32 counter = m_counter; + + RGET; + + int remain = n; + do + { + if (counter<=0) + { + counter = (int)(m_sr / sc_max(m_freq, .001f)); + counter = sc_max(1, counter); + level = frand2(s1,s2,s3); + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + (*(nout)++)=level; + } + } + while(remain); + + m_level = level; + m_counter = counter; + + RPUT; +} + + +/* ------------------------ LFNoise0 ---------------------------------*/ + +class LFNoise0_kr: + public flext_base +{ + FLEXT_HEADER(LFNoise0_kr,flext_base); + +public: + LFNoise0_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + double dt = sc_min(1/f, .001f); + m_timer.Reset(); + m_timer.Periodic(1000*dt); + } + +private: + RGen rgen; + Timer m_timer; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_T(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("LFNoise0",LFNoise0_kr); + +LFNoise0_kr::LFNoise0_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDTIMER(m_timer,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + double dt = sc_min(1/sc_getfloatarg(Args,0), .001f); + + rgen.init(timeseed()); + + m_timer.Periodic(1000*dt); + + AddOutFloat(); +} + +void LFNoise0_kr::m_perform() +{ + ToOutFloat(0,rgen.frand2()); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 2de28fa..5940253 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -56,7 +56,8 @@ void sc4pd_library_setup() " ClipNoise(~), GrayNoise(~), Dust2(~), WhiteNoise(~), " "PinkNoise(~), \n Crackle(~), Rand(~), TRand(~), " "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " - "LinRand(~), NRand(~), ExpRand(~)\n"); + "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" + " LFNoise0(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -117,6 +118,12 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(ExpRand_ar); FLEXT_SETUP(ExpRand_kr); + + FLEXT_DSP_SETUP(LFClipNoise_ar); + FLEXT_SETUP(LFClipNoise_kr); + + FLEXT_DSP_SETUP(LFNoise0_ar); + FLEXT_SETUP(LFNoise0_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp index 2e06e9e..8d80bbe 100644 --- a/sc4pd/source/support.cpp +++ b/sc4pd/source/support.cpp @@ -35,15 +35,14 @@ */ #include +#include #include "SC_PlugIn.h" -#include #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) #error You need at least FLEXT version 0.4.6 #endif - bool sc_add (flext::AtomList a) { for (int i = 0; i!=a.Count();++i) @@ -96,7 +95,16 @@ bool sc_ar(flext::AtomList a) int32 timeseed() { static int32 count = 0; - struct timeval tv; - gettimeofday(&tv, 0); - return (int32)tv.tv_sec ^ (int32)tv.tv_usec ^ count--; + + double time = flext::GetOSTime(); + + double sec = trunc(time); + double usec = (time-sec)*1e6; + + time_t tsec = sec; + suseconds_t tusec =usec; /* not exacty the way, it's calculated + in SuperCollider, but it's only + the seed */ + + return (int32)tsec ^ (int32)tusec ^ count--; } -- cgit v1.2.1 From c1f0c701a5b598e665b0e884081c9a02c44a2550 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 16 Jul 2004 16:43:48 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1869 --- sc4pd/config-pd-linux.txt | 4 +- sc4pd/make-files.txt | 2 +- sc4pd/makefile.pd-linux | 2 +- sc4pd/pd/lfnoise0.pd | 13 +- sc4pd/pd/lfnoise1.pd | 17 +++ sc4pd/source/LFClipNoise.cpp | 12 +- sc4pd/source/LFNoise0.cpp | 14 +-- sc4pd/source/LFNoise1.cpp | 239 +++++++++++++++++++++++++++++++++++++ sc4pd/source/LFNoise2.cpp | 278 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 8 +- 10 files changed, 568 insertions(+), 21 deletions(-) create mode 100644 sc4pd/pd/lfnoise1.pd create mode 100644 sc4pd/source/LFNoise1.cpp create mode 100644 sc4pd/source/LFNoise2.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index e3d8dc1..7aac9a8 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -28,8 +28,8 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) -#UFLAGS=-xN -tpp7 -ip -ipo_obj # icc -# UFLAGS=-mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 +UFLAGS=-xN -tpp7 -ip -ipo_obj # icc +#UFLAGS=-g -mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 4f7f78a..5952f9a 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -5,4 +5,4 @@ SRCS= \ BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ - ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp \ No newline at end of file + ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ No newline at end of file diff --git a/sc4pd/makefile.pd-linux b/sc4pd/makefile.pd-linux index 994141c..fc55ec6 100644 --- a/sc4pd/makefile.pd-linux +++ b/sc4pd/makefile.pd-linux @@ -55,7 +55,7 @@ $(TARGDIR)/%.o : $(SRCDIR)/%.cpp $(TARGET) : $(patsubst %.cpp,$(TARGDIR)/%.o,$(SRCS)) $(CXX) $(LDFLAGS) -shared $^ $(patsubst %,-l%,$(LIBS)) -L$(FLEXTPATH) $(LINKFLEXT) -o $@ - #strip --strip-unneeded $@ + strip --strip-unneeded $@ chmod 755 $@ $(INSTDIR): diff --git a/sc4pd/pd/lfnoise0.pd b/sc4pd/pd/lfnoise0.pd index 882d0dd..afcc0a3 100644 --- a/sc4pd/pd/lfnoise0.pd +++ b/sc4pd/pd/lfnoise0.pd @@ -3,8 +3,15 @@ #X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X floatatom 246 97 5 0 0 0 - - -; -#X obj 246 55 LFNoise0 10; #X obj 89 48 LFNoise0~ 1000; +#X obj 246 143 timer; +#X obj 246 123 t b b; +#X floatatom 246 168 5 0 0 0 - - -; +#X obj 246 55 LFNoise0 10; #X connect 1 0 0 0; -#X connect 3 0 2 0; -#X connect 4 0 0 0; +#X connect 2 0 5 0; +#X connect 3 0 0 0; +#X connect 4 0 6 0; +#X connect 5 0 4 0; +#X connect 5 1 4 1; +#X connect 7 0 2 0; diff --git a/sc4pd/pd/lfnoise1.pd b/sc4pd/pd/lfnoise1.pd new file mode 100644 index 0000000..e6a261c --- /dev/null +++ b/sc4pd/pd/lfnoise1.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 89 115 print~; +#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 246 97 5 0 0 0 - - -; +#X obj 246 143 timer; +#X obj 246 123 t b b; +#X floatatom 246 168 5 0 0 0 - - -; +#X obj 246 55 LFNoise0 10; +#X obj 89 48 LFNoise1~ 100; +#X connect 1 0 0 0; +#X connect 2 0 4 0; +#X connect 3 0 5 0; +#X connect 4 0 3 0; +#X connect 4 1 3 1; +#X connect 6 0 2 0; +#X connect 7 0 0 0; diff --git a/sc4pd/source/LFClipNoise.cpp b/sc4pd/source/LFClipNoise.cpp index 9aa6dfc..18f95ee 100644 --- a/sc4pd/source/LFClipNoise.cpp +++ b/sc4pd/source/LFClipNoise.cpp @@ -154,7 +154,7 @@ public: LFClipNoise_kr(int argc, t_atom *argv); protected: - void m_perform(); + void m_perform(void*); void m_seed(int i) { @@ -163,9 +163,9 @@ protected: void m_set(float f) { - double dt = sc_min(1/f, .001f); + double dt = sc_max(1/f, .001f); m_timer.Reset(); - m_timer.Periodic(1000*dt); + m_timer.Periodic(dt); } private: @@ -187,16 +187,16 @@ LFClipNoise_kr::LFClipNoise_kr(int argc, t_atom *argv) //parse arguments AtomList Args(argc,argv); - double dt = sc_min(1/sc_getfloatarg(Args,0), .001f); + double dt = sc_max(1/sc_getfloatarg(Args,0), .001f); rgen.init(timeseed()); - m_timer.Periodic(1000*dt); + m_timer.Periodic(dt); AddOutFloat(); } -void LFClipNoise_kr::m_perform() +void LFClipNoise_kr::m_perform(void*) { ToOutFloat(0,rgen.fcoin()); } diff --git a/sc4pd/source/LFNoise0.cpp b/sc4pd/source/LFNoise0.cpp index 6e9c5bb..c0f8abd 100644 --- a/sc4pd/source/LFNoise0.cpp +++ b/sc4pd/source/LFNoise0.cpp @@ -154,8 +154,8 @@ public: LFNoise0_kr(int argc, t_atom *argv); protected: - void m_perform(); - + void m_perform(void*); + void m_seed(int i) { rgen.init(i); @@ -163,9 +163,9 @@ protected: void m_set(float f) { - double dt = sc_min(1/f, .001f); + double dt = sc_max(1/f, .001f); m_timer.Reset(); - m_timer.Periodic(1000*dt); + m_timer.Periodic(dt); } private: @@ -187,16 +187,16 @@ LFNoise0_kr::LFNoise0_kr(int argc, t_atom *argv) //parse arguments AtomList Args(argc,argv); - double dt = sc_min(1/sc_getfloatarg(Args,0), .001f); + double dt = sc_max(1/sc_getfloatarg(Args,0), .001f); rgen.init(timeseed()); - m_timer.Periodic(1000*dt); + m_timer.Periodic(dt); AddOutFloat(); } -void LFNoise0_kr::m_perform() +void LFNoise0_kr::m_perform(void*) { ToOutFloat(0,rgen.frand2()); } diff --git a/sc4pd/source/LFNoise1.cpp b/sc4pd/source/LFNoise1.cpp new file mode 100644 index 0000000..e48d3bb --- /dev/null +++ b/sc4pd/source/LFNoise1.cpp @@ -0,0 +1,239 @@ +/* sc4pd + LFNoise1, LFNoise1~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Fred Frith: Gravity + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LFNoise1~ -------------------------------*/ + +class LFNoise1_ar: + public flext_dsp +{ + FLEXT_HEADER(LFNoise1_ar,flext_dsp); + +public: + LFNoise1_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_level; + float m_slope; + int m_counter; + int m_sr; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFNoise1~",LFNoise1_ar); + +LFNoise1_ar::LFNoise1_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + rgen.init(timeseed()); + + m_counter=0; + m_level=rgen.frand2(); + m_slope=0; + + AddOutSignal(); +} + +void LFNoise1_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_sr = Samplerate(); +} + + +void LFNoise1_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float level = m_level; + int32 counter = m_counter; + float slope = m_slope; + + RGET; + + int remain = n; + do + { + if (counter<=0) + { + counter = (int)(m_sr / sc_max(m_freq, .001f)); + counter = sc_max(1, counter); + float nextlevel = frand2(s1,s2,s3); + slope = (nextlevel - level) / counter; + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + (*(nout)++)=level; + level+=slope; + } + } + while(remain); + + m_level = level; + m_counter = counter; + m_slope = slope; + + RPUT; +} + + +/* ------------------------ LFNoise1 ---------------------------------*/ + +class LFNoise1_kr: + public flext_base +{ + FLEXT_HEADER(LFNoise1_kr,flext_base); + +public: + LFNoise1_kr(int argc, t_atom *argv); + +protected: + void m_perform(void*); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float); + +private: + RGen rgen; + float m_level; + float m_slope; + + float dt; //in s + float tick; //in s + int counter; + + Timer m_timer; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_T(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("LFNoise1",LFNoise1_kr); + +LFNoise1_kr::LFNoise1_kr(int argc, t_atom *argv) + : tick(0.01) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDTIMER(m_timer,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(timeseed()); + + m_level=rgen.frand2(); + + AddOutFloat(); + + m_set(sc_getfloatarg(Args,0)); +} + +void LFNoise1_kr::m_set(float f) +{ + dt = sc_max(1/f, .001f); + counter = (dt/tick); + + float nextlevel = rgen.frand2(); + m_slope = (nextlevel - m_level) / counter; + + m_timer.Reset(); + m_timer.Delay(tick); +} + +void LFNoise1_kr::m_perform(void*) +{ + m_level+=m_slope; + ToOutFloat(0,m_level); + if (--counter) + { + m_timer.Reset(); + m_timer.Delay(tick); + } + else + { + counter = (dt/tick); + float nextlevel = rgen.frand2(); + m_slope = (nextlevel - m_level) / counter; + + m_timer.Reset(); + m_timer.Delay(tick); + + } +} diff --git a/sc4pd/source/LFNoise2.cpp b/sc4pd/source/LFNoise2.cpp new file mode 100644 index 0000000..71aff7d --- /dev/null +++ b/sc4pd/source/LFNoise2.cpp @@ -0,0 +1,278 @@ +/* sc4pd + LFNoise2, LFNoise2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Guenther Mueller & Toshimaru Nakamura: Tint + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LFNoise2~ -------------------------------*/ + +class LFNoise2_ar: + public flext_dsp +{ + FLEXT_HEADER(LFNoise2_ar,flext_dsp); + +public: + LFNoise2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_level; + float m_slope; + float m_curve; + int m_counter; + int m_sr; + float m_nextvalue; + float m_nextmidpt; + + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFNoise2~",LFNoise2_ar); + +LFNoise2_ar::LFNoise2_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + rgen.init(timeseed()); + + m_counter=0; + m_level=rgen.frand2(); + m_slope=0; + m_curve=0; + m_nextvalue=0; + m_nextmidpt=0; + + AddOutSignal(); +} + +void LFNoise2_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_sr = Samplerate(); +} + + +void LFNoise2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float level = m_level; + int32 counter = m_counter; + float slope = m_slope; + float curve = m_curve; + + RGET; + + int remain = n; + do + { + if (counter<=0) + { + float value = m_nextvalue; + m_nextvalue = frand2(s1,s2,s3); + level = m_nextmidpt; + m_nextmidpt = (m_nextvalue + value) * .5; + + counter = (int32)(m_sr / sc_max(m_freq, .001f)); + counter = sc_max(2, counter); + float fseglen = (float)counter; + curve = 2.f * (m_nextmidpt - level - fseglen * slope) + / (fseglen * fseglen + fseglen); + } + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + (*(nout)++)=level; + slope+=curve; + level+=slope; + } + } + while(remain); + + m_level = level; + m_counter = counter; + m_slope = slope; + m_curve = curve; + + RPUT; +} + + +/* ------------------------ LFNoise2 ---------------------------------*/ + +class LFNoise2_kr: + public flext_base +{ + FLEXT_HEADER(LFNoise2_kr,flext_base); + +public: + LFNoise2_kr(int argc, t_atom *argv); + +protected: + void m_perform(void*); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float); + +private: + RGen rgen; + float m_level; + float m_slope; + float m_curve; + float m_nextvalue; + float m_nextmidpt; + + float dt; //in s + float tick; //in s + int counter; + + Timer m_timer; + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_T(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("LFNoise2",LFNoise2_kr); + +LFNoise2_kr::LFNoise2_kr(int argc, t_atom *argv) + : tick(0.01) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDTIMER(m_timer,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + rgen.init(timeseed()); + + m_level=rgen.frand2(); + + AddOutFloat(); + + m_set(sc_getfloatarg(Args,0)); +} + + +void LFNoise2_kr::m_set(float f) +{ + dt = sc_max(1/f, .001f); + counter = (dt/tick); + counter = sc_max(2, counter); + + float value = m_nextvalue; + m_nextvalue = rgen.frand2(); + m_level = m_nextmidpt; + m_nextmidpt = (m_nextvalue + value) * .5; + + float fseglen = (float)counter; + m_curve = 2.f * (m_nextmidpt - m_level - fseglen * m_slope) + / (fseglen * fseglen + fseglen); + + + m_timer.Reset(); + m_timer.Delay(tick); +} + +void LFNoise2_kr::m_perform(void*) +{ + m_slope+=m_curve; + m_level+=m_slope; + ToOutFloat(0,m_level); + if (--counter) + { + m_timer.Reset(); + m_timer.Delay(tick); + } + else + { + counter = (dt/tick); + + counter = sc_max(2, counter); + + float value = m_nextvalue; + m_nextvalue = rgen.frand2(); + m_level = m_nextmidpt; + m_nextmidpt = (m_nextvalue + value) * .5; + + float fseglen = (float)counter; + m_curve = 2.f * (m_nextmidpt - m_level - fseglen * m_slope) / + (fseglen * fseglen + fseglen); + + m_timer.Reset(); + m_timer.Delay(tick); + + } +} + diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 5940253..0ce8b16 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -57,7 +57,7 @@ void sc4pd_library_setup() "PinkNoise(~), \n Crackle(~), Rand(~), TRand(~), " "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" - " LFNoise0(~)\n"); + " LFNoise0(~), LFNoise1(~), LFNoise2\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -124,6 +124,12 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(LFNoise0_ar); FLEXT_SETUP(LFNoise0_kr); + + FLEXT_DSP_SETUP(LFNoise1_ar); + FLEXT_SETUP(LFNoise1_kr); + + FLEXT_DSP_SETUP(LFNoise2_ar); + FLEXT_SETUP(LFNoise2_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 96b9d4ab74d9b0d9bb073932f7e804585f1a7c80 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 17 Jul 2004 17:27:17 +0000 Subject: one more object and some changes svn path=/trunk/externals/tb/; revision=1870 --- sc4pd/make-files.txt | 3 +- sc4pd/pd/lfclipnoise.pd | 15 ++-- sc4pd/pd/lfnoise1.pd | 6 +- sc4pd/pd/lfnoise2.pd | 17 ++++ sc4pd/pd/logistic.pd | 24 ++++++ sc4pd/source/Crackle.cpp | 4 +- sc4pd/source/Logistic.cpp | 205 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 5 +- 8 files changed, 266 insertions(+), 13 deletions(-) create mode 100644 sc4pd/pd/lfnoise2.pd create mode 100644 sc4pd/pd/logistic.pd create mode 100644 sc4pd/source/Logistic.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 5952f9a..e652215 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -5,4 +5,5 @@ SRCS= \ BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ - ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ No newline at end of file + ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ + Logistic.cpp \ No newline at end of file diff --git a/sc4pd/pd/lfclipnoise.pd b/sc4pd/pd/lfclipnoise.pd index a4c3496..63f2eb7 100644 --- a/sc4pd/pd/lfclipnoise.pd +++ b/sc4pd/pd/lfclipnoise.pd @@ -1,10 +1,13 @@ #N canvas 0 0 450 300 10; -#X obj 89 115 print~; -#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --1; #X floatatom 246 97 5 0 0 0 - - -; -#X obj 89 48 LFClipNoise~ 1000; #X obj 246 55 LFClipNoise 10; +#X obj 139 179 dac~; +#X obj 89 154 *~ 0.1; +#X obj 161 124 LFClipNoise~ 1001; +#X obj 89 48 LFClipNoise~ 999; +#X obj 161 151 *~ 0.1; #X connect 1 0 0 0; -#X connect 3 0 0 0; -#X connect 4 0 2 0; +#X connect 3 0 2 0; +#X connect 4 0 6 0; +#X connect 5 0 3 0; +#X connect 6 0 2 1; diff --git a/sc4pd/pd/lfnoise1.pd b/sc4pd/pd/lfnoise1.pd index e6a261c..6e401f1 100644 --- a/sc4pd/pd/lfnoise1.pd +++ b/sc4pd/pd/lfnoise1.pd @@ -6,12 +6,12 @@ #X obj 246 143 timer; #X obj 246 123 t b b; #X floatatom 246 168 5 0 0 0 - - -; -#X obj 246 55 LFNoise0 10; #X obj 89 48 LFNoise1~ 100; +#X obj 246 55 LFNoise1 10; #X connect 1 0 0 0; #X connect 2 0 4 0; #X connect 3 0 5 0; #X connect 4 0 3 0; #X connect 4 1 3 1; -#X connect 6 0 2 0; -#X connect 7 0 0 0; +#X connect 6 0 0 0; +#X connect 7 0 2 0; diff --git a/sc4pd/pd/lfnoise2.pd b/sc4pd/pd/lfnoise2.pd new file mode 100644 index 0000000..3874d41 --- /dev/null +++ b/sc4pd/pd/lfnoise2.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 89 115 print~; +#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 246 97 5 0 0 0 - - -; +#X obj 246 143 timer; +#X obj 246 123 t b b; +#X floatatom 246 168 5 0 0 0 - - -; +#X obj 246 55 LFNoise2 10; +#X obj 89 48 LFNoise2~ 100; +#X connect 1 0 0 0; +#X connect 2 0 4 0; +#X connect 3 0 5 0; +#X connect 4 0 3 0; +#X connect 4 1 3 1; +#X connect 6 0 2 0; +#X connect 7 0 0 0; diff --git a/sc4pd/pd/logistic.pd b/sc4pd/pd/logistic.pd new file mode 100644 index 0000000..2bb42d6 --- /dev/null +++ b/sc4pd/pd/logistic.pd @@ -0,0 +1,24 @@ +#N canvas 0 0 450 300 10; +#X obj 89 115 print~; +#X floatatom 246 97 5 0 0 0 - - -; +#X obj 246 143 timer; +#X obj 246 123 t b b; +#X floatatom 246 168 5 0 0 0 - - -; +#X obj 246 55 Logistic 1 0.5; +#X obj 246 17 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 74 159 dac~; +#X obj 89 134 Logistic~ 1000 4 0.4; +#X obj 116 90 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 89 48 Logistic~ 1000 4 0.4; +#X connect 1 0 3 0; +#X connect 2 0 4 0; +#X connect 3 0 2 0; +#X connect 3 1 2 1; +#X connect 5 0 1 0; +#X connect 6 0 5 0; +#X connect 8 0 7 1; +#X connect 9 0 0 0; +#X connect 10 0 0 0; +#X connect 10 0 7 0; diff --git a/sc4pd/source/Crackle.cpp b/sc4pd/source/Crackle.cpp index a86ea18..0bc9ae0 100644 --- a/sc4pd/source/Crackle.cpp +++ b/sc4pd/source/Crackle.cpp @@ -74,7 +74,7 @@ FLEXT_LIB_DSP_V("Crackle~",Crackle_ar); Crackle_ar::Crackle_ar(int argc, t_atom *argv) : m_y1(0.3f),m_y2(0.f) { - FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD_(0,"parameter",m_set); //parse arguments AtomList Args(argc,argv); m_paramf=sc_getfloatarg(Args,0); @@ -139,7 +139,7 @@ Crackle_kr::Crackle_kr(int argc, t_atom *argv) : m_y1(0.3f),m_y2(0.f) { FLEXT_ADDBANG(0,m_perform); - FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD_(0,"parameter",m_set); //parse arguments AtomList Args(argc,argv); diff --git a/sc4pd/source/Logistic.cpp b/sc4pd/source/Logistic.cpp new file mode 100644 index 0000000..9a475e0 --- /dev/null +++ b/sc4pd/source/Logistic.cpp @@ -0,0 +1,205 @@ +/* sc4pd + Logistic, Logistic~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Fred Frith: Gravity + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ Logistic~ -------------------------------*/ + +class Logistic_ar: + public flext_dsp +{ + FLEXT_HEADER(Logistic_ar,flext_dsp); + +public: + Logistic_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_freq = sc_min(f,m_sr); + } + + void m_param(float f) + { + m_paramf = f; + } + +private: + int m_freq; + float m_paramf; + + int m_sr; + double m_y1; + int m_counter; + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_param); +}; + +FLEXT_LIB_DSP_V("Logistic~",Logistic_ar); + +Logistic_ar::Logistic_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"set",m_set); + FLEXT_ADDMETHOD_(0,"parameter",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_paramf = sc_getfloatarg(Args,1); + m_y1 = sc_getfloatarg(Args,2); + + m_sr=48000; // this is just a guess (i'll think about this later) + + AddOutSignal(); +} + +void Logistic_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_sr = Samplerate(); + m_paramf = sc_min(m_paramf,m_sr); +} + + +void Logistic_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + if(m_sr == m_paramf) + { + /* it might be possible to implement this without the branch */ + + double y1 = m_y1; + double paramf = m_paramf; + for (int i = 0; i!= n;++i) + { + (*(nout)++)= y1 = paramf * y1 * (1.0 - y1); + } + m_y1 = y1; + } + else + { + double y1 = m_y1; + double paramf = m_paramf; + int counter = m_counter; + int remain = n; + do + { + if (counter<=0) + { + counter = (int)(m_sr / sc_max(m_freq, .001f)); + counter = sc_max(1, counter); + y1 = paramf * y1 * (1.0 - y1); + } + + int nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + (*(nout)++)=y1; + } + } + while(remain); + m_y1 = y1; + m_counter = counter; + } +} + + +/* ------------------------ Logistic ---------------------------------*/ + +class Logistic_kr: + public flext_base +{ + FLEXT_HEADER(Logistic_kr,flext_base); + +public: + Logistic_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_param(float f) + { + m_paramf = f; + } + +private: + float m_paramf; + double m_y1; + + FLEXT_CALLBACK(m_perform); + FLEXT_CALLBACK_F(m_param); +}; + +FLEXT_LIB_V("Logistic",Logistic_kr); + +Logistic_kr::Logistic_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"parameter",m_param); + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + + m_paramf = sc_getfloatarg(Args,0); + m_y1 = sc_getfloatarg(Args,1); + + AddOutFloat(); +} + +void Logistic_kr::m_perform() +{ + m_y1 = m_paramf * m_y1 * (1.0 - m_y1); + ToOutFloat(0,m_y1); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 0ce8b16..6294cbb 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -57,7 +57,7 @@ void sc4pd_library_setup() "PinkNoise(~), \n Crackle(~), Rand(~), TRand(~), " "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" - " LFNoise0(~), LFNoise1(~), LFNoise2\n"); + " LFNoise0(~), LFNoise1(~), LFNoise2(~), Logistic(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -130,6 +130,9 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(LFNoise2_ar); FLEXT_SETUP(LFNoise2_kr); + + FLEXT_DSP_SETUP(Logistic_ar); + FLEXT_SETUP(Logistic_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 1975cbb20fda8e57b3d923358cf5007605af421c Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 19 Jul 2004 21:28:04 +0000 Subject: another object svn path=/trunk/externals/tb/; revision=1872 --- sc4pd/make-files.txt | 2 +- sc4pd/pd/latoocarfian.pd | 18 ++++ sc4pd/source/Latoocarfian.cpp | 226 ++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 6 +- 4 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 sc4pd/pd/latoocarfian.pd create mode 100644 sc4pd/source/Latoocarfian.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index e652215..df0e4a6 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -6,4 +6,4 @@ SRCS= \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ - Logistic.cpp \ No newline at end of file + Logistic.cpp Latoocarfian.cpp \ No newline at end of file diff --git a/sc4pd/pd/latoocarfian.pd b/sc4pd/pd/latoocarfian.pd new file mode 100644 index 0000000..a3fb7e1 --- /dev/null +++ b/sc4pd/pd/latoocarfian.pd @@ -0,0 +1,18 @@ +#N canvas 0 0 450 300 10; +#X obj 89 115 print~; +#X obj 141 88 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 128 161 dac~; +#X obj 89 48 Latoocarfian~ 0.88 1.8 1.2 1.3; +#X obj 231 125 Latoocarfian 0.88 1.8 1.2 1.3; +#X floatatom 247 154 5 0 0 0 - - -; +#X floatatom 410 152 5 0 0 0 - - -; +#X obj 275 97 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 1 0 0 0; +#X connect 3 0 0 0; +#X connect 3 0 2 0; +#X connect 3 1 2 1; +#X connect 4 0 5 0; +#X connect 4 1 6 0; +#X connect 7 0 4 0; diff --git a/sc4pd/source/Latoocarfian.cpp b/sc4pd/source/Latoocarfian.cpp new file mode 100644 index 0000000..f831c27 --- /dev/null +++ b/sc4pd/source/Latoocarfian.cpp @@ -0,0 +1,226 @@ +/* sc4pd + Latoocarfian, Latoocarfian~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & John Tilbury: Duos For Doris + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ Latoocarfian~ -------------------------------*/ + +class Latoocarfian_ar: + public flext_dsp +{ + FLEXT_HEADER(Latoocarfian_ar,flext_dsp); + +public: + Latoocarfian_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set_a(float f) + { + m_a = f; + } + + void m_set_b(float f) + { + m_b = f; + } + + void m_set_c(float f) + { + m_c = f; + } + + void m_set_d(float f) + { + m_d = f; + } + +private: + float m_x, m_y; //state + float m_a, m_b, m_c, m_d; //parameters + + FLEXT_CALLBACK_F(m_set_a); + FLEXT_CALLBACK_F(m_set_b); + FLEXT_CALLBACK_F(m_set_c); + FLEXT_CALLBACK_F(m_set_d); +}; + +FLEXT_LIB_DSP_V("Latoocarfian~",Latoocarfian_ar); + +Latoocarfian_ar::Latoocarfian_ar(int argc, t_atom *argv) + :m_x(0.4),m_y(1) +{ + FLEXT_ADDMETHOD_(0,"a",m_set_a); + FLEXT_ADDMETHOD_(0,"b",m_set_b); + FLEXT_ADDMETHOD_(0,"c",m_set_c); + FLEXT_ADDMETHOD_(0,"d",m_set_d); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()!=4) + { + post("4 arguments needed"); + } + + m_a = sc_getfloatarg(Args,0); + m_b = sc_getfloatarg(Args,1); + m_c = sc_getfloatarg(Args,2); + m_d = sc_getfloatarg(Args,3); + + AddOutSignal(); + AddOutSignal(); // supercollider is only using the x coordinate +} + + +void Latoocarfian_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *xout = *out; + t_sample *yout = *(out+1); + + float a = m_a; + float b = m_b; + float c = m_c; + float d = m_d; + + float x = m_x; + float y = m_y; + + for (int i = 0; i!= n;++i) + { + float x_new=sin(y*b)+c*sin(x*b); + float y_new=sin(x*a)+d*sin(y*a); + (*(xout)++)=x=x_new; + (*(yout)++)=y=y_new; + } + m_x = x; + m_y = y; +} + + + +/* ------------------------ Latoocarfian ---------------------------------*/ + +class Latoocarfian_kr: + public flext_base +{ + FLEXT_HEADER(Latoocarfian_kr,flext_base); + +public: + Latoocarfian_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_set_a(float f) + { + m_a = f; + } + + void m_set_b(float f) + { + m_b = f; + } + + void m_set_c(float f) + { + m_c = f; + } + + void m_set_d(float f) + { + m_d = f; + } + +private: + float m_x, m_y; //state + float m_a, m_b, m_c, m_d; //parameters + + FLEXT_CALLBACK_F(m_set_a); + FLEXT_CALLBACK_F(m_set_b); + FLEXT_CALLBACK_F(m_set_c); + FLEXT_CALLBACK_F(m_set_d); + FLEXT_CALLBACK(m_perform); +}; + + +FLEXT_LIB_V("Latoocarfian",Latoocarfian_kr); + +Latoocarfian_kr::Latoocarfian_kr(int argc, t_atom *argv) + :m_x(1),m_y(1) +{ + FLEXT_ADDMETHOD_(0,"a",m_set_a); + FLEXT_ADDMETHOD_(0,"b",m_set_b); + FLEXT_ADDMETHOD_(0,"c",m_set_c); + FLEXT_ADDMETHOD_(0,"d",m_set_d); + + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + if (Args.Count()!=4) + { + post("4 arguments needed"); + } + m_a = sc_getfloatarg(Args,0); + m_b = sc_getfloatarg(Args,1); + m_c = sc_getfloatarg(Args,2); + m_d = sc_getfloatarg(Args,3); + + + AddOutFloat(); + AddOutFloat(); // one outlet more than sc +} + +void Latoocarfian_kr::m_perform() +{ + m_x=sin(m_y*m_b)+m_c*sin(m_x*m_b); + m_y=sin(m_x*m_a)+m_d*sin(m_y*m_a); + + ToOutFloat(0,m_x); + ToOutFloat(1,m_y); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 6294cbb..668c300 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -57,7 +57,8 @@ void sc4pd_library_setup() "PinkNoise(~), \n Crackle(~), Rand(~), TRand(~), " "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" - " LFNoise0(~), LFNoise1(~), LFNoise2(~), Logistic(~)\n"); + " LFNoise0(~), LFNoise1(~), LFNoise2(~), Logistic(~), " + "Latoocarfian(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -133,6 +134,9 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Logistic_ar); FLEXT_SETUP(Logistic_kr); + + FLEXT_DSP_SETUP(Latoocarfian_ar); + FLEXT_SETUP(Latoocarfian_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 9b76d2cfe25558b3f1951fcf8ee26982beca1e48 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 23 Jul 2004 10:01:56 +0000 Subject: added LinCong ugen svn path=/trunk/externals/tb/; revision=1887 --- sc4pd/config-pd-linux.txt | 6 +- sc4pd/make-files.txt | 2 +- sc4pd/pd/lincong.pd | 17 ++++ sc4pd/source/Latoocarfian.cpp | 4 +- sc4pd/source/LinCong.cpp | 218 ++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 5 +- 6 files changed, 244 insertions(+), 8 deletions(-) create mode 100644 sc4pd/pd/lincong.pd create mode 100644 sc4pd/source/LinCong.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 7aac9a8..9b46ed4 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) - CXX=icc +# CXX=icc # where does the PD installation reside? @@ -28,8 +28,8 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) -UFLAGS=-xN -tpp7 -ip -ipo_obj # icc -#UFLAGS=-g -mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 +#UFLAGS=-xN -tpp7 -ip -ipo_obj # icc +UFLAGS=-g -mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index df0e4a6..b662391 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -6,4 +6,4 @@ SRCS= \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ - Logistic.cpp Latoocarfian.cpp \ No newline at end of file + Logistic.cpp Latoocarfian.cpp LinCong.cpp \ No newline at end of file diff --git a/sc4pd/pd/lincong.pd b/sc4pd/pd/lincong.pd new file mode 100644 index 0000000..c777695 --- /dev/null +++ b/sc4pd/pd/lincong.pd @@ -0,0 +1,17 @@ +#N canvas 257 167 708 300 10; +#X obj 132 247 dac~; +#X obj 228 253 print~; +#X obj 309 229 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 286 73 LinCong 100 103 140 120002; +#X obj 267 32 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 295 110 10 0 0 0 - - -; +#X obj 577 226 block~ 64; +#X obj 22 142 LinCong~ 13437 1433.34 1.34233e+06 4.33243e+09; +#X connect 2 0 1 0; +#X connect 3 0 5 0; +#X connect 4 0 3 0; +#X connect 7 0 0 0; +#X connect 7 0 0 1; +#X connect 7 0 1 0; diff --git a/sc4pd/source/Latoocarfian.cpp b/sc4pd/source/Latoocarfian.cpp index f831c27..c509711 100644 --- a/sc4pd/source/Latoocarfian.cpp +++ b/sc4pd/source/Latoocarfian.cpp @@ -91,7 +91,7 @@ private: FLEXT_LIB_DSP_V("Latoocarfian~",Latoocarfian_ar); Latoocarfian_ar::Latoocarfian_ar(int argc, t_atom *argv) - :m_x(0.4),m_y(1) + :m_x(4),m_y(1) { FLEXT_ADDMETHOD_(0,"a",m_set_a); FLEXT_ADDMETHOD_(0,"b",m_set_b); @@ -100,12 +100,10 @@ Latoocarfian_ar::Latoocarfian_ar(int argc, t_atom *argv) //parse arguments AtomList Args(argc,argv); - if (Args.Count()!=4) { post("4 arguments needed"); } - m_a = sc_getfloatarg(Args,0); m_b = sc_getfloatarg(Args,1); m_c = sc_getfloatarg(Args,2); diff --git a/sc4pd/source/LinCong.cpp b/sc4pd/source/LinCong.cpp new file mode 100644 index 0000000..0da0df7 --- /dev/null +++ b/sc4pd/source/LinCong.cpp @@ -0,0 +1,218 @@ +/* sc4pd + LinCong, LinCong~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & John Tilbury: Duos For Doris + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LinCong~ -------------------------------*/ + +class LinCong_ar: + public flext_dsp +{ + FLEXT_HEADER(LinCong_ar,flext_dsp); + +public: + LinCong_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set_seed(float f) + { + m_seed = (int)f; + } + + void m_set_mul(float f) + { + m_mul = (int)f; + } + + void m_set_add(float f) + { + m_add = (int)f; + } + + void m_set_mod(float f) + { + m_mod = (int)f; + m_scale = 2/f; //output between -1 and 1 + } + +private: + unsigned int m_seed; //seed + unsigned int m_mul, m_add, m_mod; //parameters + + float m_scale; + + FLEXT_CALLBACK_F(m_set_seed); + FLEXT_CALLBACK_F(m_set_mul); + FLEXT_CALLBACK_F(m_set_add); + FLEXT_CALLBACK_F(m_set_mod); +}; + +FLEXT_LIB_DSP_V("LinCong~",LinCong_ar); + +LinCong_ar::LinCong_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_set_seed); + FLEXT_ADDMETHOD_(0,"mul",m_set_mul); + FLEXT_ADDMETHOD_(0,"add",m_set_add); + FLEXT_ADDMETHOD_(0,"mod",m_set_mod); + + //parse arguments + AtomList Args(argc,argv); + if (Args.Count()!=4) + { + post("4 arguments needed"); + } + m_seed = sc_getfloatarg(Args,0); + m_mul = sc_getfloatarg(Args,1); + m_add = sc_getfloatarg(Args,2); + m_set_mod(sc_getfloatarg(Args,3)); + + AddOutSignal(); +} + + +void LinCong_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *xout = *out; + + + unsigned int seed = m_seed; + unsigned int mul = m_mul; + unsigned int add = m_add; + unsigned int mod = m_mod; + + float scale = m_scale; + + for (int i = 0; i!= n;++i) + { + seed=(seed * mul + add) % mod; + (*(xout)++)=float(seed)*scale - 1; + } + + m_seed = seed; +} + + + +/* ------------------------ LinCong ---------------------------------*/ + +class LinCong_kr: + public flext_base +{ + FLEXT_HEADER(LinCong_kr,flext_base); + +public: + LinCong_kr(int argc, t_atom *argv); + +protected: + void m_perform(); + + void m_set_seed(float f) + { + m_seed = (int)f; + } + + void m_set_mul(float f) + { + m_mul = (int)f; + } + + void m_set_add(float f) + { + m_add = (int)f; + } + + void m_set_mod(float f) + { + m_mod = (int)f; + m_scale = 2/f; //output between -1 and 1 + } + +private: + unsigned int m_seed; //seed + unsigned int m_mul, m_add, m_mod; //parameters + + float m_scale; + + FLEXT_CALLBACK_F(m_set_seed); + FLEXT_CALLBACK_F(m_set_mul); + FLEXT_CALLBACK_F(m_set_add); + FLEXT_CALLBACK_F(m_set_mod); + FLEXT_CALLBACK(m_perform); +}; + + +FLEXT_LIB_V("LinCong",LinCong_kr); + +LinCong_kr::LinCong_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_set_seed); + FLEXT_ADDMETHOD_(0,"mul",m_set_mul); + FLEXT_ADDMETHOD_(0,"add",m_set_add); + FLEXT_ADDMETHOD_(0,"mod",m_set_mod); + FLEXT_ADDBANG(0,m_perform); + + //parse arguments + AtomList Args(argc,argv); + if (Args.Count()!=4) + { + post("4 arguments needed"); + } + m_seed = sc_getfloatarg(Args,0); + m_mul = sc_getfloatarg(Args,1); + m_add = sc_getfloatarg(Args,2); + m_set_mod(sc_getfloatarg(Args,3)); + + AddOutFloat(); +} + +void LinCong_kr::m_perform() +{ + m_seed=(m_seed * m_mul + m_add) % m_mod; + ToOutFloat(0,float(m_seed) * m_scale - 1); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 668c300..9f2287a 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,7 @@ void sc4pd_library_setup() "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" " LFNoise0(~), LFNoise1(~), LFNoise2(~), Logistic(~), " - "Latoocarfian(~)\n"); + "Latoocarfian(~), LinCong(~)\n"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -137,6 +137,9 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Latoocarfian_ar); FLEXT_SETUP(Latoocarfian_kr); + + FLEXT_DSP_SETUP(LinCong_ar); + FLEXT_SETUP(LinCong_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 7cc309b8c5c5c901489e3b6c4fc95a6f049a58d7 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 29 Jul 2004 10:53:55 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r1896, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=1897 --- xvalue/LICENSE.txt | 30 +++++++++++++++++ xvalue/makefile | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ xvalue/test.pd | 14 ++++++++ xvalue/xvalue.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 215 insertions(+) create mode 100644 xvalue/LICENSE.txt create mode 100644 xvalue/makefile create mode 100644 xvalue/test.pd create mode 100644 xvalue/xvalue.c diff --git a/xvalue/LICENSE.txt b/xvalue/LICENSE.txt new file mode 100644 index 0000000..a56a51e --- /dev/null +++ b/xvalue/LICENSE.txt @@ -0,0 +1,30 @@ +This software is copyrighted by Miller Puckette and others. The following +terms (the "Standard Improved BSD License") apply to all files associated with +the software unless explicitly disclaimed in individual files: + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. +3. The name of the author may not be used to endorse or promote + products derived from this software without specific prior + written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. diff --git a/xvalue/makefile b/xvalue/makefile new file mode 100644 index 0000000..4cae4fc --- /dev/null +++ b/xvalue/makefile @@ -0,0 +1,94 @@ +NAME=xvalue +CSYM=xvalue + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations diff --git a/xvalue/test.pd b/xvalue/test.pd new file mode 100644 index 0000000..6b7e3c0 --- /dev/null +++ b/xvalue/test.pd @@ -0,0 +1,14 @@ +#N canvas 0 0 450 300 10; +#X obj 39 133 xvalue test1; +#X obj 220 139 value test; +#X floatatom 254 115 5 0 0 0 - - -; +#X floatatom 32 192 5 0 0 0 - - -; +#X obj 34 72 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 68 63 5 0 0 0 - - -; +#X msg 94 96 set test; +#X connect 0 0 3 0; +#X connect 2 0 1 0; +#X connect 4 0 0 0; +#X connect 5 0 0 0; +#X connect 6 0 0 0; diff --git a/xvalue/xvalue.c b/xvalue/xvalue.c new file mode 100644 index 0000000..4f16f06 --- /dev/null +++ b/xvalue/xvalue.c @@ -0,0 +1,77 @@ +/* extended (settable) value object + Copyright (c) 2004 Tim Blechmann + a huge part of the code is broken out of the code of the value object. + + * Copyright (c) 1997-1999 Miller Puckette. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +#include "m_pd.h" + + +/* -------------------- xvalue ----------------------------- */ + +static t_class *xvalue_class; + +static t_class *vcommon_class; + +typedef struct vcommon +{ + t_pd c_pd; + int c_refcount; + t_float c_f; +} t_vcommon; + + +typedef struct _xvalue +{ + t_object x_obj; + t_symbol *x_sym; + t_float *x_floatstar; +} t_xvalue; + +static void *xvalue_new(t_symbol *s) +{ + t_xvalue *x = (t_xvalue *)pd_new(xvalue_class); + x->x_sym = s; + x->x_floatstar = value_get(s); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +static void xvalue_bang(t_xvalue *x) +{ + outlet_float(x->x_obj.ob_outlet, *x->x_floatstar); +} + +static void xvalue_float(t_xvalue *x, t_float f) +{ + *x->x_floatstar = f; +} + +static void xvalue_ff(t_xvalue *x) +{ + value_release(x->x_sym); +} + +static void xvalue_set(t_xvalue *x, t_symbol *s) +{ + x->x_sym = s; + x->x_floatstar = value_get(s); +} + +void xvalue_setup(void) +{ + xvalue_class = class_new(gensym("xvalue"), (t_newmethod)xvalue_new, + (t_method)xvalue_ff, + sizeof(t_xvalue), 0, A_DEFSYM, 0); + class_addcreator((t_newmethod)xvalue_new, gensym("xv"), A_DEFSYM, 0); + class_addbang(xvalue_class, xvalue_bang); + class_addfloat(xvalue_class, xvalue_float); + class_addmethod(xvalue_class, (t_method) xvalue_set, gensym("set"), + A_SYMBOL, 0); + vcommon_class = class_new(gensym("xvalue"), 0, 0, + sizeof(t_vcommon), CLASS_PD, 0); +} + + -- cgit v1.2.1 From 5a8caf3981072a2184a17bd9a23c4b7b6f07feb7 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 30 Jul 2004 08:43:43 +0000 Subject: 0001's fixes svn path=/trunk/externals/tb/; revision=1898 --- sc4pd/makefile.pd-darwin | 4 ++-- sc4pd/source/support.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sc4pd/makefile.pd-darwin b/sc4pd/makefile.pd-darwin index 04a3779..9523425 100755 --- a/sc4pd/makefile.pd-darwin +++ b/sc4pd/makefile.pd-darwin @@ -15,7 +15,7 @@ include ${CONFIG} FLEXTLIB=$(FLEXTPATH)/libflext.a # compiler stuff -INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang +INCLUDES=$(PDINC) ./headers/plugin_interface ./headers/common ./headers/server ./headers/app ./headers/lang /usr/include/machine/ FLAGS=-DFLEXT_SYS=2 CFLAGS=${UFLAGS} -dynamic -O2 -Wno-unused -Wno-parentheses -Wno-switch -Wstrict-prototypes -funroll-loops -fmove-all-movables -frerun-loop-opt -fno-rtti -fno-exceptions LIBS=m gcc @@ -26,7 +26,7 @@ FRAMEWORKS=Carbon veclib # the rest can stay untouched # ---------------------------------------------- -NAME=sc4dp +NAME=sc4pd include make-files.txt diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp index 8d80bbe..5211b71 100644 --- a/sc4pd/source/support.cpp +++ b/sc4pd/source/support.cpp @@ -102,7 +102,7 @@ int32 timeseed() double usec = (time-sec)*1e6; time_t tsec = sec; - suseconds_t tusec =usec; /* not exacty the way, it's calculated + useconds_t tusec =usec; /* not exacty the way, it's calculated in SuperCollider, but it's only the seed */ -- cgit v1.2.1 From 0aa3917ce03265d942b86fcc0b0d224b0e46627f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 30 Jul 2004 21:27:07 +0000 Subject: Binary Operators svn path=/trunk/externals/tb/; revision=1899 --- sc4pd/make-files.txt | 4 +- sc4pd/pd/amclip.pd | 16 ++++++ sc4pd/pd/excess.pd | 16 ++++++ sc4pd/pd/scaleneg.pd | 16 ++++++ sc4pd/source/absdif.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/amclip.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/difsqr.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/excess.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/hypot.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 46 +++++++++++++++- sc4pd/source/ring1.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring1.cpp~ | 130 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring2.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring2.cpp~ | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring3.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring3.cpp~ | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring4.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/ring4.cpp~ | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/scaleneg.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/sqrdif.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/sqrdif.cpp~ | 136 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/sqrsum.cpp | 137 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/sqrsum.cpp~ | 137 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/sumsqr.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ 24 files changed, 2657 insertions(+), 2 deletions(-) create mode 100644 sc4pd/pd/amclip.pd create mode 100644 sc4pd/pd/excess.pd create mode 100644 sc4pd/pd/scaleneg.pd create mode 100644 sc4pd/source/absdif.cpp create mode 100644 sc4pd/source/amclip.cpp create mode 100644 sc4pd/source/difsqr.cpp create mode 100644 sc4pd/source/excess.cpp create mode 100644 sc4pd/source/hypot.cpp create mode 100644 sc4pd/source/ring1.cpp create mode 100644 sc4pd/source/ring1.cpp~ create mode 100644 sc4pd/source/ring2.cpp create mode 100644 sc4pd/source/ring2.cpp~ create mode 100644 sc4pd/source/ring3.cpp create mode 100644 sc4pd/source/ring3.cpp~ create mode 100644 sc4pd/source/ring4.cpp create mode 100644 sc4pd/source/ring4.cpp~ create mode 100644 sc4pd/source/scaleneg.cpp create mode 100644 sc4pd/source/sqrdif.cpp create mode 100644 sc4pd/source/sqrdif.cpp~ create mode 100644 sc4pd/source/sqrsum.cpp create mode 100644 sc4pd/source/sqrsum.cpp~ create mode 100644 sc4pd/source/sumsqr.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index b662391..c5a874b 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -6,4 +6,6 @@ SRCS= \ PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ - Logistic.cpp Latoocarfian.cpp LinCong.cpp \ No newline at end of file + Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ + excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ + difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp \ No newline at end of file diff --git a/sc4pd/pd/amclip.pd b/sc4pd/pd/amclip.pd new file mode 100644 index 0000000..21cfb91 --- /dev/null +++ b/sc4pd/pd/amclip.pd @@ -0,0 +1,16 @@ +#N canvas 0 0 450 300 10; +#X obj 33 137 amclip~; +#X obj 26 88 osc~ 440; +#X obj 22 176 dac~; +#X floatatom 327 136 5 0 0 0 - - -; +#X obj 96 113 osc~ 40; +#X floatatom 222 99 5 0 0 0 - - -; +#X floatatom 263 228 5 0 0 0 - - -; +#X obj 263 181 amclip; +#X connect 0 0 2 0; +#X connect 0 0 2 1; +#X connect 1 0 0 0; +#X connect 3 0 7 1; +#X connect 4 0 0 1; +#X connect 5 0 7 0; +#X connect 7 0 6 0; diff --git a/sc4pd/pd/excess.pd b/sc4pd/pd/excess.pd new file mode 100644 index 0000000..3edde5e --- /dev/null +++ b/sc4pd/pd/excess.pd @@ -0,0 +1,16 @@ +#N canvas 0 0 450 300 10; +#X obj 26 88 osc~ 440; +#X obj 22 176 dac~; +#X floatatom 327 136 5 0 0 0 - - -; +#X floatatom 222 99 5 0 0 0 - - -; +#X floatatom 263 228 5 0 0 0 - - -; +#X obj 33 137 excess~; +#X obj 96 113 osc~ 45; +#X obj 263 181 excess; +#X connect 0 0 5 0; +#X connect 2 0 7 1; +#X connect 3 0 7 0; +#X connect 5 0 1 0; +#X connect 5 0 1 1; +#X connect 6 0 5 1; +#X connect 7 0 4 0; diff --git a/sc4pd/pd/scaleneg.pd b/sc4pd/pd/scaleneg.pd new file mode 100644 index 0000000..70e6f14 --- /dev/null +++ b/sc4pd/pd/scaleneg.pd @@ -0,0 +1,16 @@ +#N canvas 0 0 450 300 10; +#X obj 26 88 osc~ 440; +#X obj 22 176 dac~; +#X floatatom 327 136 5 0 0 0 - - -; +#X floatatom 222 99 5 0 0 0 - - -; +#X floatatom 263 228 5 0 0 0 - - -; +#X obj 33 137 scaleneg~; +#X obj 263 181 scaleneg; +#X obj 96 113 osc~ 230; +#X connect 0 0 5 0; +#X connect 2 0 6 1; +#X connect 3 0 6 0; +#X connect 5 0 1 0; +#X connect 5 0 1 1; +#X connect 6 0 4 0; +#X connect 7 0 5 1; diff --git a/sc4pd/source/absdif.cpp b/sc4pd/source/absdif.cpp new file mode 100644 index 0000000..34f41db --- /dev/null +++ b/sc4pd/source/absdif.cpp @@ -0,0 +1,137 @@ +/* sc4pd + absdif, absdif~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_absdif (float a, float b) +{ + float f=a-b; + return fabsf(f); +} + + +/* ------------------------ absdif~ -----------------------------*/ + +class absdif_ar + :public flext_dsp +{ + FLEXT_HEADER(absdif_ar,flext_dsp); + +public: + absdif_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("absdif~",absdif_ar); + +absdif_ar::absdif_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void absdif_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_absdif( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ absdif ------------------------------*/ + +class absdif_kr + :public flext_base +{ + FLEXT_HEADER(absdif_kr,flext_base); + +public: + absdif_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("absdif",absdif_kr); + +absdif_kr::absdif_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void absdif_kr::m_perform(float f) +{ + ToOutFloat(0,sc_absdif(f,b)); +} + +void absdif_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/amclip.cpp b/sc4pd/source/amclip.cpp new file mode 100644 index 0000000..9d4a936 --- /dev/null +++ b/sc4pd/source/amclip.cpp @@ -0,0 +1,133 @@ +/* sc4pd + amclip, amclip(~) + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Toshimaru Nakamura: Weather Sky + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ amclip~ -----------------------------*/ + +class amclip_ar + :public flext_dsp +{ + FLEXT_HEADER(amclip_ar,flext_dsp); + +public: + amclip_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("amclip~",amclip_ar); + +amclip_ar::amclip_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void amclip_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_amclip( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ amclip ------------------------------*/ + +class amclip_kr + :public flext_base +{ + FLEXT_HEADER(amclip_kr,flext_base); + +public: + amclip_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("amclip",amclip_kr); + +amclip_kr::amclip_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void amclip_kr::m_perform(float f) +{ + ToOutFloat(0,f*b); +} + +void amclip_kr::m_set(float f) +{ + if (f>0) + b=f; + else + b=0; +} diff --git a/sc4pd/source/difsqr.cpp b/sc4pd/source/difsqr.cpp new file mode 100644 index 0000000..823f266 --- /dev/null +++ b/sc4pd/source/difsqr.cpp @@ -0,0 +1,136 @@ +/* sc4pd + difsqr, difsqr~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_difsqr (float a, float b) +{ + return a*a-b*b; +} + + +/* ------------------------ difsqr~ -----------------------------*/ + +class difsqr_ar + :public flext_dsp +{ + FLEXT_HEADER(difsqr_ar,flext_dsp); + +public: + difsqr_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("difsqr~",difsqr_ar); + +difsqr_ar::difsqr_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void difsqr_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_difsqr( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ difsqr ------------------------------*/ + +class difsqr_kr + :public flext_base +{ + FLEXT_HEADER(difsqr_kr,flext_base); + +public: + difsqr_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("difsqr",difsqr_kr); + +difsqr_kr::difsqr_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void difsqr_kr::m_perform(float f) +{ + ToOutFloat(0,sc_difsqr(f,b)); +} + +void difsqr_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/excess.cpp b/sc4pd/source/excess.cpp new file mode 100644 index 0000000..00f8666 --- /dev/null +++ b/sc4pd/source/excess.cpp @@ -0,0 +1,130 @@ +/* sc4pd + excess, excess~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Toshimaru Nakamura: Weather Sky + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ excess~ -----------------------------*/ + +class excess_ar + :public flext_dsp +{ + FLEXT_HEADER(excess_ar,flext_dsp); + +public: + excess_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("excess~",excess_ar); + +excess_ar::excess_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void excess_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_excess( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ excess ------------------------------*/ + +class excess_kr + :public flext_base +{ + FLEXT_HEADER(excess_kr,flext_base); + +public: + excess_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("excess",excess_kr); + +excess_kr::excess_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void excess_kr::m_perform(float f) +{ + ToOutFloat(0,sc_excess(f,b)); +} + +void excess_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/hypot.cpp b/sc4pd/source/hypot.cpp new file mode 100644 index 0000000..b096e48 --- /dev/null +++ b/sc4pd/source/hypot.cpp @@ -0,0 +1,130 @@ +/* sc4pd + hypot, hypot~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Toshimaru Nakamura: Weather Sky + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ hypot~ -----------------------------*/ + +class hypot_ar + :public flext_dsp +{ + FLEXT_HEADER(hypot_ar,flext_dsp); + +public: + hypot_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("hypot~",hypot_ar); + +hypot_ar::hypot_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void hypot_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = hypot( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ hypot ------------------------------*/ + +class hypot_kr + :public flext_base +{ + FLEXT_HEADER(hypot_kr,flext_base); + +public: + hypot_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("hypot",hypot_kr); + +hypot_kr::hypot_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void hypot_kr::m_perform(float f) +{ + ToOutFloat(0,hypot(f,b)); +} + +void hypot_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 9f2287a..df430f9 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,12 @@ void sc4pd_library_setup() "TExpRand(~), IRand(~), TIRand(~),\n CoinGate, " "LinRand(~), NRand(~), ExpRand(~), LFClipNoise(~),\n" " LFNoise0(~), LFNoise1(~), LFNoise2(~), Logistic(~), " - "Latoocarfian(~), LinCong(~)\n"); + "Latoocarfian(~),\n" + " LinCong(~), amclip(~), scaleneg(~), excess(~), hypot(~), " + "ring1(~),\n" + " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~)\n" + "sqrdif(~), sqrsum(~),\n" + " absdif(~)"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -140,6 +145,45 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(LinCong_ar); FLEXT_SETUP(LinCong_kr); + + FLEXT_DSP_SETUP(amclip_ar); + FLEXT_SETUP(amclip_kr); + + FLEXT_DSP_SETUP(scaleneg_ar); + FLEXT_SETUP(scaleneg_kr); + + FLEXT_DSP_SETUP(excess_ar); + FLEXT_SETUP(excess_kr); + + FLEXT_DSP_SETUP(hypot_ar); + FLEXT_SETUP(hypot_kr); + + FLEXT_DSP_SETUP(ring1_ar); + FLEXT_SETUP(ring1_kr); + + FLEXT_DSP_SETUP(ring2_ar); + FLEXT_SETUP(ring2_kr); + + FLEXT_DSP_SETUP(ring3_ar); + FLEXT_SETUP(ring3_kr); + + FLEXT_DSP_SETUP(ring4_ar); + FLEXT_SETUP(ring4_kr); + + FLEXT_DSP_SETUP(difsqr_ar); + FLEXT_SETUP(difsqr_kr); + + FLEXT_DSP_SETUP(sumsqr_ar); + FLEXT_SETUP(sumsqr_kr); + + FLEXT_DSP_SETUP(sqrsum_ar); + FLEXT_SETUP(sqrsum_kr); + + FLEXT_DSP_SETUP(sqrdif_ar); + FLEXT_SETUP(sqrdif_kr); + + FLEXT_DSP_SETUP(absdif_ar); + FLEXT_SETUP(absdif_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/ring1.cpp b/sc4pd/source/ring1.cpp new file mode 100644 index 0000000..b9aee15 --- /dev/null +++ b/sc4pd/source/ring1.cpp @@ -0,0 +1,136 @@ +/* sc4pd + ring1, ring1~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring1 (float a, float b) +{ + return a*b+a; +} + + +/* ------------------------ ring1~ -----------------------------*/ + +class ring1_ar + :public flext_dsp +{ + FLEXT_HEADER(ring1_ar,flext_dsp); + +public: + ring1_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring1~",ring1_ar); + +ring1_ar::ring1_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring1_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring1( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring1 ------------------------------*/ + +class ring1_kr + :public flext_base +{ + FLEXT_HEADER(ring1_kr,flext_base); + +public: + ring1_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring1",ring1_kr); + +ring1_kr::ring1_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring1_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring1(f,b)); +} + +void ring1_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring1.cpp~ b/sc4pd/source/ring1.cpp~ new file mode 100644 index 0000000..00f8666 --- /dev/null +++ b/sc4pd/source/ring1.cpp~ @@ -0,0 +1,130 @@ +/* sc4pd + excess, excess~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Toshimaru Nakamura: Weather Sky + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ excess~ -----------------------------*/ + +class excess_ar + :public flext_dsp +{ + FLEXT_HEADER(excess_ar,flext_dsp); + +public: + excess_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("excess~",excess_ar); + +excess_ar::excess_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void excess_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_excess( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ excess ------------------------------*/ + +class excess_kr + :public flext_base +{ + FLEXT_HEADER(excess_kr,flext_base); + +public: + excess_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("excess",excess_kr); + +excess_kr::excess_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void excess_kr::m_perform(float f) +{ + ToOutFloat(0,sc_excess(f,b)); +} + +void excess_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring2.cpp b/sc4pd/source/ring2.cpp new file mode 100644 index 0000000..02e9a18 --- /dev/null +++ b/sc4pd/source/ring2.cpp @@ -0,0 +1,136 @@ +/* sc4pd + ring2, ring2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring2 (float a, float b) +{ + return a*b+a+b; +} + + +/* ------------------------ ring2~ -----------------------------*/ + +class ring2_ar + :public flext_dsp +{ + FLEXT_HEADER(ring2_ar,flext_dsp); + +public: + ring2_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring2~",ring2_ar); + +ring2_ar::ring2_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring2( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring2 ------------------------------*/ + +class ring2_kr + :public flext_base +{ + FLEXT_HEADER(ring2_kr,flext_base); + +public: + ring2_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring2",ring2_kr); + +ring2_kr::ring2_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring2_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring2(f,b)); +} + +void ring2_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring2.cpp~ b/sc4pd/source/ring2.cpp~ new file mode 100644 index 0000000..b9aee15 --- /dev/null +++ b/sc4pd/source/ring2.cpp~ @@ -0,0 +1,136 @@ +/* sc4pd + ring1, ring1~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring1 (float a, float b) +{ + return a*b+a; +} + + +/* ------------------------ ring1~ -----------------------------*/ + +class ring1_ar + :public flext_dsp +{ + FLEXT_HEADER(ring1_ar,flext_dsp); + +public: + ring1_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring1~",ring1_ar); + +ring1_ar::ring1_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring1_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring1( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring1 ------------------------------*/ + +class ring1_kr + :public flext_base +{ + FLEXT_HEADER(ring1_kr,flext_base); + +public: + ring1_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring1",ring1_kr); + +ring1_kr::ring1_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring1_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring1(f,b)); +} + +void ring1_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring3.cpp b/sc4pd/source/ring3.cpp new file mode 100644 index 0000000..1887066 --- /dev/null +++ b/sc4pd/source/ring3.cpp @@ -0,0 +1,136 @@ +/* sc4pd + ring3, ring3~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring3 (float a, float b) +{ + return a*a*b; +} + + +/* ------------------------ ring3~ -----------------------------*/ + +class ring3_ar + :public flext_dsp +{ + FLEXT_HEADER(ring3_ar,flext_dsp); + +public: + ring3_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring3~",ring3_ar); + +ring3_ar::ring3_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring3_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring3( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring3 ------------------------------*/ + +class ring3_kr + :public flext_base +{ + FLEXT_HEADER(ring3_kr,flext_base); + +public: + ring3_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring3",ring3_kr); + +ring3_kr::ring3_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring3_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring3(f,b)); +} + +void ring3_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring3.cpp~ b/sc4pd/source/ring3.cpp~ new file mode 100644 index 0000000..02e9a18 --- /dev/null +++ b/sc4pd/source/ring3.cpp~ @@ -0,0 +1,136 @@ +/* sc4pd + ring2, ring2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring2 (float a, float b) +{ + return a*b+a+b; +} + + +/* ------------------------ ring2~ -----------------------------*/ + +class ring2_ar + :public flext_dsp +{ + FLEXT_HEADER(ring2_ar,flext_dsp); + +public: + ring2_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring2~",ring2_ar); + +ring2_ar::ring2_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring2( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring2 ------------------------------*/ + +class ring2_kr + :public flext_base +{ + FLEXT_HEADER(ring2_kr,flext_base); + +public: + ring2_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring2",ring2_kr); + +ring2_kr::ring2_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring2_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring2(f,b)); +} + +void ring2_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring4.cpp b/sc4pd/source/ring4.cpp new file mode 100644 index 0000000..b343f67 --- /dev/null +++ b/sc4pd/source/ring4.cpp @@ -0,0 +1,136 @@ +/* sc4pd + ring4, ring4~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring4 (float a, float b) +{ + return (a*a*b)-(a*b*b); +} + + +/* ------------------------ ring4~ -----------------------------*/ + +class ring4_ar + :public flext_dsp +{ + FLEXT_HEADER(ring4_ar,flext_dsp); + +public: + ring4_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring4~",ring4_ar); + +ring4_ar::ring4_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring4_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring4( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring4 ------------------------------*/ + +class ring4_kr + :public flext_base +{ + FLEXT_HEADER(ring4_kr,flext_base); + +public: + ring4_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring4",ring4_kr); + +ring4_kr::ring4_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring4_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring4(f,b)); +} + +void ring4_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/ring4.cpp~ b/sc4pd/source/ring4.cpp~ new file mode 100644 index 0000000..1887066 --- /dev/null +++ b/sc4pd/source/ring4.cpp~ @@ -0,0 +1,136 @@ +/* sc4pd + ring3, ring3~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_ring3 (float a, float b) +{ + return a*a*b; +} + + +/* ------------------------ ring3~ -----------------------------*/ + +class ring3_ar + :public flext_dsp +{ + FLEXT_HEADER(ring3_ar,flext_dsp); + +public: + ring3_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("ring3~",ring3_ar); + +ring3_ar::ring3_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void ring3_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_ring3( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ ring3 ------------------------------*/ + +class ring3_kr + :public flext_base +{ + FLEXT_HEADER(ring3_kr,flext_base); + +public: + ring3_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("ring3",ring3_kr); + +ring3_kr::ring3_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void ring3_kr::m_perform(float f) +{ + ToOutFloat(0,sc_ring3(f,b)); +} + +void ring3_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/scaleneg.cpp b/sc4pd/source/scaleneg.cpp new file mode 100644 index 0000000..f6e69db --- /dev/null +++ b/sc4pd/source/scaleneg.cpp @@ -0,0 +1,130 @@ +/* sc4pd + scaleneg, scaleneg(~) + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Toshimaru Nakamura: Weather Sky + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ scaleneg~ -----------------------------*/ + +class scaleneg_ar + :public flext_dsp +{ + FLEXT_HEADER(scaleneg_ar,flext_dsp); + +public: + scaleneg_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("scaleneg~",scaleneg_ar); + +scaleneg_ar::scaleneg_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void scaleneg_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_scaleneg( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ scaleneg ------------------------------*/ + +class scaleneg_kr + :public flext_base +{ + FLEXT_HEADER(scaleneg_kr,flext_base); + +public: + scaleneg_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("scaleneg",scaleneg_kr); + +scaleneg_kr::scaleneg_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void scaleneg_kr::m_perform(float f) +{ + ToOutFloat(0,sc_scaleneg(f,b)); +} + +void scaleneg_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/sqrdif.cpp b/sc4pd/source/sqrdif.cpp new file mode 100644 index 0000000..617f987 --- /dev/null +++ b/sc4pd/source/sqrdif.cpp @@ -0,0 +1,137 @@ +/* sc4pd + sqrdif, sqrdif~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_sqrdif (float a, float b) +{ + float f=a-b; + return f*f; +} + + +/* ------------------------ sqrdif~ -----------------------------*/ + +class sqrdif_ar + :public flext_dsp +{ + FLEXT_HEADER(sqrdif_ar,flext_dsp); + +public: + sqrdif_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("sqrdif~",sqrdif_ar); + +sqrdif_ar::sqrdif_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void sqrdif_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_sqrdif( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ sqrdif ------------------------------*/ + +class sqrdif_kr + :public flext_base +{ + FLEXT_HEADER(sqrdif_kr,flext_base); + +public: + sqrdif_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("sqrdif",sqrdif_kr); + +sqrdif_kr::sqrdif_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void sqrdif_kr::m_perform(float f) +{ + ToOutFloat(0,sc_sqrdif(f,b)); +} + +void sqrdif_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/sqrdif.cpp~ b/sc4pd/source/sqrdif.cpp~ new file mode 100644 index 0000000..7e5d431 --- /dev/null +++ b/sc4pd/source/sqrdif.cpp~ @@ -0,0 +1,136 @@ +/* sc4pd + sqrdif, sqrdif~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_sqrdif (float a, float b) +{ + return a*a+b*b; +} + + +/* ------------------------ sqrdif~ -----------------------------*/ + +class sqrdif_ar + :public flext_dsp +{ + FLEXT_HEADER(sqrdif_ar,flext_dsp); + +public: + sqrdif_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("sqrdif~",sqrdif_ar); + +sqrdif_ar::sqrdif_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void sqrdif_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_sqrdif( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ sqrdif ------------------------------*/ + +class sqrdif_kr + :public flext_base +{ + FLEXT_HEADER(sqrdif_kr,flext_base); + +public: + sqrdif_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("sqrdif",sqrdif_kr); + +sqrdif_kr::sqrdif_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void sqrdif_kr::m_perform(float f) +{ + ToOutFloat(0,sc_sqrdif(f,b)); +} + +void sqrdif_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/sqrsum.cpp b/sc4pd/source/sqrsum.cpp new file mode 100644 index 0000000..8a39b68 --- /dev/null +++ b/sc4pd/source/sqrsum.cpp @@ -0,0 +1,137 @@ +/* sc4pd + sqrsum, sqrsum~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_sqrsum (float a, float b) +{ + float f=a+b; + return f*f; +} + + +/* ------------------------ sqrsum~ -----------------------------*/ + +class sqrsum_ar + :public flext_dsp +{ + FLEXT_HEADER(sqrsum_ar,flext_dsp); + +public: + sqrsum_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("sqrsum~",sqrsum_ar); + +sqrsum_ar::sqrsum_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void sqrsum_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_sqrsum( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ sqrsum ------------------------------*/ + +class sqrsum_kr + :public flext_base +{ + FLEXT_HEADER(sqrsum_kr,flext_base); + +public: + sqrsum_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("sqrsum",sqrsum_kr); + +sqrsum_kr::sqrsum_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void sqrsum_kr::m_perform(float f) +{ + ToOutFloat(0,sc_sqrsum(f,b)); +} + +void sqrsum_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/sqrsum.cpp~ b/sc4pd/source/sqrsum.cpp~ new file mode 100644 index 0000000..617f987 --- /dev/null +++ b/sc4pd/source/sqrsum.cpp~ @@ -0,0 +1,137 @@ +/* sc4pd + sqrdif, sqrdif~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_sqrdif (float a, float b) +{ + float f=a-b; + return f*f; +} + + +/* ------------------------ sqrdif~ -----------------------------*/ + +class sqrdif_ar + :public flext_dsp +{ + FLEXT_HEADER(sqrdif_ar,flext_dsp); + +public: + sqrdif_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("sqrdif~",sqrdif_ar); + +sqrdif_ar::sqrdif_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void sqrdif_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_sqrdif( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ sqrdif ------------------------------*/ + +class sqrdif_kr + :public flext_base +{ + FLEXT_HEADER(sqrdif_kr,flext_base); + +public: + sqrdif_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("sqrdif",sqrdif_kr); + +sqrdif_kr::sqrdif_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void sqrdif_kr::m_perform(float f) +{ + ToOutFloat(0,sc_sqrdif(f,b)); +} + +void sqrdif_kr::m_set(float f) +{ + b=f; +} diff --git a/sc4pd/source/sumsqr.cpp b/sc4pd/source/sumsqr.cpp new file mode 100644 index 0000000..5eb5726 --- /dev/null +++ b/sc4pd/source/sumsqr.cpp @@ -0,0 +1,136 @@ +/* sc4pd + sumsqr, sumsqr~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Evan Parker & Keith Rowe: Dark Rags + +*/ + +#include +#include "SC_PlugIn.h" + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +inline float sc_sumsqr (float a, float b) +{ + return a*a+b*b; +} + + +/* ------------------------ sumsqr~ -----------------------------*/ + +class sumsqr_ar + :public flext_dsp +{ + FLEXT_HEADER(sumsqr_ar,flext_dsp); + +public: + sumsqr_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + +}; + +FLEXT_LIB_DSP_V("sumsqr~",sumsqr_ar); + +sumsqr_ar::sumsqr_ar(int argc,t_atom * argv) +{ + AddInSignal(); + AddInSignal(); + AddOutSignal(); +} + +void sumsqr_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin1 = *in; + t_sample *nin2 = *(in+1); + + for (int i = 0; i!= n;++i) + { + if( *nin2 > 0) + (*(nout)++) = sc_sumsqr( (*(nin1)++), (*(nin2)++) ); + } +} + + + +/* ------------------------ sumsqr ------------------------------*/ + +class sumsqr_kr + :public flext_base +{ + FLEXT_HEADER(sumsqr_kr,flext_base); + +public: + sumsqr_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + void m_set(float f); + +private: + float b; + FLEXT_CALLBACK_F(m_perform); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_V("sumsqr",sumsqr_kr); + +sumsqr_kr::sumsqr_kr(int argc,t_atom * argv) + :b(0) +{ + + AddInFloat(); + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD(1,m_set); +} + +void sumsqr_kr::m_perform(float f) +{ + ToOutFloat(0,sc_sumsqr(f,b)); +} + +void sumsqr_kr::m_set(float f) +{ + b=f; +} -- cgit v1.2.1 From 5a6affc4fcaaa5dbac6f29c6638084c77146c8f5 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 30 Jul 2004 21:35:05 +0000 Subject: oops ... removed temporary files svn path=/trunk/externals/tb/; revision=1900 --- sc4pd/source/ring1.cpp~ | 130 -------------------------------------------- sc4pd/source/ring2.cpp~ | 136 ---------------------------------------------- sc4pd/source/ring3.cpp~ | 136 ---------------------------------------------- sc4pd/source/ring4.cpp~ | 136 ---------------------------------------------- sc4pd/source/sqrdif.cpp~ | 136 ---------------------------------------------- sc4pd/source/sqrsum.cpp~ | 137 ----------------------------------------------- 6 files changed, 811 deletions(-) delete mode 100644 sc4pd/source/ring1.cpp~ delete mode 100644 sc4pd/source/ring2.cpp~ delete mode 100644 sc4pd/source/ring3.cpp~ delete mode 100644 sc4pd/source/ring4.cpp~ delete mode 100644 sc4pd/source/sqrdif.cpp~ delete mode 100644 sc4pd/source/sqrsum.cpp~ diff --git a/sc4pd/source/ring1.cpp~ b/sc4pd/source/ring1.cpp~ deleted file mode 100644 index 00f8666..0000000 --- a/sc4pd/source/ring1.cpp~ +++ /dev/null @@ -1,130 +0,0 @@ -/* sc4pd - excess, excess~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Keith Rowe & Toshimaru Nakamura: Weather Sky - -*/ - -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - -/* ------------------------ excess~ -----------------------------*/ - -class excess_ar - :public flext_dsp -{ - FLEXT_HEADER(excess_ar,flext_dsp); - -public: - excess_ar(int argc,t_atom * argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - -private: - -}; - -FLEXT_LIB_DSP_V("excess~",excess_ar); - -excess_ar::excess_ar(int argc,t_atom * argv) -{ - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -void excess_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nout = *out; - t_sample *nin1 = *in; - t_sample *nin2 = *(in+1); - - for (int i = 0; i!= n;++i) - { - if( *nin2 > 0) - (*(nout)++) = sc_excess( (*(nin1)++), (*(nin2)++) ); - } -} - - - -/* ------------------------ excess ------------------------------*/ - -class excess_kr - :public flext_base -{ - FLEXT_HEADER(excess_kr,flext_base); - -public: - excess_kr(int argc,t_atom * argv); - -protected: - void m_perform(float f); - void m_set(float f); - -private: - float b; - FLEXT_CALLBACK_F(m_perform); - FLEXT_CALLBACK_F(m_set); -}; - -FLEXT_LIB_V("excess",excess_kr); - -excess_kr::excess_kr(int argc,t_atom * argv) - :b(0) -{ - - AddInFloat(); - AddInFloat(); - AddOutFloat(); - - FLEXT_ADDMETHOD(0,m_perform); - FLEXT_ADDMETHOD(1,m_set); -} - -void excess_kr::m_perform(float f) -{ - ToOutFloat(0,sc_excess(f,b)); -} - -void excess_kr::m_set(float f) -{ - b=f; -} diff --git a/sc4pd/source/ring2.cpp~ b/sc4pd/source/ring2.cpp~ deleted file mode 100644 index b9aee15..0000000 --- a/sc4pd/source/ring2.cpp~ +++ /dev/null @@ -1,136 +0,0 @@ -/* sc4pd - ring1, ring1~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Evan Parker & Keith Rowe: Dark Rags - -*/ - -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - -inline float sc_ring1 (float a, float b) -{ - return a*b+a; -} - - -/* ------------------------ ring1~ -----------------------------*/ - -class ring1_ar - :public flext_dsp -{ - FLEXT_HEADER(ring1_ar,flext_dsp); - -public: - ring1_ar(int argc,t_atom * argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - -private: - -}; - -FLEXT_LIB_DSP_V("ring1~",ring1_ar); - -ring1_ar::ring1_ar(int argc,t_atom * argv) -{ - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -void ring1_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nout = *out; - t_sample *nin1 = *in; - t_sample *nin2 = *(in+1); - - for (int i = 0; i!= n;++i) - { - if( *nin2 > 0) - (*(nout)++) = sc_ring1( (*(nin1)++), (*(nin2)++) ); - } -} - - - -/* ------------------------ ring1 ------------------------------*/ - -class ring1_kr - :public flext_base -{ - FLEXT_HEADER(ring1_kr,flext_base); - -public: - ring1_kr(int argc,t_atom * argv); - -protected: - void m_perform(float f); - void m_set(float f); - -private: - float b; - FLEXT_CALLBACK_F(m_perform); - FLEXT_CALLBACK_F(m_set); -}; - -FLEXT_LIB_V("ring1",ring1_kr); - -ring1_kr::ring1_kr(int argc,t_atom * argv) - :b(0) -{ - - AddInFloat(); - AddInFloat(); - AddOutFloat(); - - FLEXT_ADDMETHOD(0,m_perform); - FLEXT_ADDMETHOD(1,m_set); -} - -void ring1_kr::m_perform(float f) -{ - ToOutFloat(0,sc_ring1(f,b)); -} - -void ring1_kr::m_set(float f) -{ - b=f; -} diff --git a/sc4pd/source/ring3.cpp~ b/sc4pd/source/ring3.cpp~ deleted file mode 100644 index 02e9a18..0000000 --- a/sc4pd/source/ring3.cpp~ +++ /dev/null @@ -1,136 +0,0 @@ -/* sc4pd - ring2, ring2~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Evan Parker & Keith Rowe: Dark Rags - -*/ - -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - -inline float sc_ring2 (float a, float b) -{ - return a*b+a+b; -} - - -/* ------------------------ ring2~ -----------------------------*/ - -class ring2_ar - :public flext_dsp -{ - FLEXT_HEADER(ring2_ar,flext_dsp); - -public: - ring2_ar(int argc,t_atom * argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - -private: - -}; - -FLEXT_LIB_DSP_V("ring2~",ring2_ar); - -ring2_ar::ring2_ar(int argc,t_atom * argv) -{ - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -void ring2_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nout = *out; - t_sample *nin1 = *in; - t_sample *nin2 = *(in+1); - - for (int i = 0; i!= n;++i) - { - if( *nin2 > 0) - (*(nout)++) = sc_ring2( (*(nin1)++), (*(nin2)++) ); - } -} - - - -/* ------------------------ ring2 ------------------------------*/ - -class ring2_kr - :public flext_base -{ - FLEXT_HEADER(ring2_kr,flext_base); - -public: - ring2_kr(int argc,t_atom * argv); - -protected: - void m_perform(float f); - void m_set(float f); - -private: - float b; - FLEXT_CALLBACK_F(m_perform); - FLEXT_CALLBACK_F(m_set); -}; - -FLEXT_LIB_V("ring2",ring2_kr); - -ring2_kr::ring2_kr(int argc,t_atom * argv) - :b(0) -{ - - AddInFloat(); - AddInFloat(); - AddOutFloat(); - - FLEXT_ADDMETHOD(0,m_perform); - FLEXT_ADDMETHOD(1,m_set); -} - -void ring2_kr::m_perform(float f) -{ - ToOutFloat(0,sc_ring2(f,b)); -} - -void ring2_kr::m_set(float f) -{ - b=f; -} diff --git a/sc4pd/source/ring4.cpp~ b/sc4pd/source/ring4.cpp~ deleted file mode 100644 index 1887066..0000000 --- a/sc4pd/source/ring4.cpp~ +++ /dev/null @@ -1,136 +0,0 @@ -/* sc4pd - ring3, ring3~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Evan Parker & Keith Rowe: Dark Rags - -*/ - -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - -inline float sc_ring3 (float a, float b) -{ - return a*a*b; -} - - -/* ------------------------ ring3~ -----------------------------*/ - -class ring3_ar - :public flext_dsp -{ - FLEXT_HEADER(ring3_ar,flext_dsp); - -public: - ring3_ar(int argc,t_atom * argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - -private: - -}; - -FLEXT_LIB_DSP_V("ring3~",ring3_ar); - -ring3_ar::ring3_ar(int argc,t_atom * argv) -{ - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -void ring3_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nout = *out; - t_sample *nin1 = *in; - t_sample *nin2 = *(in+1); - - for (int i = 0; i!= n;++i) - { - if( *nin2 > 0) - (*(nout)++) = sc_ring3( (*(nin1)++), (*(nin2)++) ); - } -} - - - -/* ------------------------ ring3 ------------------------------*/ - -class ring3_kr - :public flext_base -{ - FLEXT_HEADER(ring3_kr,flext_base); - -public: - ring3_kr(int argc,t_atom * argv); - -protected: - void m_perform(float f); - void m_set(float f); - -private: - float b; - FLEXT_CALLBACK_F(m_perform); - FLEXT_CALLBACK_F(m_set); -}; - -FLEXT_LIB_V("ring3",ring3_kr); - -ring3_kr::ring3_kr(int argc,t_atom * argv) - :b(0) -{ - - AddInFloat(); - AddInFloat(); - AddOutFloat(); - - FLEXT_ADDMETHOD(0,m_perform); - FLEXT_ADDMETHOD(1,m_set); -} - -void ring3_kr::m_perform(float f) -{ - ToOutFloat(0,sc_ring3(f,b)); -} - -void ring3_kr::m_set(float f) -{ - b=f; -} diff --git a/sc4pd/source/sqrdif.cpp~ b/sc4pd/source/sqrdif.cpp~ deleted file mode 100644 index 7e5d431..0000000 --- a/sc4pd/source/sqrdif.cpp~ +++ /dev/null @@ -1,136 +0,0 @@ -/* sc4pd - sqrdif, sqrdif~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Evan Parker & Keith Rowe: Dark Rags - -*/ - -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - -inline float sc_sqrdif (float a, float b) -{ - return a*a+b*b; -} - - -/* ------------------------ sqrdif~ -----------------------------*/ - -class sqrdif_ar - :public flext_dsp -{ - FLEXT_HEADER(sqrdif_ar,flext_dsp); - -public: - sqrdif_ar(int argc,t_atom * argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - -private: - -}; - -FLEXT_LIB_DSP_V("sqrdif~",sqrdif_ar); - -sqrdif_ar::sqrdif_ar(int argc,t_atom * argv) -{ - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -void sqrdif_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nout = *out; - t_sample *nin1 = *in; - t_sample *nin2 = *(in+1); - - for (int i = 0; i!= n;++i) - { - if( *nin2 > 0) - (*(nout)++) = sc_sqrdif( (*(nin1)++), (*(nin2)++) ); - } -} - - - -/* ------------------------ sqrdif ------------------------------*/ - -class sqrdif_kr - :public flext_base -{ - FLEXT_HEADER(sqrdif_kr,flext_base); - -public: - sqrdif_kr(int argc,t_atom * argv); - -protected: - void m_perform(float f); - void m_set(float f); - -private: - float b; - FLEXT_CALLBACK_F(m_perform); - FLEXT_CALLBACK_F(m_set); -}; - -FLEXT_LIB_V("sqrdif",sqrdif_kr); - -sqrdif_kr::sqrdif_kr(int argc,t_atom * argv) - :b(0) -{ - - AddInFloat(); - AddInFloat(); - AddOutFloat(); - - FLEXT_ADDMETHOD(0,m_perform); - FLEXT_ADDMETHOD(1,m_set); -} - -void sqrdif_kr::m_perform(float f) -{ - ToOutFloat(0,sc_sqrdif(f,b)); -} - -void sqrdif_kr::m_set(float f) -{ - b=f; -} diff --git a/sc4pd/source/sqrsum.cpp~ b/sc4pd/source/sqrsum.cpp~ deleted file mode 100644 index 617f987..0000000 --- a/sc4pd/source/sqrsum.cpp~ +++ /dev/null @@ -1,137 +0,0 @@ -/* sc4pd - sqrdif, sqrdif~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Evan Parker & Keith Rowe: Dark Rags - -*/ - -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - -inline float sc_sqrdif (float a, float b) -{ - float f=a-b; - return f*f; -} - - -/* ------------------------ sqrdif~ -----------------------------*/ - -class sqrdif_ar - :public flext_dsp -{ - FLEXT_HEADER(sqrdif_ar,flext_dsp); - -public: - sqrdif_ar(int argc,t_atom * argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - -private: - -}; - -FLEXT_LIB_DSP_V("sqrdif~",sqrdif_ar); - -sqrdif_ar::sqrdif_ar(int argc,t_atom * argv) -{ - AddInSignal(); - AddInSignal(); - AddOutSignal(); -} - -void sqrdif_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nout = *out; - t_sample *nin1 = *in; - t_sample *nin2 = *(in+1); - - for (int i = 0; i!= n;++i) - { - if( *nin2 > 0) - (*(nout)++) = sc_sqrdif( (*(nin1)++), (*(nin2)++) ); - } -} - - - -/* ------------------------ sqrdif ------------------------------*/ - -class sqrdif_kr - :public flext_base -{ - FLEXT_HEADER(sqrdif_kr,flext_base); - -public: - sqrdif_kr(int argc,t_atom * argv); - -protected: - void m_perform(float f); - void m_set(float f); - -private: - float b; - FLEXT_CALLBACK_F(m_perform); - FLEXT_CALLBACK_F(m_set); -}; - -FLEXT_LIB_V("sqrdif",sqrdif_kr); - -sqrdif_kr::sqrdif_kr(int argc,t_atom * argv) - :b(0) -{ - - AddInFloat(); - AddInFloat(); - AddOutFloat(); - - FLEXT_ADDMETHOD(0,m_perform); - FLEXT_ADDMETHOD(1,m_set); -} - -void sqrdif_kr::m_perform(float f) -{ - ToOutFloat(0,sc_sqrdif(f,b)); -} - -void sqrdif_kr::m_set(float f) -{ - b=f; -} -- cgit v1.2.1 From 732d85194f69cc1d6b72d67e48211799cd5583e3 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 1 Aug 2004 19:00:30 +0000 Subject: checkin: lfpulse, lfsaw svn path=/trunk/externals/tb/; revision=1901 --- sc4pd/make-files.txt | 3 +- sc4pd/pd/lfpulse.pd | 42 +++++++ sc4pd/pd/lfsaw.pd | 29 +++++ sc4pd/source/LFPulse.cpp | 299 +++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/LFSaw.cpp | 263 +++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 13 ++- sc4pd/source/support.hpp | 29 +++++ 7 files changed, 673 insertions(+), 5 deletions(-) create mode 100644 sc4pd/pd/lfpulse.pd create mode 100644 sc4pd/pd/lfsaw.pd create mode 100644 sc4pd/source/LFPulse.cpp create mode 100644 sc4pd/source/LFSaw.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index c5a874b..8c45378 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -8,4 +8,5 @@ SRCS= \ ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ - difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp \ No newline at end of file + difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ + LFPulse.cpp \ No newline at end of file diff --git a/sc4pd/pd/lfpulse.pd b/sc4pd/pd/lfpulse.pd new file mode 100644 index 0000000..f8cdec5 --- /dev/null +++ b/sc4pd/pd/lfpulse.pd @@ -0,0 +1,42 @@ +#N canvas 0 0 782 300 10; +#X obj 93 170 dac~; +#X obj 108 75 sig~ 440; +#X floatatom 227 53 5 0 0 0 - - -; +#X msg 20 31 kr; +#X msg 62 30 ar; +#X floatatom 363 150 5 0 0 0 - - -; +#X obj 343 235 timer; +#X floatatom 343 267 5 0 0 0 - - -; +#X obj 353 197 t b b; +#X msg 402 29 0.1; +#X msg 451 39 kr 10; +#X msg 223 88 freq \$1; +#X obj 107 117 LFPulse~ 440 0.3 ar; +#X msg 162 48 width \$1; +#X floatatom 162 20 5 0 0 0 - - -; +#X obj 373 128 change; +#X obj 376 89 LFPulse 1 0.5 20; +#X msg 162 48 width \$1; +#X floatatom 162 20 5 0 0 0 - - -; +#X msg 598 46 width \$1; +#X floatatom 598 18 5 0 0 0 - - -; +#X connect 1 0 12 0; +#X connect 2 0 11 0; +#X connect 3 0 12 0; +#X connect 4 0 12 0; +#X connect 5 0 8 0; +#X connect 6 0 7 0; +#X connect 8 0 6 0; +#X connect 8 1 6 1; +#X connect 9 0 16 0; +#X connect 10 0 16 0; +#X connect 11 0 12 0; +#X connect 12 0 0 0; +#X connect 12 0 0 1; +#X connect 13 0 12 0; +#X connect 14 0 13 0; +#X connect 15 0 5 0; +#X connect 16 0 15 0; +#X connect 18 0 17 0; +#X connect 19 0 16 0; +#X connect 20 0 19 0; diff --git a/sc4pd/pd/lfsaw.pd b/sc4pd/pd/lfsaw.pd new file mode 100644 index 0000000..ed3f7b3 --- /dev/null +++ b/sc4pd/pd/lfsaw.pd @@ -0,0 +1,29 @@ +#N canvas 0 0 782 300 10; +#X obj 93 170 dac~; +#X obj 107 117 LFSaw~ 440 ar; +#X obj 108 75 sig~ 440; +#X floatatom 227 53 5 0 0 0 - - -; +#X msg 20 31 kr; +#X msg 62 30 ar; +#X floatatom 349 176 5 0 0 0 - - -; +#X obj 343 235 timer; +#X floatatom 343 267 5 0 0 0 - - -; +#X obj 353 197 t b b; +#X obj 376 89 LFSaw 2 50; +#X msg 402 29 0.1; +#X msg 451 39 kr 10; +#X msg 223 88 freq \$1; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 2 0 1 0; +#X connect 3 0 13 0; +#X connect 4 0 1 0; +#X connect 5 0 1 0; +#X connect 6 0 9 0; +#X connect 7 0 8 0; +#X connect 9 0 7 0; +#X connect 9 1 7 1; +#X connect 10 0 6 0; +#X connect 11 0 10 0; +#X connect 12 0 10 0; +#X connect 13 0 1 0; diff --git a/sc4pd/source/LFPulse.cpp b/sc4pd/source/LFPulse.cpp new file mode 100644 index 0000000..76abc2c --- /dev/null +++ b/sc4pd/source/LFPulse.cpp @@ -0,0 +1,299 @@ +/* sc4pd + LFPulse, LFPulse~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Oren Ambarchi: Flypaper + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LFPulse~ -------------------------------*/ + +class LFPulse_ar: + public flext_dsp +{ + FLEXT_HEADER(LFPulse_ar,flext_dsp); + +public: + LFPulse_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_freq=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + + void m_width (float f) + { + nextDuty = f; + } + + +private: + double mPhase; + float mFreqMul; + float m_freq; //for kr arguments + float mDuty; + float nextDuty; + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_width); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("LFPulse~",LFPulse_ar); + +LFPulse_ar::LFPulse_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"freq",m_set); + FLEXT_ADDMETHOD_(0,"width",m_width); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + nextDuty = sc_getfloatarg(Args,1); + + if(sc_ar(Args)) + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); +} + +void LFPulse_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + mFreqMul = 1 / Samplerate(); + +} + +void LFPulse_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *freq = *in; + t_sample *xout = *out; + + float freqmul = mFreqMul; + double phase = mPhase; + float duty = mDuty; + + for (int i = 0; i!= n;++i) + { + float z; + if (phase >= 1.f) + { + phase -= 1.f; + duty = mDuty = nextDuty; + // output at least one sample from the opposite polarity + z = duty < 0.5 ? 1.f : 0.f; + } + else + { + z = phase < duty ? 1.f : 0.f; + } + + phase += (*(freq)++) * freqmul; + (*(xout)++) = z; + } + + mPhase=phase; +} + + +void LFPulse_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *xout = *out; + + double phase = mPhase; + float duty = mDuty; + float freq = m_freq * mFreqMul; + + for (int i = 0; i!= n;++i) + { + float z; + if (phase >= 1.f) + { + phase -= 1.f; + duty = mDuty = nextDuty; + // output at least one sample from the opposite polarity + z = duty < 0.5 ? 1.f : 0.f; + } + else + { + z = phase < duty ? 1.f : 0.f; + } + + phase += freq; + (*(xout)++) = z; + } + mPhase=phase; +} + +/* ------------------------ LFPulse ---------------------------------*/ + +/* todo: remove obsolete messages */ + +class LFPulse_kr: + public flext_base +{ + FLEXT_HEADER(LFPulse_kr,flext_base); + +public: + LFPulse_kr(int argc, t_atom *argv); + +protected: + void m_perform(void*); + + void m_set(float f) + { + m_freq_set = f; + m_freq = f * mFreqMul; + } + + void m_set_kr(float f) + { + if (f != 0) + { + dt = f * 0.001; + mFreqMul = dt; + m_freq = m_freq_set * mFreqMul; + m_timer.Reset(); + m_timer.Periodic(dt); + } + } + + void m_set_width(float f) + { + nextDuty=f; + } + +private: + double mPhase; + float mFreqMul; + float mDuty; + float nextDuty; + float m_freq; + float dt; + float m_freq_set; + + Timer m_timer; + + FLEXT_CALLBACK_F(m_set_kr); + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_set_width); + FLEXT_CALLBACK_T(m_perform); +}; + + +FLEXT_LIB_V("LFPulse",LFPulse_kr); + +LFPulse_kr::LFPulse_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_set); + FLEXT_ADDMETHOD_(0,"kr",m_set_kr); + FLEXT_ADDMETHOD_(0,"width",m_set_width); + + FLEXT_ADDTIMER(m_timer,m_perform); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + m_freq_set = sc_getfloatarg(Args,0); + + nextDuty = sc_getfloatarg(Args,1); + + dt = sc_getfloatarg(Args,2) * 0.001; + + if (dt == 0) + dt = 0.02; // 20 ms as default control rate as in line + mFreqMul = dt; + + m_freq = m_freq_set * mFreqMul; + + m_timer.Periodic(dt); + +} + +void LFPulse_kr::m_perform(void*) +{ + float z; + if (mPhase >= 1.f) + { + mPhase -= 1.f; + mDuty = nextDuty; + // output at least one sample from the opposite polarity + z = mDuty < 0.5 ? 1.f : 0.f; + } + else + { + z = mPhase < mDuty ? 1.f : 0.f; + } + mPhase += m_freq; + ToOutFloat(0,z); +} diff --git a/sc4pd/source/LFSaw.cpp b/sc4pd/source/LFSaw.cpp new file mode 100644 index 0000000..358cb2f --- /dev/null +++ b/sc4pd/source/LFSaw.cpp @@ -0,0 +1,263 @@ +/* sc4pd + LFSaw, LFSaw~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & Oren Ambarchi: Flypaper + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + + +/* ------------------------ LFSaw~ -------------------------------*/ + +class LFSaw_ar: + public flext_dsp +{ + FLEXT_HEADER(LFSaw_ar,flext_dsp); + +public: + LFSaw_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_freq=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + double mPhase; + float mFreqMul; + float m_freq; //for kr arguments + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("LFSaw~",LFSaw_ar); + +LFSaw_ar::LFSaw_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"freq",m_set); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + if(sc_ar(Args)) + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); +} + +void LFSaw_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + mFreqMul = 2 / Samplerate(); +} + +void LFSaw_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *freq = *in; + t_sample *xout = *out; + + float freqmul = mFreqMul; + double phase = mPhase; + + for (int i = 0; i!= n;++i) + { + float z = phase; // out must be written last for in place operation + phase += (*(freq)++) * freqmul; + if (phase >= 1.f) + phase -= 2.f; + else + if (phase <= -1.f) + phase += 2.f; + (*(xout)++) = z; + } + + mPhase=phase; +} + + +void LFSaw_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *xout = *out; + + float freq = m_freq * mFreqMul; + double phase = mPhase; + + if (freq >= 0.f) + { + for (int i = 0; i!= n;++i) + { + (*(xout)++) = phase; + phase += freq; + if (phase >= 1.f) phase -= 2.f; + } + } + else + { + for (int i = 0; i!= n;++i) + { + (*(xout)++) = phase; + phase += freq; + if (phase <= -1.f) phase += 2.f; + } + } + + mPhase=phase; +} + +/* ------------------------ LFSaw ---------------------------------*/ + +class LFSaw_kr: + public flext_base +{ + FLEXT_HEADER(LFSaw_kr,flext_base); + +public: + LFSaw_kr(int argc, t_atom *argv); + +protected: + void m_perform(void*); + + void m_set(float f) + { + m_freq_set = f; + m_freq = f * mFreqMul; + } + + void m_set_kr(float f) + { + if (f != 0) + { + dt = f * 0.001; + mFreqMul = 2*dt; + m_freq = m_freq_set * mFreqMul; + m_timer.Reset(); + m_timer.Periodic(dt); + } + } + +private: + double mPhase; + float mFreqMul; + float m_freq; + float dt; + float m_freq_set; + + Timer m_timer; + + FLEXT_CALLBACK_F(m_set_kr); + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_T(m_perform); +}; + + +FLEXT_LIB_V("LFSaw",LFSaw_kr); + +LFSaw_kr::LFSaw_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_set); + FLEXT_ADDMETHOD_(0,"kr",m_set_kr); + // FLEXT_ADDBANG(0,m_perform); + FLEXT_ADDTIMER(m_timer,m_perform); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + m_freq_set = sc_getfloatarg(Args,0); + + dt = sc_getfloatarg(Args,1) * 0.001; + + if (dt == 0 ) + dt = 0.02; // 20 ms as default control rate as in line + mFreqMul = 2 * dt; /* test this !!! */ + + m_freq = m_freq_set * mFreqMul; + + m_timer.Periodic(dt); + +} + +void LFSaw_kr::m_perform(void*) +{ + if (m_freq >= 0.f) + { + ToOutFloat(0,mPhase); + mPhase += m_freq; + if (mPhase >= 1.f) mPhase -= 2.f; + } + else + { + ToOutFloat(0,mPhase); + mPhase += m_freq; + if (mPhase <= -1.f) mPhase += 2.f; + } +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index df430f9..7b16ccb 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -32,7 +32,6 @@ http://www.audiosynth.com Coded while listening to: Phosphor - */ #include @@ -61,9 +60,9 @@ void sc4pd_library_setup() "Latoocarfian(~),\n" " LinCong(~), amclip(~), scaleneg(~), excess(~), hypot(~), " "ring1(~),\n" - " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~)\n" - "sqrdif(~), sqrsum(~),\n" - " absdif(~)"); + " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " + "sqrdif(~),\n" + " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~)"); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -184,6 +183,12 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(absdif_ar); FLEXT_SETUP(absdif_kr); + + FLEXT_DSP_SETUP(LFSaw_ar); + FLEXT_SETUP(LFSaw_kr); + + FLEXT_DSP_SETUP(LFPulse_ar); + FLEXT_SETUP(LFPulse_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index 79faff5..d05497e 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -64,3 +64,32 @@ bool sc_ar(flext::AtomList a); rgen.s3 = s3; int32 timeseed(); + + +/* this is copied from thomas grill's xsample: +xsample - extended sample objects for Max/MSP and pd (pure data) + +Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net) +For information on usage and redistribution, and for a DISCLAIMER OF ALL +WARRANTIES, see the file, "license.txt," in this distribution. +*/ + +#define F float +#define D double +#define I int +#define L long +#define C char +#define V void +#define BL bool +#define S t_sample + +#define SETSIGFUN(VAR,FUN) v_##VAR = FUN + +#define DEFSIGFUN(NAME) V NAME(I n,S *const *in,S *const *out) + +#define DEFSIGCALL(NAME) \ + inline V NAME(I n,S *const *in,S *const *out) \ + { (this->*v_##NAME)(n,in,out); } \ + V (thisType::*v_##NAME)(I n,S *const *invecs,S *const *outvecs) + +#define SIGFUN(FUN) &thisType::FUN -- cgit v1.2.1 From 0d2a4d810fdc7ecbe67de784d4eb901cd5699c38 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 1 Aug 2004 20:51:11 +0000 Subject: some more ugens svn path=/trunk/externals/tb/; revision=1902 --- sc4pd/gpl.txt | 346 ++++++++++++++++++++++++++++++++++++++++++++ sc4pd/make-files.txt | 2 +- sc4pd/pd/impulse.pd | 31 ++++ sc4pd/pd/integrator.pd | 21 +++ sc4pd/pd/mantissamask.pd | 18 +-- sc4pd/source/Decay.cpp | 218 ++++++++++++++++++++++++++++ sc4pd/source/Impulse.cpp | 271 ++++++++++++++++++++++++++++++++++ sc4pd/source/Integrator.cpp | 206 ++++++++++++++++++++++++++ sc4pd/source/main.cpp | 12 +- sc4pd/source/support.hpp | 8 + 10 files changed, 1122 insertions(+), 11 deletions(-) create mode 100644 sc4pd/gpl.txt create mode 100644 sc4pd/pd/impulse.pd create mode 100644 sc4pd/pd/integrator.pd create mode 100644 sc4pd/source/Decay.cpp create mode 100644 sc4pd/source/Impulse.cpp create mode 100644 sc4pd/source/Integrator.cpp diff --git a/sc4pd/gpl.txt b/sc4pd/gpl.txt new file mode 100644 index 0000000..5ea29a7 --- /dev/null +++ b/sc4pd/gpl.txt @@ -0,0 +1,346 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 8c45378..49ba19b 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -9,4 +9,4 @@ SRCS= \ Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ - LFPulse.cpp \ No newline at end of file + LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp \ No newline at end of file diff --git a/sc4pd/pd/impulse.pd b/sc4pd/pd/impulse.pd new file mode 100644 index 0000000..5381863 --- /dev/null +++ b/sc4pd/pd/impulse.pd @@ -0,0 +1,31 @@ +#N canvas 0 0 782 300 10; +#X obj 93 170 dac~; +#X obj 108 75 sig~ 440; +#X floatatom 227 53 5 0 0 0 - - -; +#X msg 20 31 kr; +#X msg 62 30 ar; +#X floatatom 363 150 5 0 0 0 - - -; +#X obj 343 235 timer; +#X floatatom 343 267 5 0 0 0 - - -; +#X obj 353 197 t b b; +#X msg 402 29 0.1; +#X msg 451 39 kr 10; +#X msg 223 88 freq \$1; +#X obj 373 128 change; +#X obj 107 117 Impulse~ 440 ar; +#X obj 376 89 Impulse 1 20; +#X connect 1 0 13 0; +#X connect 2 0 11 0; +#X connect 3 0 13 0; +#X connect 4 0 13 0; +#X connect 5 0 8 0; +#X connect 6 0 7 0; +#X connect 8 0 6 0; +#X connect 8 1 6 1; +#X connect 9 0 14 0; +#X connect 10 0 14 0; +#X connect 11 0 13 0; +#X connect 12 0 5 0; +#X connect 13 0 0 0; +#X connect 13 0 0 1; +#X connect 14 0 12 0; diff --git a/sc4pd/pd/integrator.pd b/sc4pd/pd/integrator.pd new file mode 100644 index 0000000..3c8719d --- /dev/null +++ b/sc4pd/pd/integrator.pd @@ -0,0 +1,21 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 112 20 5 0 0 0 - - -; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 86 Integrator~ 0.3; +#X msg 89 60 leak \$1; +#X obj 18 28 Dust~ 441; +#X obj 266 78 Integrator 0.5; +#X connect 2 0 1 0; +#X connect 3 0 7 0; +#X connect 4 0 9 0; +#X connect 6 0 1 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; +#X connect 7 0 6 0; +#X connect 8 0 6 0; +#X connect 9 0 5 0; diff --git a/sc4pd/pd/mantissamask.pd b/sc4pd/pd/mantissamask.pd index 5e2d3ed..b99ca00 100644 --- a/sc4pd/pd/mantissamask.pd +++ b/sc4pd/pd/mantissamask.pd @@ -4,18 +4,18 @@ #X obj 89 131 print~; #X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X obj 18 86 MantissaMask~ 3; #X floatatom 112 20 5 0 0 0 - - -; -#X msg 89 60 set \$1; #X floatatom 265 37 9 0 0 0 - - -; #X floatatom 266 110 9 0 0 0 - - -; #X obj 266 78 MantissaMask 0; -#X connect 0 0 4 0; +#X obj 18 86 MantissaMask~ 3; +#X msg 89 60 set \$1; +#X connect 0 0 8 0; #X connect 3 0 2 0; -#X connect 4 0 2 0; -#X connect 4 0 1 0; -#X connect 4 0 1 1; -#X connect 5 0 6 0; -#X connect 6 0 4 0; -#X connect 7 0 9 0; +#X connect 4 0 9 0; +#X connect 5 0 7 0; +#X connect 7 0 6 0; +#X connect 8 0 2 0; +#X connect 8 0 1 0; +#X connect 8 0 1 1; #X connect 9 0 8 0; diff --git a/sc4pd/source/Decay.cpp b/sc4pd/source/Decay.cpp new file mode 100644 index 0000000..95bc22e --- /dev/null +++ b/sc4pd/source/Decay.cpp @@ -0,0 +1,218 @@ +/* sc4pd + Decay~, Decay + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: AMM: AMMMusic 1966 + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Decay~ -----------------------------*/ + +class Decay_ar + :public flext_dsp +{ + FLEXT_HEADER(Decay_ar,flext_dsp); + +public: + Decay_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1; //leak + float m_y1; //z-1 + float decayTime; +}; + +FLEXT_LIB_DSP_V("Decay~",Decay_ar); + +Decay_ar::Decay_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"decayTime",m_set); + + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_y1 = 0.f; +} + +void Decay_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float b1 = m_b1; + float y1 = m_y1; + + if (b1 == m_b1) + { + if (b1 == 1.f) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + y1; + } + + } + else if (b1 == 0.f) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + b1 * y1; + } + } + } + else + { + float b1_slope = CALCSLOPE(m_b1, b1); + if (b1 >= 0.f && m_b1 >= 0) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + b1 * (y1 - y0); + b1 += b1_slope; + } + } + else if (b1 <= 0.f && m_b1 <= 0) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + b1 * (y1 + y0); + b1 += b1_slope; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = (1.f - fabs(b1)) * y0 + b1 * y1; + b1 += b1_slope; + } + } + } + m_y1 = zapgremlins(y1); +} + +void Decay_ar::m_set(float f) +{ + decayTime = f; + m_b1= 0.f ? 0.f : exp(log001 / (decayTime * Samplerate())); +} + +void Decay_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + m_b1= 0.f ? 0.f : exp(log001 / (decayTime * Samplerate())); +} + +/* todo: does it make sense to implement a message-based Decay? + Probably not... */ + + +/* ------------------------ Decay ------------------------------*/ + +// class Decay_kr +// :public flext_base +// { +// FLEXT_HEADER(Decay_kr,flext_base); + +// public: +// Decay_kr(int argc,t_atom * argv); + +// protected: +// void m_set(float f); +// void m_perform(float f); + +// private: +// float m_b1; //leak +// float m_y1; //z-1 + +// FLEXT_CALLBACK_F(m_set); +// FLEXT_CALLBACK_F(m_perform); +// }; + +// FLEXT_LIB_V("Decay",Decay_kr); + +// Decay_kr::Decay_kr(int argc,t_atom * argv) +// { +// AtomList Args(argc,argv); + +// m_b1 = sc_getfloatarg(Args,0); +// m_y1 = 0.f; + + +// AddInFloat(); +// AddOutFloat(); + +// FLEXT_ADDMETHOD(0,m_perform); +// FLEXT_ADDMETHOD_(0,"leak",m_set); +// } + +// void Decay_kr::m_perform(float f) +// { +// m_y1 = f + m_y1 * m_b1; +// ToOutFloat(0,m_y1); +// } + +// void Decay_kr::m_set(float f) +// { +// m_b1=f; +// } diff --git a/sc4pd/source/Impulse.cpp b/sc4pd/source/Impulse.cpp new file mode 100644 index 0000000..277ad34 --- /dev/null +++ b/sc4pd/source/Impulse.cpp @@ -0,0 +1,271 @@ +/* sc4pd + Impulse, Impulse~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: AMM: AMMMusic 1966 + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* todo: implement phase offset as in sc3 +/* ------------------------ Impulse~ -------------------------------*/ + +class Impulse_ar: + public flext_dsp +{ + FLEXT_HEADER(Impulse_ar,flext_dsp); + +public: + Impulse_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_freq=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + double mPhase, mPhaseOffset; + float mFreqMul; + float m_freq; //for kr arguments + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("Impulse~",Impulse_ar); + +Impulse_ar::Impulse_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"freq",m_set); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + if(sc_ar(Args)) + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); +} + +void Impulse_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + mFreqMul = 1 / Samplerate(); + +} + +void Impulse_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *freq = *in; + t_sample *xout = *out; + + float freqmul = mFreqMul; + double phase = mPhase; + + for (int i = 0; i!= n;++i) + { + float z; + if (phase >= 1.f) + { + phase -= 1.f; + z = 1.f; + } + else + { + z = 0.f; + } + phase += (*(freq)++) * freqmul; + (*(xout)++) = z; + } + + mPhase=phase; +} + + +void Impulse_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *xout = *out; + + float freq = m_freq * mFreqMul; + float freqmul = mFreqMul; + double phase = mPhase; + + for (int i = 0; i!= n;++i) + { + float z; + if (phase >= 1.f) + { + phase -= 1.f; + z = 1.f; + } + else + { + z = 0.f; + } + phase += freq; + (*(xout)++) = z; + } + + mPhase=phase; +} + +/* ------------------------ Impulse ---------------------------------*/ + +/* todo: remove obsolete messages */ + +class Impulse_kr: + public flext_base +{ + FLEXT_HEADER(Impulse_kr,flext_base); + +public: + Impulse_kr(int argc, t_atom *argv); + +protected: + void m_perform(void*); + + void m_set(float f) + { + m_freq_set = f; + m_freq = f * mFreqMul; + } + + void m_set_kr(float f) + { + if (f != 0) + { + dt = f * 0.001; + mFreqMul = dt; + m_freq = m_freq_set * mFreqMul; + m_timer.Reset(); + m_timer.Periodic(dt); + } + } + +private: + + double mPhase, mPhaseOffset; + float mFreqMul; + float m_freq; //for kr arguments + + float dt; + float m_freq_set; + + Timer m_timer; + + FLEXT_CALLBACK_F(m_set_kr); + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_T(m_perform); +}; + + +FLEXT_LIB_V("Impulse",Impulse_kr); + +Impulse_kr::Impulse_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_set); + FLEXT_ADDMETHOD_(0,"kr",m_set_kr); + + FLEXT_ADDTIMER(m_timer,m_perform); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + m_freq_set = sc_getfloatarg(Args,0); + + dt = sc_getfloatarg(Args,1) * 0.001; + + if (dt == 0) + dt = 0.02; // 20 ms as default control rate as in line + mFreqMul = dt; + + m_freq = m_freq_set * mFreqMul; + + m_timer.Periodic(dt); + +} + +void Impulse_kr::m_perform(void*) +{ + float z; + if (mPhase >= 1.f) + { + mPhase -= 1.f; + z = 1.f; + } + else + { + z = 0.f; + } + + mPhase += m_freq; + ToOutFloat(0,z); +} diff --git a/sc4pd/source/Integrator.cpp b/sc4pd/source/Integrator.cpp new file mode 100644 index 0000000..75bb350 --- /dev/null +++ b/sc4pd/source/Integrator.cpp @@ -0,0 +1,206 @@ +/* sc4pd + Integrator~, Integrator + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: AMM: AMMMusic 1966 + +*/ + +#include +#include "SC_PlugIn.h" +#include "support.hpp" + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +/* ------------------------ Integrator~ -----------------------------*/ + +class Integrator_ar + :public flext_dsp +{ + FLEXT_HEADER(Integrator_ar,flext_dsp); + +public: + Integrator_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1; //leak + float m_y1; //z-1 +}; + +FLEXT_LIB_DSP_V("Integrator~",Integrator_ar); + +Integrator_ar::Integrator_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"leak",m_set); + + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_y1 = 0.f; +} + +void Integrator_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float b1 = m_b1; + float y1 = m_y1; + + if (b1 == m_b1) + { + if (b1 == 1.f) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + y1; + } + + } + else if (b1 == 0.f) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + b1 * y1; + } + } + } + else + { + float b1_slope = CALCSLOPE(m_b1, b1); + if (b1 >= 0.f && m_b1 >= 0) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + b1 * (y1 - y0); + b1 += b1_slope; + } + } + else if (b1 <= 0.f && m_b1 <= 0) + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = y0 + b1 * (y1 + y0); + b1 += b1_slope; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = (*(nin)++); + (*(nout)++) = y1 = (1.f - fabs(b1)) * y0 + b1 * y1; + b1 += b1_slope; + } + } + } + m_y1 = zapgremlins(y1); +} + +void Integrator_ar::m_set(float f) +{ + m_b1=f; +} + +/* ------------------------ Integrator ------------------------------*/ + +class Integrator_kr + :public flext_base +{ + FLEXT_HEADER(Integrator_kr,flext_base); + +public: + Integrator_kr(int argc,t_atom * argv); + +protected: + void m_set(float f); + void m_perform(float f); + +private: + float m_b1; //leak + float m_y1; //z-1 + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("Integrator",Integrator_kr); + +Integrator_kr::Integrator_kr(int argc,t_atom * argv) +{ + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + m_y1 = 0.f; + + + AddInFloat(); + AddOutFloat(); + + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"leak",m_set); +} + +void Integrator_kr::m_perform(float f) +{ + m_y1 = f + m_y1 * m_b1; + ToOutFloat(0,m_y1); +} + +void Integrator_kr::m_set(float f) +{ + m_b1=f; +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 7b16ccb..bc8af2a 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -62,7 +62,9 @@ void sc4pd_library_setup() "ring1(~),\n" " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " "sqrdif(~),\n" - " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~)"); + " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" + " Integrator(~), Decay~\n" + ); //initialize objects FLEXT_DSP_SETUP(Dust_ar); @@ -189,6 +191,14 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(LFPulse_ar); FLEXT_SETUP(LFPulse_kr); + + FLEXT_DSP_SETUP(Impulse_ar); + FLEXT_SETUP(Impulse_kr); + + FLEXT_DSP_SETUP(Integrator_ar); + FLEXT_SETUP(Integrator_kr); + + FLEXT_DSP_SETUP(Decay_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index d05497e..bb5537a 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -93,3 +93,11 @@ WARRANTIES, see the file, "license.txt," in this distribution. V (thisType::*v_##NAME)(I n,S *const *invecs,S *const *outvecs) #define SIGFUN(FUN) &thisType::FUN + + +/* this macro has to be redefined to work with flext */ + +// calculate a slope for control rate interpolation to audio rate. +//#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor) +#undef CALCSLOPE +#define CALCSLOPE(next,prev) ((next - prev) * 1/Blocksize()) -- cgit v1.2.1 From 5e1268fb9920b248ee377797b130605f669c6dee Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 2 Aug 2004 19:18:22 +0000 Subject: main header file svn path=/trunk/externals/tb/; revision=1903 --- sc4pd/source/BrownNoise.cpp | 10 +--------- sc4pd/source/ClipNoise.cpp | 9 +-------- sc4pd/source/CoinGate.cpp | 10 +--------- sc4pd/source/Crackle.cpp | 10 +--------- sc4pd/source/Decay.cpp | 9 +-------- sc4pd/source/Dust.cpp | 8 +------- sc4pd/source/Dust2.cpp | 8 +------- sc4pd/source/ExpRand.cpp | 10 +--------- sc4pd/source/GrayNoise.cpp | 10 +--------- sc4pd/source/Hasher.cpp | 7 ------- sc4pd/source/IRand.cpp | 10 +--------- sc4pd/source/Impulse.cpp | 9 +-------- sc4pd/source/Integrator.cpp | 9 +-------- sc4pd/source/LFClipNoise.cpp | 9 +-------- sc4pd/source/LFNoise0.cpp | 9 +-------- sc4pd/source/LFNoise1.cpp | 9 +-------- sc4pd/source/LFNoise2.cpp | 9 +-------- sc4pd/source/LFPulse.cpp | 9 +-------- sc4pd/source/LFSaw.cpp | 9 +-------- sc4pd/source/Latoocarfian.cpp | 9 +-------- sc4pd/source/LinCong.cpp | 9 +-------- sc4pd/source/LinRand.cpp | 9 +-------- sc4pd/source/Logistic.cpp | 9 +-------- sc4pd/source/MantissaMask.cpp | 7 ------- sc4pd/source/Median.cpp | 9 +-------- sc4pd/source/NRand.cpp | 9 +-------- sc4pd/source/PinkNoise.cpp | 10 +--------- sc4pd/source/Rand.cpp | 9 +-------- sc4pd/source/TExpRand.cpp | 9 +-------- sc4pd/source/TIRand.cpp | 9 +-------- sc4pd/source/TRand.cpp | 9 +-------- sc4pd/source/WhiteNoise.cpp | 9 +-------- sc4pd/source/absdif.cpp | 7 +------ sc4pd/source/amclip.cpp | 7 +------ sc4pd/source/difsqr.cpp | 7 +------ sc4pd/source/excess.cpp | 8 +------- sc4pd/source/hypot.cpp | 7 +------ sc4pd/source/main.cpp | 7 +------ sc4pd/source/ring2.cpp | 8 +------- sc4pd/source/ring3.cpp | 8 +------- sc4pd/source/ring4.cpp | 7 +------ sc4pd/source/scaleneg.cpp | 7 +------ sc4pd/source/sqrdif.cpp | 7 +------ sc4pd/source/sqrsum.cpp | 7 +------ sc4pd/source/sumsqr.cpp | 7 +------ sc4pd/source/support.cpp | 8 ++------ sc4pd/source/support.hpp | 6 ------ 47 files changed, 45 insertions(+), 352 deletions(-) diff --git a/sc4pd/source/BrownNoise.cpp b/sc4pd/source/BrownNoise.cpp index b9bc138..ad8a275 100644 --- a/sc4pd/source/BrownNoise.cpp +++ b/sc4pd/source/BrownNoise.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ BrownNoise~ -------------------------------*/ diff --git a/sc4pd/source/ClipNoise.cpp b/sc4pd/source/ClipNoise.cpp index 761fbb6..32d8c94 100644 --- a/sc4pd/source/ClipNoise.cpp +++ b/sc4pd/source/ClipNoise.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ ClipNoise~ -------------------------------*/ diff --git a/sc4pd/source/CoinGate.cpp b/sc4pd/source/CoinGate.cpp index 27961c2..fc47aca 100644 --- a/sc4pd/source/CoinGate.cpp +++ b/sc4pd/source/CoinGate.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ CoinGate ---------------------------------*/ diff --git a/sc4pd/source/Crackle.cpp b/sc4pd/source/Crackle.cpp index 0bc9ae0..a013a1a 100644 --- a/sc4pd/source/Crackle.cpp +++ b/sc4pd/source/Crackle.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ Crackle~ -------------------------------*/ diff --git a/sc4pd/source/Decay.cpp b/sc4pd/source/Decay.cpp index 95bc22e..38112aa 100644 --- a/sc4pd/source/Decay.cpp +++ b/sc4pd/source/Decay.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Decay~ -----------------------------*/ diff --git a/sc4pd/source/Dust.cpp b/sc4pd/source/Dust.cpp index 0acd45f..c44572e 100644 --- a/sc4pd/source/Dust.cpp +++ b/sc4pd/source/Dust.cpp @@ -34,13 +34,7 @@ Coded while listening to: Assif Tsahar & Tatsuya Nakatani: Come Sunday */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Dust~ -------------------------------------*/ diff --git a/sc4pd/source/Dust2.cpp b/sc4pd/source/Dust2.cpp index cb5d509..19013ee 100644 --- a/sc4pd/source/Dust2.cpp +++ b/sc4pd/source/Dust2.cpp @@ -35,13 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Dust2~ -------------------------------------*/ diff --git a/sc4pd/source/ExpRand.cpp b/sc4pd/source/ExpRand.cpp index 3b17aef..9f1f4a7 100644 --- a/sc4pd/source/ExpRand.cpp +++ b/sc4pd/source/ExpRand.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ ExpRand~ -------------------------------*/ diff --git a/sc4pd/source/GrayNoise.cpp b/sc4pd/source/GrayNoise.cpp index 6c76217..4fa7b23 100644 --- a/sc4pd/source/GrayNoise.cpp +++ b/sc4pd/source/GrayNoise.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ GrayNoise~ -------------------------------*/ diff --git a/sc4pd/source/Hasher.cpp b/sc4pd/source/Hasher.cpp index 9fc2f48..8c43c8c 100644 --- a/sc4pd/source/Hasher.cpp +++ b/sc4pd/source/Hasher.cpp @@ -35,14 +35,7 @@ */ -#include #include "support.hpp" -#include "SC_PlugIn.h" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif /* ------------------------ Hasher~ -----------------------------------*/ diff --git a/sc4pd/source/IRand.cpp b/sc4pd/source/IRand.cpp index 095df92..18cf125 100644 --- a/sc4pd/source/IRand.cpp +++ b/sc4pd/source/IRand.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ IRand~ -------------------------------*/ diff --git a/sc4pd/source/Impulse.cpp b/sc4pd/source/Impulse.cpp index 277ad34..dbb07e2 100644 --- a/sc4pd/source/Impulse.cpp +++ b/sc4pd/source/Impulse.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* todo: implement phase offset as in sc3 /* ------------------------ Impulse~ -------------------------------*/ diff --git a/sc4pd/source/Integrator.cpp b/sc4pd/source/Integrator.cpp index 75bb350..97d2766 100644 --- a/sc4pd/source/Integrator.cpp +++ b/sc4pd/source/Integrator.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Integrator~ -----------------------------*/ diff --git a/sc4pd/source/LFClipNoise.cpp b/sc4pd/source/LFClipNoise.cpp index 18f95ee..60f5049 100644 --- a/sc4pd/source/LFClipNoise.cpp +++ b/sc4pd/source/LFClipNoise.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LFClipNoise~ -------------------------------*/ diff --git a/sc4pd/source/LFNoise0.cpp b/sc4pd/source/LFNoise0.cpp index c0f8abd..a548e9e 100644 --- a/sc4pd/source/LFNoise0.cpp +++ b/sc4pd/source/LFNoise0.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LFNoise0~ -------------------------------*/ diff --git a/sc4pd/source/LFNoise1.cpp b/sc4pd/source/LFNoise1.cpp index e48d3bb..d80b55b 100644 --- a/sc4pd/source/LFNoise1.cpp +++ b/sc4pd/source/LFNoise1.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LFNoise1~ -------------------------------*/ diff --git a/sc4pd/source/LFNoise2.cpp b/sc4pd/source/LFNoise2.cpp index 71aff7d..891a0f3 100644 --- a/sc4pd/source/LFNoise2.cpp +++ b/sc4pd/source/LFNoise2.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LFNoise2~ -------------------------------*/ diff --git a/sc4pd/source/LFPulse.cpp b/sc4pd/source/LFPulse.cpp index 76abc2c..020fb57 100644 --- a/sc4pd/source/LFPulse.cpp +++ b/sc4pd/source/LFPulse.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LFPulse~ -------------------------------*/ diff --git a/sc4pd/source/LFSaw.cpp b/sc4pd/source/LFSaw.cpp index 358cb2f..c442a89 100644 --- a/sc4pd/source/LFSaw.cpp +++ b/sc4pd/source/LFSaw.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LFSaw~ -------------------------------*/ diff --git a/sc4pd/source/Latoocarfian.cpp b/sc4pd/source/Latoocarfian.cpp index c509711..3fdb0b2 100644 --- a/sc4pd/source/Latoocarfian.cpp +++ b/sc4pd/source/Latoocarfian.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Latoocarfian~ -------------------------------*/ diff --git a/sc4pd/source/LinCong.cpp b/sc4pd/source/LinCong.cpp index 0da0df7..4f0b327 100644 --- a/sc4pd/source/LinCong.cpp +++ b/sc4pd/source/LinCong.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LinCong~ -------------------------------*/ diff --git a/sc4pd/source/LinRand.cpp b/sc4pd/source/LinRand.cpp index 3ebc458..f5acb00 100644 --- a/sc4pd/source/LinRand.cpp +++ b/sc4pd/source/LinRand.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ LinRand~ -------------------------------*/ diff --git a/sc4pd/source/Logistic.cpp b/sc4pd/source/Logistic.cpp index 9a475e0..89c6c2e 100644 --- a/sc4pd/source/Logistic.cpp +++ b/sc4pd/source/Logistic.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Logistic~ -------------------------------*/ diff --git a/sc4pd/source/MantissaMask.cpp b/sc4pd/source/MantissaMask.cpp index d3a867d..dfbf605 100644 --- a/sc4pd/source/MantissaMask.cpp +++ b/sc4pd/source/MantissaMask.cpp @@ -35,14 +35,7 @@ */ -#include #include "support.hpp" -#include "SC_PlugIn.h" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif /* ------------------------ MantissaMask~ -----------------------------*/ diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp index 77b0a5d..f15ce63 100644 --- a/sc4pd/source/Median.cpp +++ b/sc4pd/source/Median.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Median(~) ---------------------------------*/ diff --git a/sc4pd/source/NRand.cpp b/sc4pd/source/NRand.cpp index 9921c82..84a4374 100644 --- a/sc4pd/source/NRand.cpp +++ b/sc4pd/source/NRand.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ NRand~ -------------------------------*/ diff --git a/sc4pd/source/PinkNoise.cpp b/sc4pd/source/PinkNoise.cpp index 9a1c5bc..513d02a 100644 --- a/sc4pd/source/PinkNoise.cpp +++ b/sc4pd/source/PinkNoise.cpp @@ -35,15 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ PinkNoise~ -------------------------------*/ diff --git a/sc4pd/source/Rand.cpp b/sc4pd/source/Rand.cpp index 243cc5e..791db68 100644 --- a/sc4pd/source/Rand.cpp +++ b/sc4pd/source/Rand.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ Rand~ -------------------------------*/ diff --git a/sc4pd/source/TExpRand.cpp b/sc4pd/source/TExpRand.cpp index b7ee16e..6e2b1c6 100644 --- a/sc4pd/source/TExpRand.cpp +++ b/sc4pd/source/TExpRand.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ TExpRand~ -------------------------------*/ diff --git a/sc4pd/source/TIRand.cpp b/sc4pd/source/TIRand.cpp index 93fdd09..1995e46 100644 --- a/sc4pd/source/TIRand.cpp +++ b/sc4pd/source/TIRand.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ TIRand~ -------------------------------*/ diff --git a/sc4pd/source/TRand.cpp b/sc4pd/source/TRand.cpp index b18704f..d761dc4 100644 --- a/sc4pd/source/TRand.cpp +++ b/sc4pd/source/TRand.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ TRand~ -------------------------------*/ diff --git a/sc4pd/source/WhiteNoise.cpp b/sc4pd/source/WhiteNoise.cpp index 6d308db..779cb2f 100644 --- a/sc4pd/source/WhiteNoise.cpp +++ b/sc4pd/source/WhiteNoise.cpp @@ -35,14 +35,7 @@ */ -#include -#include "SC_PlugIn.h" -#include "support.hpp" - - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ WhiteNoise~ -------------------------------*/ diff --git a/sc4pd/source/absdif.cpp b/sc4pd/source/absdif.cpp index 34f41db..1af9473 100644 --- a/sc4pd/source/absdif.cpp +++ b/sc4pd/source/absdif.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" inline float sc_absdif (float a, float b) diff --git a/sc4pd/source/amclip.cpp b/sc4pd/source/amclip.cpp index 9d4a936..4a3b194 100644 --- a/sc4pd/source/amclip.cpp +++ b/sc4pd/source/amclip.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ amclip~ -----------------------------*/ diff --git a/sc4pd/source/difsqr.cpp b/sc4pd/source/difsqr.cpp index 823f266..807eefc 100644 --- a/sc4pd/source/difsqr.cpp +++ b/sc4pd/source/difsqr.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" inline float sc_difsqr (float a, float b) diff --git a/sc4pd/source/excess.cpp b/sc4pd/source/excess.cpp index 00f8666..2aca853 100644 --- a/sc4pd/source/excess.cpp +++ b/sc4pd/source/excess.cpp @@ -35,13 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" /* ------------------------ excess~ -----------------------------*/ diff --git a/sc4pd/source/hypot.cpp b/sc4pd/source/hypot.cpp index b096e48..1e2dd1a 100644 --- a/sc4pd/source/hypot.cpp +++ b/sc4pd/source/hypot.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ hypot~ -----------------------------*/ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index bc8af2a..cbec3c3 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -34,12 +34,7 @@ Coded while listening to: Phosphor */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" #define SC4PD_VERSION "0.01" diff --git a/sc4pd/source/ring2.cpp b/sc4pd/source/ring2.cpp index 02e9a18..e5c48cf 100644 --- a/sc4pd/source/ring2.cpp +++ b/sc4pd/source/ring2.cpp @@ -35,13 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" inline float sc_ring2 (float a, float b) { diff --git a/sc4pd/source/ring3.cpp b/sc4pd/source/ring3.cpp index 1887066..adb13c2 100644 --- a/sc4pd/source/ring3.cpp +++ b/sc4pd/source/ring3.cpp @@ -35,13 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" inline float sc_ring3 (float a, float b) { diff --git a/sc4pd/source/ring4.cpp b/sc4pd/source/ring4.cpp index b343f67..5bd2af4 100644 --- a/sc4pd/source/ring4.cpp +++ b/sc4pd/source/ring4.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" inline float sc_ring4 (float a, float b) diff --git a/sc4pd/source/scaleneg.cpp b/sc4pd/source/scaleneg.cpp index f6e69db..abd316f 100644 --- a/sc4pd/source/scaleneg.cpp +++ b/sc4pd/source/scaleneg.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" /* ------------------------ scaleneg~ -----------------------------*/ diff --git a/sc4pd/source/sqrdif.cpp b/sc4pd/source/sqrdif.cpp index 617f987..2762fe5 100644 --- a/sc4pd/source/sqrdif.cpp +++ b/sc4pd/source/sqrdif.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" inline float sc_sqrdif (float a, float b) diff --git a/sc4pd/source/sqrsum.cpp b/sc4pd/source/sqrsum.cpp index 8a39b68..265c909 100644 --- a/sc4pd/source/sqrsum.cpp +++ b/sc4pd/source/sqrsum.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" inline float sc_sqrsum (float a, float b) diff --git a/sc4pd/source/sumsqr.cpp b/sc4pd/source/sumsqr.cpp index 5eb5726..4b2564d 100644 --- a/sc4pd/source/sumsqr.cpp +++ b/sc4pd/source/sumsqr.cpp @@ -35,12 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif +#include "sc4pd.hpp" inline float sc_sumsqr (float a, float b) diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp index 5211b71..fd87c86 100644 --- a/sc4pd/source/support.cpp +++ b/sc4pd/source/support.cpp @@ -34,14 +34,10 @@ */ -#include -#include -#include "SC_PlugIn.h" +#include "sc4pd.hpp" +#include -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif bool sc_add (flext::AtomList a) { diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index bb5537a..34e260a 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -95,9 +95,3 @@ WARRANTIES, see the file, "license.txt," in this distribution. #define SIGFUN(FUN) &thisType::FUN -/* this macro has to be redefined to work with flext */ - -// calculate a slope for control rate interpolation to audio rate. -//#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor) -#undef CALCSLOPE -#define CALCSLOPE(next,prev) ((next - prev) * 1/Blocksize()) -- cgit v1.2.1 From 1bf32780fe1281eda6deb51f661f2f234a16fd1f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 2 Aug 2004 20:13:59 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1904 --- sc4pd/make-files.txt | 2 +- sc4pd/pd/LFSaw.pd | 16 +++++ sc4pd/pd/decay.pd | 12 ++++ sc4pd/pd/decay2.pd | 12 ++++ sc4pd/readme.txt | 5 +- sc4pd/source/Decay.cpp | 7 ++- sc4pd/source/Decay2.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 4 +- sc4pd/source/ring1.cpp | 8 +-- sc4pd/source/sc4pd.hpp | 60 +++++++++++++++++++ 10 files changed, 266 insertions(+), 13 deletions(-) create mode 100644 sc4pd/pd/LFSaw.pd create mode 100644 sc4pd/pd/decay.pd create mode 100644 sc4pd/pd/decay2.pd create mode 100644 sc4pd/source/Decay2.cpp create mode 100644 sc4pd/source/sc4pd.hpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 49ba19b..5a2aaf7 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -9,4 +9,4 @@ SRCS= \ Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ - LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp \ No newline at end of file + LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp \ No newline at end of file diff --git a/sc4pd/pd/LFSaw.pd b/sc4pd/pd/LFSaw.pd new file mode 100644 index 0000000..190ddcf --- /dev/null +++ b/sc4pd/pd/LFSaw.pd @@ -0,0 +1,16 @@ +#N canvas 0 0 782 300 10; +#X obj 93 170 dac~; +#X obj 107 117 LFSaw~ 440 ar; +#X obj 108 75 sig~ 440; +#X msg 223 88 set \$1; +#X floatatom 227 53 5 0 0 0 - - -; +#X msg 20 31 kr; +#X msg 62 30 ar; +#X obj 405 107 LFSaw 1 100; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 2 0 1 0; +#X connect 3 0 1 0; +#X connect 4 0 3 0; +#X connect 5 0 1 0; +#X connect 6 0 1 0; diff --git a/sc4pd/pd/decay.pd b/sc4pd/pd/decay.pd new file mode 100644 index 0000000..4d54e30 --- /dev/null +++ b/sc4pd/pd/decay.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 149 72 Dust~ 440; +#X obj 156 130 Decay~ 0.01; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 4 0 1 0; diff --git a/sc4pd/pd/decay2.pd b/sc4pd/pd/decay2.pd new file mode 100644 index 0000000..98260f6 --- /dev/null +++ b/sc4pd/pd/decay2.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 149 72 Dust~ 440; +#X obj 156 130 Decay2~ 0.01 0.002; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 4 0 1 0; diff --git a/sc4pd/readme.txt b/sc4pd/readme.txt index 7372555..9a09b43 100644 --- a/sc4pd/readme.txt +++ b/sc4pd/readme.txt @@ -19,5 +19,8 @@ thanks to: Miller Puckette for PureData Thomas Grill for Flext three great pieces of software... - + + thanks for bug reports: + Gerard (0001@ooo000ooo.org) + bugs, suggestions, complains to: TimBlechmann@gmx.de \ No newline at end of file diff --git a/sc4pd/source/Decay.cpp b/sc4pd/source/Decay.cpp index 38112aa..467611c 100644 --- a/sc4pd/source/Decay.cpp +++ b/sc4pd/source/Decay.cpp @@ -37,6 +37,7 @@ #include "sc4pd.hpp" +/* todo: linear interpolation is broken */ /* ------------------------ Decay~ -----------------------------*/ class Decay_ar @@ -67,7 +68,7 @@ Decay_ar::Decay_ar(int argc,t_atom * argv) AtomList Args(argc,argv); - m_b1 = sc_getfloatarg(Args,0); + decayTime = sc_getfloatarg(Args,0); AddOutSignal(); @@ -148,12 +149,12 @@ void Decay_ar::m_signal(int n, t_sample *const *in, void Decay_ar::m_set(float f) { decayTime = f; - m_b1= 0.f ? 0.f : exp(log001 / (decayTime * Samplerate())); + m_b1= f == 0.f ? 0.f : exp(log001 / (decayTime * Samplerate())); } void Decay_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) { - m_b1= 0.f ? 0.f : exp(log001 / (decayTime * Samplerate())); + m_b1= decayTime == 0.f ? 0.f : exp(log001 / (decayTime * Samplerate())); } /* todo: does it make sense to implement a message-based Decay? diff --git a/sc4pd/source/Decay2.cpp b/sc4pd/source/Decay2.cpp new file mode 100644 index 0000000..557f057 --- /dev/null +++ b/sc4pd/source/Decay2.cpp @@ -0,0 +1,153 @@ +/* sc4pd + Decay2~, Decay2 + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: AMM: AMMMusic 1966 + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ Decay2~ -----------------------------*/ + +class Decay2_ar + :public flext_dsp +{ + FLEXT_HEADER(Decay2_ar,flext_dsp); + +public: + Decay2_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_attack(float f); + void m_decay(float f); + +private: + FLEXT_CALLBACK_F(m_decay); + FLEXT_CALLBACK_F(m_attack); + float m_attackTime, m_y1a, m_b1a, n_b1a; + float m_decayTime, m_y1b, m_b1b, n_b1b; + bool changed; +}; + +FLEXT_LIB_DSP_V("Decay2~",Decay2_ar); + +Decay2_ar::Decay2_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"decayTime",m_decay); + FLEXT_ADDMETHOD_(0,"attackTime",m_attack); + + AtomList Args(argc,argv); + + m_decayTime = sc_getfloatarg(Args,1); //decay + m_attackTime = sc_getfloatarg(Args,0);//attack + + AddOutSignal(); + + m_y1a = m_y1b = 0.f; //different than in sc + +} + +void Decay2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y1a = m_y1a; + float y1b = m_y1b; + float b1a = m_b1a; + float b1b = m_b1b; + + if(changed) + { + float b1a_slope = CALCSLOPE(n_b1a, b1a); + float b1b_slope = CALCSLOPE(n_b1b, b1b); + m_b1a = n_b1a; + m_b1b = n_b1b; + + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + y1a = y0 + b1a * y1a; + y1b = y0 + b1b * y1b; + + ZXP (nout) = y1a - y1b; + b1a += b1a_slope; + b1b += b1b_slope; + } + changed = false; + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + y1a = y0 + b1a * y1a; + y1b = y0 + b1b * y1b; + + ZXP (nout) = y1a - y1b; + } + } + + m_y1a = zapgremlins(y1a); + m_y1b = zapgremlins(y1b); +} + +void Decay2_ar::m_decay(float f) +{ + m_decayTime = f; + n_b1a = f == 0.f ? 0.f : exp(log001 / (f * Samplerate())); + changed = true; +} + +void Decay2_ar::m_attack(float f) +{ + m_attackTime = f; + n_b1b = f == 0.f ? 0.f : exp(log001 / (f * Samplerate())); + changed = true; +} + +void Decay2_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + m_b1a = m_decayTime == 0.f ? 0.f : exp(log001 / + (m_decayTime * Samplerate())); + m_b1b = m_attackTime == 0.f ? 0.f : exp(log001 / + (m_attackTime * Samplerate())); +} + +/* todo: does it make sense to implement a message-based Decay2? + Probably not... */ + diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index cbec3c3..1f76f4c 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,7 @@ void sc4pd_library_setup() " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " "sqrdif(~),\n" " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" - " Integrator(~), Decay~\n" + " Integrator(~), Decay~, Decay2~\n" ); //initialize objects @@ -194,6 +194,8 @@ void sc4pd_library_setup() FLEXT_SETUP(Integrator_kr); FLEXT_DSP_SETUP(Decay_ar); + + FLEXT_DSP_SETUP(Decay2_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/ring1.cpp b/sc4pd/source/ring1.cpp index b9aee15..f3bce43 100644 --- a/sc4pd/source/ring1.cpp +++ b/sc4pd/source/ring1.cpp @@ -35,13 +35,7 @@ */ -#include -#include "SC_PlugIn.h" - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - +#include "sc4pd.hpp" inline float sc_ring1 (float a, float b) { diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp new file mode 100644 index 0000000..214b80c --- /dev/null +++ b/sc4pd/source/sc4pd.hpp @@ -0,0 +1,60 @@ +/* sc4pd: + support functions + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Morton Feldman: For John Cage + +*/ + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) +#error You need at least FLEXT version 0.4.6 +#endif + +#include "SC_PlugIn.h" +#include "support.hpp" + +/* this macro has to be redefined to work with flext */ + +// calculate a slope for control rate interpolation to audio rate. +//#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor) +#undef CALCSLOPE +#define CALCSLOPE(next,prev) ((next - prev) * 1/Blocksize()) + + + + +/* to make sure the behaviour is consistent: */ + +#undef ZXP +#define ZXP(z) (*(z)++) + -- cgit v1.2.1 From 78431322cc77b9654fa4a2e2b1b42a9310cb9141 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 2 Aug 2004 21:13:50 +0000 Subject: lag svn path=/trunk/externals/tb/; revision=1905 --- sc4pd/make-files.txt | 2 +- sc4pd/pd/lag.pd | 17 +++++++ sc4pd/source/Decay2.cpp | 1 + sc4pd/source/Lag.cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 4 +- sc4pd/source/sc4pd.hpp | 4 +- 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 sc4pd/pd/lag.pd create mode 100644 sc4pd/source/Lag.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 5a2aaf7..922e05c 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -9,4 +9,4 @@ SRCS= \ Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ - LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp \ No newline at end of file + LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ No newline at end of file diff --git a/sc4pd/pd/lag.pd b/sc4pd/pd/lag.pd new file mode 100644 index 0000000..206a07b --- /dev/null +++ b/sc4pd/pd/lag.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 257 82 hsl 128 15 1e-04 1 1 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 0; +#X msg 254 102 lagTime \$1; +#X obj 155 61 WhiteNoise~; +#X obj 156 130 Lag~ 0.0004; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 6 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; +#X connect 6 0 1 0; diff --git a/sc4pd/source/Decay2.cpp b/sc4pd/source/Decay2.cpp index 557f057..001eb31 100644 --- a/sc4pd/source/Decay2.cpp +++ b/sc4pd/source/Decay2.cpp @@ -146,6 +146,7 @@ void Decay2_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) (m_decayTime * Samplerate())); m_b1b = m_attackTime == 0.f ? 0.f : exp(log001 / (m_attackTime * Samplerate())); + changed = false; } /* todo: does it make sense to implement a message-based Decay2? diff --git a/sc4pd/source/Lag.cpp b/sc4pd/source/Lag.cpp new file mode 100644 index 0000000..81482a8 --- /dev/null +++ b/sc4pd/source/Lag.cpp @@ -0,0 +1,124 @@ +/* sc4pd + Lag~, Lag + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: VA: Live from the Vision Festival + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ Lag~ -----------------------------*/ + +class Lag_ar + :public flext_dsp +{ + FLEXT_HEADER(Lag_ar,flext_dsp); + +public: + Lag_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1, n_b1; + float m_y1; + float m_lag; + bool changed; +}; + +FLEXT_LIB_DSP_V("Lag~",Lag_ar); + +Lag_ar::Lag_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"lagTime",m_set); + + AtomList Args(argc,argv); + + m_lag = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_y1 = 0.f; +} + +void Lag_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + changed = false; + m_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); +} + +void Lag_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y1 = m_y1; + float b1 = m_b1; + + if (changed) + { + float b1_slope = CALCSLOPE(m_b1, n_b1); + m_b1 = n_b1; + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = y0 + b1 * (y1 - y0); + b1 += b1_slope; + } + changed = false; + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = y0 + b1 * (y1 - y0); + } + } + m_y1 = zapgremlins(y1); +} + +void Lag_ar::m_set(float f) +{ + m_lag = f; + n_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); + changed = true; +} + +/* todo: does a control rate Lag make sense? */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 1f76f4c..681c165 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,7 @@ void sc4pd_library_setup() " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " "sqrdif(~),\n" " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" - " Integrator(~), Decay~, Decay2~\n" + " Integrator(~), Decay~, Decay2~, Lag~\n" ); //initialize objects @@ -196,6 +196,8 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Decay_ar); FLEXT_DSP_SETUP(Decay2_ar); + + FLEXT_DSP_SETUP(Lag_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp index 214b80c..d26e09e 100644 --- a/sc4pd/source/sc4pd.hpp +++ b/sc4pd/source/sc4pd.hpp @@ -48,9 +48,7 @@ // calculate a slope for control rate interpolation to audio rate. //#define CALCSLOPE(next,prev) ((next - prev) * unit->mRate->mSlopeFactor) #undef CALCSLOPE -#define CALCSLOPE(next,prev) ((next - prev) * 1/Blocksize()) - - +#define CALCSLOPE(next,prev) ((next - prev) * 1/ Blocksize()) /* to make sure the behaviour is consistent: */ -- cgit v1.2.1 From b85f8bc7af3fda0f31af1c79a9f25145b8004705 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 3 Aug 2004 09:56:19 +0000 Subject: works of one morning svn path=/trunk/externals/tb/; revision=1906 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/make-files.txt | 3 +- sc4pd/pd/delayn.pd | 11 +++ sc4pd/pd/lag2.pd | 17 ++++ sc4pd/pd/lag3.pd | 17 ++++ sc4pd/pd/linexp.pd | 17 ++++ sc4pd/source/DelayN.cpp | 239 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/DelayUnit.cpp | 77 +++++++++++++++ sc4pd/source/DelayUnit.hpp | 58 +++++++++++ sc4pd/source/Lag2.cpp | 132 +++++++++++++++++++++++++ sc4pd/source/Lag3.cpp | 137 ++++++++++++++++++++++++++ sc4pd/source/LinExp.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 12 ++- sc4pd/source/sc4pd.hpp | 19 ++++ sc4pd/source/template.cpp | 8 +- 15 files changed, 962 insertions(+), 10 deletions(-) create mode 100644 sc4pd/pd/delayn.pd create mode 100644 sc4pd/pd/lag2.pd create mode 100644 sc4pd/pd/lag3.pd create mode 100644 sc4pd/pd/linexp.pd create mode 100644 sc4pd/source/DelayN.cpp create mode 100644 sc4pd/source/DelayUnit.cpp create mode 100644 sc4pd/source/DelayUnit.hpp create mode 100644 sc4pd/source/Lag2.cpp create mode 100644 sc4pd/source/Lag3.cpp create mode 100644 sc4pd/source/LinExp.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 9b46ed4..1e95392 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) -# CXX=icc + CXX=icc # where does the PD installation reside? diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 922e05c..78ed170 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -9,4 +9,5 @@ SRCS= \ Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ - LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ No newline at end of file + LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ + Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp \ No newline at end of file diff --git a/sc4pd/pd/delayn.pd b/sc4pd/pd/delayn.pd new file mode 100644 index 0000000..37b0c29 --- /dev/null +++ b/sc4pd/pd/delayn.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X obj 77 138 DelayN~ 1 3; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 90 233 dac~; +#X msg 185 88 delaytime \$1; +#X obj 79 57 Dust~ 4; +#X connect 0 0 2 0; +#X connect 1 0 3 0; +#X connect 3 0 0 0; +#X connect 4 0 0 0; +#X connect 4 0 2 1; diff --git a/sc4pd/pd/lag2.pd b/sc4pd/pd/lag2.pd new file mode 100644 index 0000000..0398109 --- /dev/null +++ b/sc4pd/pd/lag2.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 257 82 hsl 128 15 1e-04 1 1 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 0; +#X msg 254 102 lagTime \$1; +#X obj 155 61 WhiteNoise~; +#X obj 156 130 Lag2~ 0.0004; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 6 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; +#X connect 6 0 1 0; diff --git a/sc4pd/pd/lag3.pd b/sc4pd/pd/lag3.pd new file mode 100644 index 0000000..206a07b --- /dev/null +++ b/sc4pd/pd/lag3.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 159 205 dac~; +#X obj 239 198 print~; +#X obj 244 171 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 257 82 hsl 128 15 1e-04 1 1 0 empty empty empty -2 -6 0 8 -262144 +-1 -1 0 0; +#X msg 254 102 lagTime \$1; +#X obj 155 61 WhiteNoise~; +#X obj 156 130 Lag~ 0.0004; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 6 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; +#X connect 6 0 1 0; diff --git a/sc4pd/pd/linexp.pd b/sc4pd/pd/linexp.pd new file mode 100644 index 0000000..5a7fc04 --- /dev/null +++ b/sc4pd/pd/linexp.pd @@ -0,0 +1,17 @@ +#N canvas 0 0 450 300 10; +#X obj 31 230 dac~; +#X obj 111 223 print~; +#X obj 116 196 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 27 86 osc~ 440; +#X obj 27 142 LinExp~ 0 1 0.001 2; +#X floatatom 252 204 5 0 0 0 - - -; +#X obj 246 151 LinExp 0 100 0.001 2; +#X floatatom 248 123 5 0 0 0 - - -; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 4 0 1 0; +#X connect 6 0 5 0; +#X connect 7 0 6 0; diff --git a/sc4pd/source/DelayN.cpp b/sc4pd/source/DelayN.cpp new file mode 100644 index 0000000..176c6c3 --- /dev/null +++ b/sc4pd/source/DelayN.cpp @@ -0,0 +1,239 @@ +/* sc4pd + DelayN~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class DelayN_ar : private DelayUnit_ar +{ + FLEXT_HEADER(DelayN_ar,DelayUnit_ar); + + DelayN_ar (int argc, t_atom *argv); + ~DelayN_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + changed = false; + DelayUnit_Reset(m_maxdelaytime, m_delaytime); + post("start"); + } + + void m_set(float f) + { + m_delaytime=f; + changed = true; + } + +private: + bool changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("DelayN~",DelayN_ar); + +DelayN_ar::DelayN_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_set); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("2 arguments are needed"); + return; + } + + m_delaytime = sc_getfloatarg(Args,0); + m_maxdelaytime = sc_getfloatarg(Args,1); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +DelayN_ar::~DelayN_ar () +{ + DelayUnit_Dtor(); +} + +void DelayN_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long irdphase = iwrphase - (long)dsamp; + + dlybuf[iwrphase & mask] = ZXP(nin); + if (irdphase < 0) + { + ZXP(nout) = 0.f; + } + else + { + ZXP(nout) = dlybuf[irdphase & mask]; + } + iwrphase++; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyN = dlybuf1 + m_idelaylen; + long remain = n; + + while (remain) + { + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyrd = dlybuf1 + (irdphase & mask); + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + if (irdphase < 0) + { + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = 0.f; + } + } + else + { + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = ZXP(dlyrd); + } + } + iwrphase += nsmps; + irdphase += nsmps; + } + } + + m_iwrphase = iwrphase; + + m_numoutput += n; + + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void DelayN_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dlybuf[iwrphase & mask] = ZXP(nin); + dsamp += dsamp_slope; + ++iwrphase; + long irdphase = iwrphase - (long)dsamp; + ZXP(nout) = dlybuf[irdphase & mask]; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyrd = dlybuf1 + (irdphase & mask); + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyN = dlybuf1 + m_idelaylen; + long remain = n; + while (remain) + { + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = ZXP(dlyrd); + } + if (dlyrd == dlyN) dlyrd = dlybuf1; + if (dlywr == dlyN) dlywr = dlybuf1; + } + iwrphase += n; + } + m_iwrphase = iwrphase; +} + +/* todo: DelayN for control rate ? */ diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp new file mode 100644 index 0000000..7f96677 --- /dev/null +++ b/sc4pd/source/DelayUnit.cpp @@ -0,0 +1,77 @@ +/* sc4pd + public class for several delay objects + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +void DelayUnit_ar::DelayUnit_AllocDelayLine() +{ + long delaybufsize = (long)ceil(m_maxdelaytime * Samplerate() + 1.f); + delaybufsize = delaybufsize + Blocksize(); + delaybufsize = NEXTPOWEROFTWO(delaybufsize); // round up to next power of two + m_fdelaylen = m_idelaylen = delaybufsize; + + delete m_dlybuf; + m_dlybuf = new float[delaybufsize] ; + m_mask = delaybufsize - 1; +} + +void DelayUnit_ar::DelayUnit_Dtor() +{ + delete m_dlybuf; +} + +float DelayUnit_ar::CalcDelay(float delaytime) +{ + float next_dsamp = delaytime * Samplerate(); + return sc_clip(next_dsamp, 1.f, m_fdelaylen); +} + +void DelayUnit_ar::DelayUnit_Reset(float f, float g) +{ + m_maxdelaytime = f; + m_delaytime = g; + m_dlybuf = 0; + + DelayUnit_AllocDelayLine(); + + m_dsamp = CalcDelay(m_delaytime); + + m_numoutput = 0; + m_iwrphase = 0; +} diff --git a/sc4pd/source/DelayUnit.hpp b/sc4pd/source/DelayUnit.hpp new file mode 100644 index 0000000..d794031 --- /dev/null +++ b/sc4pd/source/DelayUnit.hpp @@ -0,0 +1,58 @@ +/* sc4pd + public class for several delay objects + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + +*/ + +#include "sc4pd.hpp" + +class DelayUnit_ar : public flext_dsp +{ + FLEXT_HEADER(DelayUnit_ar, flext_dsp); +public: + /* functions */ + void DelayUnit_AllocDelayLine(); + void DelayUnit_Reset(float maxdelaytime, float delaytime); + float CalcDelay(float delaytime); + void DelayUnit_Dtor(); + + /* data */ + float *m_dlybuf; + float m_dsamp, m_fdelaylen; + float m_delaytime, m_maxdelaytime; + long m_iwrphase, m_idelaylen, m_mask; + long m_numoutput; +}; + +/* todo: a delay for control messages? */ diff --git a/sc4pd/source/Lag2.cpp b/sc4pd/source/Lag2.cpp new file mode 100644 index 0000000..2e3096b --- /dev/null +++ b/sc4pd/source/Lag2.cpp @@ -0,0 +1,132 @@ +/* sc4pd + Lag2~, Lag2 + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: DKV Trio: Baraka + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ Lag2~ -----------------------------*/ + +class Lag2_ar + :public flext_dsp +{ + FLEXT_HEADER(Lag2_ar,flext_dsp); + +public: + Lag2_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1, n_b1; + float m_y1a, m_y1b; + float m_lag; + bool changed; +}; + +FLEXT_LIB_DSP_V("Lag2~",Lag2_ar); + +Lag2_ar::Lag2_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"lagTime",m_set); + + AtomList Args(argc,argv); + + m_lag = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_b1 = 0.f; + m_y1a = 0.f; + m_y1b = 0.f; +} + +void Lag2_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + changed = false; + m_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); +} + +void Lag2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y1a = m_y1a; + float y1b = m_y1b; + float b1 = m_b1; + + if (changed) + { + float b1_slope = CALCSLOPE(m_b1, n_b1); + m_b1 = n_b1; + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + ZXP(nout) = y1b; + b1 += b1_slope; + } + changed = false; + } + else + { + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + ZXP(nout) = y1b; + } + } + m_y1a = zapgremlins(y1a); + m_y1b = zapgremlins(y1b); +} + +void Lag2_ar::m_set(float f) +{ + m_lag = f; + n_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); + changed = true; +} + +/* todo: does a control rate Lag2 make sense? */ diff --git a/sc4pd/source/Lag3.cpp b/sc4pd/source/Lag3.cpp new file mode 100644 index 0000000..bedd625 --- /dev/null +++ b/sc4pd/source/Lag3.cpp @@ -0,0 +1,137 @@ +/* sc4pd + Lag3~, Lag3 + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: DKV Trio: Baraka + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ Lag3~ -----------------------------*/ + +class Lag3_ar + :public flext_dsp +{ + FLEXT_HEADER(Lag3_ar,flext_dsp); + +public: + Lag3_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + void m_set(float f); + +private: + FLEXT_CALLBACK_F(m_set); + float m_b1, n_b1; + float m_y1a, m_y1b,m_y1c; + float m_lag; + bool changed; +}; + +FLEXT_LIB_DSP_V("Lag3~",Lag3_ar); + +Lag3_ar::Lag3_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"lagTime",m_set); + + AtomList Args(argc,argv); + + m_lag = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_b1 = 0.f; + m_y1a = 0.f; + m_y1b = 0.f; + m_y1c = 0.f; +} + +void Lag3_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + changed = false; + m_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); +} + +void Lag3_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y1a = m_y1a; + float y1b = m_y1b; + float y1c = m_y1c; + float b1 = m_b1; + + if (changed) + { + float b1_slope = CALCSLOPE(m_b1, n_b1); + m_b1 = n_b1; + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + y1c = y1b + b1 * (y1c - y1b); + ZXP(nout) = y1c; + b1 += b1_slope; + } + changed = false; + } + else + { + for (int i = 0; i!= n;++i) + { + float y0a = ZXP(nin); + y1a = y0a + b1 * (y1a - y0a); + y1b = y1a + b1 * (y1b - y1a); + y1c = y1b + b1 * (y1c - y1b); + ZXP(nout) = y1c; + } + } + m_y1a = zapgremlins(y1a); + m_y1b = zapgremlins(y1b); + m_y1b = zapgremlins(y1c); +} + +void Lag3_ar::m_set(float f) +{ + m_lag = f; + n_b1 = m_lag == 0.f ? 0.f : exp(log001 / (m_lag * Samplerate())); + changed = true; +} + +/* todo: does a control rate Lag3 make sense? */ diff --git a/sc4pd/source/LinExp.cpp b/sc4pd/source/LinExp.cpp new file mode 100644 index 0000000..6be19f3 --- /dev/null +++ b/sc4pd/source/LinExp.cpp @@ -0,0 +1,223 @@ +/* sc4pd + LinExp~, LinExp + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: The Ex & Tom Cora - And The Weathermen Shrug + Their Shoulders + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ LinExp~ -----------------------------*/ + +class LinExp_ar + :public flext_dsp +{ + FLEXT_HEADER(LinExp_ar,flext_dsp); + +public: + LinExp_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set_srclo(float f) + { + m_srclo = f; + m_reset(); + } + + void m_set_srchi(float f) + { + m_srchi = f; + m_reset(); + } + + void m_set_dstlo(float f) + { + m_dstlo = f; + m_reset(); + } + + void m_set_dsthi(float f) + { + m_dsthi = f; + m_reset(); + } + + void m_reset() + { + m_dstratio = m_dsthi/m_dstlo; + m_rsrcrange = 1. / (m_srchi - m_srclo); + m_rrminuslo = m_rsrcrange * -m_srclo; + } + +private: + FLEXT_CALLBACK_F(m_set_srclo); + FLEXT_CALLBACK_F(m_set_srchi); + FLEXT_CALLBACK_F(m_set_dstlo); + FLEXT_CALLBACK_F(m_set_dsthi); + float m_dstratio, m_rsrcrange, m_rrminuslo, m_dstlo; + float m_srclo, m_srchi, m_dsthi; //we will be able to reset the values +}; + +FLEXT_LIB_DSP_V("LinExp~",LinExp_ar); + +LinExp_ar::LinExp_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"srclo",m_set_srclo); + FLEXT_ADDMETHOD_(0,"srchi",m_set_srchi); + FLEXT_ADDMETHOD_(0,"dstlo",m_set_dstlo); + FLEXT_ADDMETHOD_(0,"dsthi",m_set_dsthi); + + AtomList Args(argc,argv); + + if (Args.Count() != 4) + post("4 arguments are required"); + else + { + m_srclo = sc_getfloatarg(Args,0); + m_srchi = sc_getfloatarg(Args,1); + m_dstlo = sc_getfloatarg(Args,2); + m_dsthi = sc_getfloatarg(Args,3); + + m_reset(); + AddOutSignal(); + } +} + +void LinExp_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float dstlo = m_dstlo; + float dstratio = m_dstratio; + float rsrcrange = m_rsrcrange; + float rrminuslo = m_rrminuslo; + + for (int i = 0; i!= n;++i) + { + ZXP(nout) = dstlo * pow(dstratio, ZXP(nin) * rsrcrange + rrminuslo); + } +} + +/* ------------------------ LinExp ------------------------------*/ + +class LinExp_kr + :public flext_base +{ + FLEXT_HEADER(LinExp_kr,flext_base); + +public: + LinExp_kr(int argc,t_atom * argv); + +protected: + void m_perform(float f); + + void m_set_srclo(float f) + { + m_srclo = f; + m_reset(); + } + + void m_set_srchi(float f) + { + m_srchi = f; + m_reset(); + } + + void m_set_dstlo(float f) + { + m_dstlo = f; + m_reset(); + } + + void m_set_dsthi(float f) + { + m_dsthi = f; + m_reset(); + } + + void m_reset() + { + m_dstratio = m_dsthi/m_dstlo; + m_rsrcrange = 1. / (m_srchi - m_srclo); + m_rrminuslo = m_rsrcrange * -m_srclo; + } + +private: + FLEXT_CALLBACK_F(m_set_srclo); + FLEXT_CALLBACK_F(m_set_srchi); + FLEXT_CALLBACK_F(m_set_dstlo); + FLEXT_CALLBACK_F(m_set_dsthi); + float m_dstratio, m_rsrcrange, m_rrminuslo, m_dstlo; + float m_srclo, m_srchi, m_dsthi; //we will be able to reset the values + + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("LinExp",LinExp_kr); + +LinExp_kr::LinExp_kr(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"srclo",m_set_srclo); + FLEXT_ADDMETHOD_(0,"srchi",m_set_srchi); + FLEXT_ADDMETHOD_(0,"dstlo",m_set_dstlo); + FLEXT_ADDMETHOD_(0,"dsthi",m_set_dsthi); + + AtomList Args(argc,argv); + + if (Args.Count() != 4) + post("4 arguments are required"); + else + { + m_srclo = sc_getfloatarg(Args,0); + m_srchi = sc_getfloatarg(Args,1); + m_dstlo = sc_getfloatarg(Args,2); + m_dsthi = sc_getfloatarg(Args,3); + + m_reset(); + + AddInFloat(); + AddOutFloat(); + } +} + +void LinExp_kr::m_perform(float f) +{ + ToOutFloat(0,m_dstlo * pow(m_dstratio, f * m_rsrcrange + m_rrminuslo)); +} diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 681c165..568d130 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,7 +58,8 @@ void sc4pd_library_setup() " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " "sqrdif(~),\n" " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" - " Integrator(~), Decay~, Decay2~, Lag~\n" + " Integrator(~), Decay~, Decay2~, Lag~, Lag2~, LinExp(~)" + "DelayN~\n" ); //initialize objects @@ -198,6 +199,15 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(Decay2_ar); FLEXT_DSP_SETUP(Lag_ar); + + FLEXT_DSP_SETUP(Lag2_ar); + + FLEXT_DSP_SETUP(Lag3_ar); + + FLEXT_DSP_SETUP(LinExp_ar); + FLEXT_SETUP(LinExp_kr); + + FLEXT_DSP_SETUP(DelayN_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp index d26e09e..f1f90e2 100644 --- a/sc4pd/source/sc4pd.hpp +++ b/sc4pd/source/sc4pd.hpp @@ -34,6 +34,9 @@ */ +#ifndef _SC4PD_HPP +#define _SC$PD_HPP + #include #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) @@ -51,8 +54,24 @@ #define CALCSLOPE(next,prev) ((next - prev) * 1/ Blocksize()) + +//#define SAMPLERATE (unit->mRate->mSampleRate) +#undef SAMPLERATE +#define SAMPLERATE Samplerate() + +//#define BUFLENGTH (unit->mBufLength) +#undef BUFLENGTH +#define BUFLENGTH Blocksize() + + + /* to make sure the behaviour is consistent: */ #undef ZXP #define ZXP(z) (*(z)++) + + + + +#endif diff --git a/sc4pd/source/template.cpp b/sc4pd/source/template.cpp index 0682c24..15d9f06 100644 --- a/sc4pd/source/template.cpp +++ b/sc4pd/source/template.cpp @@ -34,10 +34,4 @@ */ -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) -#error You need at least FLEXT version 0.4.6 -#endif - - +#include "sc4pd.hpp" -- cgit v1.2.1 From f91b27f71b88c45202afe0baf9776e30c4177e19 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 3 Aug 2004 17:51:51 +0000 Subject: small changes svn path=/trunk/externals/tb/; revision=1907 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/make-files.txt | 3 ++- sc4pd/source/DelayN.cpp | 5 ++--- sc4pd/source/DelayUnit.cpp | 19 ++++++++++++------- sc4pd/source/DelayUnit.hpp | 9 ++++++++- sc4pd/source/main.cpp | 9 +++++++-- sc4pd/source/support.hpp | 33 +++++++++++++++++++++++++++++++-- 7 files changed, 63 insertions(+), 17 deletions(-) diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 1e95392..9b46ed4 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) - CXX=icc +# CXX=icc # where does the PD installation reside? diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 78ed170..38c790a 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -10,4 +10,5 @@ SRCS= \ excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ - Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp \ No newline at end of file + Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ + DelayC.cpp CombN.cpp diff --git a/sc4pd/source/DelayN.cpp b/sc4pd/source/DelayN.cpp index 176c6c3..6bbbb18 100644 --- a/sc4pd/source/DelayN.cpp +++ b/sc4pd/source/DelayN.cpp @@ -32,7 +32,7 @@ http://www.audiosynth.com Coded while listening to: - + */ #include "sc4pd.hpp" @@ -54,8 +54,7 @@ protected: virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) { changed = false; - DelayUnit_Reset(m_maxdelaytime, m_delaytime); - post("start"); + DelayUnit_Reset(); } void m_set(float f) diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp index 7f96677..5b11f96 100644 --- a/sc4pd/source/DelayUnit.cpp +++ b/sc4pd/source/DelayUnit.cpp @@ -46,26 +46,24 @@ void DelayUnit_ar::DelayUnit_AllocDelayLine() delaybufsize = NEXTPOWEROFTWO(delaybufsize); // round up to next power of two m_fdelaylen = m_idelaylen = delaybufsize; - delete m_dlybuf; + delete[] m_dlybuf; m_dlybuf = new float[delaybufsize] ; m_mask = delaybufsize - 1; } void DelayUnit_ar::DelayUnit_Dtor() { - delete m_dlybuf; + delete[] m_dlybuf; } float DelayUnit_ar::CalcDelay(float delaytime) { - float next_dsamp = delaytime * Samplerate(); - return sc_clip(next_dsamp, 1.f, m_fdelaylen); + float next_dsamp = delaytime * Samplerate(); + return sc_clip(next_dsamp, 1.f, m_fdelaylen); } -void DelayUnit_ar::DelayUnit_Reset(float f, float g) +void DelayUnit_ar::DelayUnit_Reset() { - m_maxdelaytime = f; - m_delaytime = g; m_dlybuf = 0; DelayUnit_AllocDelayLine(); @@ -75,3 +73,10 @@ void DelayUnit_ar::DelayUnit_Reset(float f, float g) m_numoutput = 0; m_iwrphase = 0; } + +void FeedbackDelay_ar::FeedbackDelay_Reset() +{ + DelayUnit_Reset(); + + m_feedbk = CalcFeedback(m_delaytime, m_decaytime); +} diff --git a/sc4pd/source/DelayUnit.hpp b/sc4pd/source/DelayUnit.hpp index d794031..a15a8c3 100644 --- a/sc4pd/source/DelayUnit.hpp +++ b/sc4pd/source/DelayUnit.hpp @@ -43,7 +43,7 @@ class DelayUnit_ar : public flext_dsp public: /* functions */ void DelayUnit_AllocDelayLine(); - void DelayUnit_Reset(float maxdelaytime, float delaytime); + void DelayUnit_Reset(); float CalcDelay(float delaytime); void DelayUnit_Dtor(); @@ -56,3 +56,10 @@ public: }; /* todo: a delay for control messages? */ + +class FeedbackDelay_ar : public DelayUnit_ar +{ + FLEXT_HEADER(FeedbackDelay_ar,DelayUnit_ar); + float m_feedbk, m_decaytime; + void FeedbackDelay_Reset(); +}; diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 568d130..126cf50 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -58,8 +58,9 @@ void sc4pd_library_setup() " ring2(~), ring3(~), ring4(~), difsqr(~), sumsqr(~), " "sqrdif(~),\n" " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" - " Integrator(~), Decay~, Decay2~, Lag~, Lag2~, LinExp(~)" - "DelayN~\n" + " Integrator(~), Decay~, Decay2~, Lag~, Lag2~, LinExp(~), " + "DelayN~,\n" + " DelayL~, DelayC~" ); //initialize objects @@ -208,6 +209,10 @@ void sc4pd_library_setup() FLEXT_SETUP(LinExp_kr); FLEXT_DSP_SETUP(DelayN_ar); + + FLEXT_DSP_SETUP(DelayL_ar); + + FLEXT_DSP_SETUP(DelayC_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index 34e260a..6b51f2b 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -34,16 +34,18 @@ */ +#ifndef _SUPPORT_HPP +#define _SUPPORT_HPP + #include -//#include #include "SC_PlugIn.h" -//#include #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) #error You need at least FLEXT version 0.4.6 #endif + /* for argument parsing */ bool sc_add (flext::AtomList a); float sc_getfloatarg (flext::AtomList a,int i); @@ -65,6 +67,32 @@ bool sc_ar(flext::AtomList a); int32 timeseed(); +/* cubic interpolation from DelayUGens.cpp */ +inline float cubicinterp(float x, float y0, float y1, float y2, float y3) +{ + // 4-point, 3rd-order Hermite (x-form) + float c0 = y1; + float c1 = 0.5f * (y2 - y0); + float c2 = y0 - 2.5f * y1 + 2.f * y2 - 0.5f * y3; + float c3 = 0.5f * (y3 - y0) + 1.5f * (y1 - y2); + + return ((c3 * x + c2) * x + c1) * x + c0; +} + +/* feedback calculation from DelayUGens.cpp */ +inline float CalcFeedback(float delaytime, float decaytime) +{ + if (delaytime == 0.f) { + return 0.f; + } else if (decaytime > 0.f) { + return exp(log001 * delaytime / decaytime); + } else if (decaytime < 0.f) { + return -exp(log001 * delaytime / -decaytime); + } else { + return 0.f; + } +} + /* this is copied from thomas grill's xsample: xsample - extended sample objects for Max/MSP and pd (pure data) @@ -95,3 +123,4 @@ WARRANTIES, see the file, "license.txt," in this distribution. #define SIGFUN(FUN) &thisType::FUN +#endif -- cgit v1.2.1 From dfed9bb41f3da99644213f11edbef530b2df1ee2 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 4 Aug 2004 16:46:55 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1908 --- sc4pd/make-files.txt | 2 +- sc4pd/pd/combl.pd | 20 +++ sc4pd/pd/combn.pd | 20 +++ sc4pd/pd/delayc.pd | 11 ++ sc4pd/pd/delayl.pd | 11 ++ sc4pd/source/CombL.cpp | 272 ++++++++++++++++++++++++++++++++++++ sc4pd/source/CombN.cpp | 341 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/DelayC.cpp | 287 ++++++++++++++++++++++++++++++++++++++ sc4pd/source/DelayL.cpp | 236 +++++++++++++++++++++++++++++++ sc4pd/source/DelayUnit.cpp | 3 +- sc4pd/source/main.cpp | 6 +- 11 files changed, 1205 insertions(+), 4 deletions(-) create mode 100644 sc4pd/pd/combl.pd create mode 100644 sc4pd/pd/combn.pd create mode 100644 sc4pd/pd/delayc.pd create mode 100644 sc4pd/pd/delayl.pd create mode 100644 sc4pd/source/CombL.cpp create mode 100644 sc4pd/source/CombN.cpp create mode 100644 sc4pd/source/DelayC.cpp create mode 100644 sc4pd/source/DelayL.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 38c790a..99913e7 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -11,4 +11,4 @@ SRCS= \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ - DelayC.cpp CombN.cpp + DelayC.cpp CombN.cpp CombL.cpp diff --git a/sc4pd/pd/combl.pd b/sc4pd/pd/combl.pd new file mode 100644 index 0000000..b8fb0d2 --- /dev/null +++ b/sc4pd/pd/combl.pd @@ -0,0 +1,20 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 111 190 print~; +#X obj 128 170 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 316 107 decaytime \$1; +#X obj 79 57 WhiteNoise~; +#X obj 77 138 CombL~ 1 0.001 0.2; +#X connect 0 0 2 0; +#X connect 2 0 8 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 1 1; +#X connect 8 0 3 0; diff --git a/sc4pd/pd/combn.pd b/sc4pd/pd/combn.pd new file mode 100644 index 0000000..4baf6ef --- /dev/null +++ b/sc4pd/pd/combn.pd @@ -0,0 +1,20 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 111 190 print~; +#X obj 128 170 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 316 107 decaytime \$1; +#X obj 79 57 WhiteNoise~; +#X obj 77 138 CombN~ 1 0.001 0.2; +#X connect 0 0 2 0; +#X connect 2 0 8 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 1 1; +#X connect 8 0 3 0; diff --git a/sc4pd/pd/delayc.pd b/sc4pd/pd/delayc.pd new file mode 100644 index 0000000..2f539ff --- /dev/null +++ b/sc4pd/pd/delayc.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 77 138 CombN~ 0.01 0.003 3; +#X obj 79 57 Dust~ 440; +#X connect 0 0 2 0; +#X connect 2 0 3 0; +#X connect 3 0 1 0; +#X connect 3 0 1 1; +#X connect 4 0 3 0; diff --git a/sc4pd/pd/delayl.pd b/sc4pd/pd/delayl.pd new file mode 100644 index 0000000..690063b --- /dev/null +++ b/sc4pd/pd/delayl.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 90 233 dac~; +#X msg 185 88 delaytime \$1; +#X obj 79 57 Dust~ 4; +#X obj 77 138 DelayL~ 1 3; +#X connect 0 0 2 0; +#X connect 2 0 4 0; +#X connect 3 0 1 1; +#X connect 3 0 4 0; +#X connect 4 0 1 0; diff --git a/sc4pd/source/CombL.cpp b/sc4pd/source/CombL.cpp new file mode 100644 index 0000000..9af21ae --- /dev/null +++ b/sc4pd/source/CombL.cpp @@ -0,0 +1,272 @@ +/* sc4pd + CombL~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Butcher/Charles/Doerner: The Contest Of Pleasures + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class CombL_ar : public FeedbackDelay_ar +{ + FLEXT_HEADER(CombL_ar,FeedbackDelay_ar); + + CombL_ar (int argc, t_atom *argv); + ~CombL_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + delay_changed = decay_changed = false; + FeedbackDelay_Reset(); + } + + void m_delay(float f) + { + m_delaytime=f; + delay_changed = true; + } + + void m_decay(float f) + { + m_decaytime=f; + decay_changed = true; + } + +private: + bool delay_changed, decay_changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_delay); + FLEXT_CALLBACK_F(m_decay); +}; + +FLEXT_LIB_DSP_V("CombL~",CombL_ar); + +CombL_ar::CombL_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_delay); + FLEXT_ADDMETHOD_(0,"decaytime",m_decay); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("3 arguments are needed"); + return; + } + + m_maxdelaytime = sc_getfloatarg(Args,0); + m_delaytime = sc_getfloatarg(Args,1); + m_decaytime = sc_getfloatarg(Args,2); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +CombL_ar::~CombL_ar () +{ + DelayUnit_Dtor(); +} + +void CombL_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if (delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + + float zin = ZXP(nin); + if (irdphase < 0) + { + dlybuf[iwrphase & mask] = zin; + ZXP(nout) = 0.f; + } + else if (irdphaseb < 0) + { + float d1 = dlybuf[irdphase & mask]; + float value = d1 - frac * d1; + dlybuf[iwrphase & mask] = zin + feedbk * value; + ZXP(nout) = value; + } + else + { + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + dlybuf[iwrphase & mask] = zin + feedbk * value; + ZXP(nout) = value; + } + + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + for (int i = 0; i!= n;++i) + { + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + + float zin = ZXP(nin); + if (irdphase < 0) + { + dlybuf[iwrphase & mask] = zin; + ZXP(nout) = 0.f; + } + else if (irdphaseb < 0) + { + float d1 = dlybuf[irdphase & mask]; + float value = d1 - frac * d1; + dlybuf[iwrphase & mask] = zin + feedbk * value; + ZXP(nout) = value; + } + else + { + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + dlybuf[iwrphase & mask] = zin + feedbk * value; + ZXP(nout) = value; + } + iwrphase++; + } + + + } + + m_iwrphase = iwrphase; + m_numoutput += n; + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void CombL_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if(delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for(int i=0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + for(int i=0; i!= n;++i) + { + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + iwrphase++; + + } + } + m_iwrphase = iwrphase; +} + +/* todo: CombL for control rate ? */ diff --git a/sc4pd/source/CombN.cpp b/sc4pd/source/CombN.cpp new file mode 100644 index 0000000..9c6f33e --- /dev/null +++ b/sc4pd/source/CombN.cpp @@ -0,0 +1,341 @@ +/* sc4pd + CombN~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Keith Rowe & John Tilbury: Duos For Doris + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class CombN_ar : public FeedbackDelay_ar +{ + FLEXT_HEADER(CombN_ar,FeedbackDelay_ar); + + CombN_ar (int argc, t_atom *argv); + ~CombN_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + delay_changed = decay_changed = false; + FeedbackDelay_Reset(); + } + + void m_delay(float f) + { + m_delaytime=f; + delay_changed = true; + } + + void m_decay(float f) + { + m_decaytime=f; + decay_changed = true; + } + +private: + bool delay_changed, decay_changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_delay); + FLEXT_CALLBACK_F(m_decay); +}; + +FLEXT_LIB_DSP_V("CombN~",CombN_ar); + +CombN_ar::CombN_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_delay); + FLEXT_ADDMETHOD_(0,"decaytime",m_decay); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("3 arguments are needed"); + return; + } + + m_maxdelaytime = sc_getfloatarg(Args,0); + m_delaytime = sc_getfloatarg(Args,1); + m_decaytime = sc_getfloatarg(Args,2); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +CombN_ar::~CombN_ar () +{ + DelayUnit_Dtor(); +} + +void CombN_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if (delay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long irdphase = iwrphase - (long)dsamp; + + if (irdphase < 0) + { + dlybuf[iwrphase & mask] = ZXP(nin); + ZXP(nout) = 0.f; + } + else + { + float value = dlybuf[irdphase & mask]; + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + } + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyN = dlybuf1 + m_idelaylen; + if (decay_changed) + { + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + long remain = n; + while (remain) + { + float* dlyrd = dlybuf1 + (irdphase & mask); + float* dlywr = dlybuf1 + (iwrphase & mask); + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + + if (irdphase < 0) + { + feedbk += nsmps * feedbk_slope; + dlyrd += nsmps; + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = 0.f; + } + } + else + { + for (int i = 0; i!= nsmps;++i) + { + float value = ZXP(dlyrd); + ZXP(dlywr) = value * feedbk + ZXP(nin); + ZXP(nout) = value; + feedbk += feedbk_slope; + } + } + iwrphase += nsmps; + irdphase += nsmps; + } + m_feedbk = feedbk; + decay_changed=false; + } + else + { + long remain = n; + while (remain) + { + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyrd = dlybuf1 + (irdphase & mask); + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + if (irdphase < 0) + { + for (int i = 0; i!= nsmps;++i) + { + ZXP(dlywr) = ZXP(nin); + ZXP(nout) = 0.f; + } + } + else + { + for (int i = 0; i!= nsmps;++i) + { + float value = ZXP(dlyrd); + ZXP(dlywr) = value * feedbk + ZXP(nin); + ZXP(nout) = value; + } + } + iwrphase += nsmps; + irdphase += nsmps; + } + + } + } + + m_iwrphase = iwrphase; + m_numoutput += n; + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void CombN_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if(delay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for(int i=0; i!= n;++i) + { + dsamp += dsamp_slope; + ++iwrphase; + long irdphase = iwrphase - (long)dsamp; + float value = dlybuf[irdphase & mask]; + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + feedbk += feedbk_slope; + + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyrd = dlybuf1 + (irdphase & mask); + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyN = dlybuf1 + m_idelaylen; + + if(decay_changed) + { + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + long remain = n; + while (remain) + { + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + + for(int i=0; i!= nsmps;++i) + { + float value = ZXP(dlyrd); + ZXP(dlywr) = value * feedbk + ZXP(nin); + ZXP(nout) = value; + feedbk += feedbk_slope; + } + if (dlyrd == dlyN) dlyrd = dlybuf1; + if (dlywr == dlyN) dlywr = dlybuf1; + } + m_feedbk = feedbk; + decay_changed = false; + } + else + { + long remain = n; + while (remain) + { + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + + for (int i = 0; i!= nsmps; ++i) + { + float value = ZXP(dlyrd); + ZXP(dlywr) = value * feedbk + ZXP(nin); + ZXP(nout) = value; + } + if (dlyrd == dlyN) dlyrd = dlybuf1; + if (dlywr == dlyN) dlywr = dlybuf1; + } + + } + iwrphase += n; + + + } + m_iwrphase = iwrphase; +} + +/* todo: CombN for control rate ? */ diff --git a/sc4pd/source/DelayC.cpp b/sc4pd/source/DelayC.cpp new file mode 100644 index 0000000..50ab366 --- /dev/null +++ b/sc4pd/source/DelayC.cpp @@ -0,0 +1,287 @@ +/* sc4pd + DelayC~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Tom Cora: Halleluja, Anyway + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class DelayC_ar : private DelayUnit_ar +{ + FLEXT_HEADER(DelayC_ar,DelayUnit_ar); + + DelayC_ar (int argc, t_atom *argv); + ~DelayC_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + changed = false; + DelayUnit_Reset(); + } + + void m_set(float f) + { + m_delaytime=f; + changed = true; + } + +private: + bool changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("DelayC~",DelayC_ar); + +DelayC_ar::DelayC_ar (int argc, t_atom *argv) +{ + + FLEXT_ADDMETHOD_(0,"delaytime",m_set); + + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("2 arguments are needed"); + return; + } + + m_delaytime = sc_getfloatarg(Args,0); + m_maxdelaytime = sc_getfloatarg(Args,1); + + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +DelayC_ar::~DelayC_ar () +{ + DelayUnit_Dtor(); +} + +void DelayC_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + float d0, d1, d2, d3; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + + dlybuf[iwrphase & mask] = ZXP(nin); + if (irdphase0 < 0) + { + ZXP(nout) = 0.f; + } + else + { + if (irdphase1 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + } + else if (irdphase2 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + } + else if (irdphase3 < 0) + { + d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + } + else + { + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + d3 = dlybuf[irdphase3 & mask]; + } + ZXP(nout) = cubicinterp(frac, d0, d1, d2, d3); + } + iwrphase++; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + for (int i = 0; i!= n;++i) + { + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + + dlybuf[iwrphase & mask] = ZXP(nin); + if (irdphase0 < 0) + { + ZXP(nout) = 0.f; + } + else + { + if (irdphase1 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + } + else if (irdphase2 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + } + else if (irdphase3 < 0) + { + d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + } + else + { + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + d3 = dlybuf[irdphase3 & mask]; + } + ZXP(nout) = cubicinterp(frac, d0, d1, d2, d3); + } + iwrphase++; + } + } + + m_iwrphase = iwrphase; + + m_numoutput += n; + + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void DelayC_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dlybuf[iwrphase & mask] = ZXP(nin); + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; + float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; + ZXP(nout) = cubicinterp(frac, d0, d1, d2, d3); + iwrphase++; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + for (int i = 0; i!= n;++i) + { + dlybuf[iwrphase & mask] = ZXP(nin); + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; + float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; + ZXP(nout) = cubicinterp(frac, d0, d1, d2, d3); + iwrphase++; + } + } + m_iwrphase = iwrphase; +} + +/* todo: DelayC for control rate ? */ diff --git a/sc4pd/source/DelayL.cpp b/sc4pd/source/DelayL.cpp new file mode 100644 index 0000000..46b5458 --- /dev/null +++ b/sc4pd/source/DelayL.cpp @@ -0,0 +1,236 @@ +/* sc4pd + DelayL~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Tom Cora: Halleluja, Anyway + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class DelayL_ar : private DelayUnit_ar +{ + FLEXT_HEADER(DelayL_ar,DelayUnit_ar); + + DelayL_ar (int argc, t_atom *argv); + ~DelayL_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + changed = false; + DelayUnit_Reset(); + } + + void m_set(float f) + { + m_delaytime=f; + changed = true; + } + +private: + bool changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("DelayL~",DelayL_ar); + +DelayL_ar::DelayL_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_set); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 2) + { + post("2 arguments are needed"); + return; + } + + m_delaytime = sc_getfloatarg(Args,0); + m_maxdelaytime = sc_getfloatarg(Args,1); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +DelayL_ar::~DelayL_ar () +{ + DelayUnit_Dtor(); +} + +void DelayL_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + + dlybuf[iwrphase & mask] = ZXP(nin); + if (irdphase < 0) + { + ZXP(nout) = 0.f; + } + else if (irdphaseb < 0) + { + float d1 = dlybuf[irdphase & mask]; + ZXP(nout) = d1 - frac * d1; + } + else + { + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + ZXP(nout) = lininterp(frac, d1, d2); + } + iwrphase++; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + for (int i = 0; i!= n;++i) + { + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + + dlybuf[iwrphase & mask] = ZXP(nin); + if (irdphase < 0) + { + ZXP(nout) = 0.f; + } + else if (irdphaseb < 0) + { + float d1 = dlybuf[irdphase & mask]; + ZXP(nout) = d1 - frac * d1; + } + else + { + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + ZXP(nout) = lininterp(frac, d1, d2); + } + iwrphase++; + } + } + + m_iwrphase = iwrphase; + + m_numoutput += n; + + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void DelayL_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + long mask = m_mask; + + if (changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + for (int i = 0; i!= n;++i) + { + dlybuf[iwrphase & mask] = ZXP(nin); + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + ZXP(nout) = lininterp(frac, d1, d2); + iwrphase++; + } + m_dsamp = dsamp; + changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + for (int i = 0; i!= n;++i) + { + dlybuf[iwrphase & mask] = ZXP(nin); + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + ZXP(nout) = lininterp(frac, d1, d2); + iwrphase++; + } + + } + m_iwrphase = iwrphase; +} + +/* todo: DelayL for control rate ? */ diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp index 5b11f96..45b05d5 100644 --- a/sc4pd/source/DelayUnit.cpp +++ b/sc4pd/source/DelayUnit.cpp @@ -30,8 +30,7 @@ http://www.parasitaere-kapazitaeten.net/ext SuperCollider by James McCartney http://www.audiosynth.com - - Coded while listening to: + Coded while listening to: */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 126cf50..79e67a9 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -60,7 +60,7 @@ void sc4pd_library_setup() " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" " Integrator(~), Decay~, Decay2~, Lag~, Lag2~, LinExp(~), " "DelayN~,\n" - " DelayL~, DelayC~" + " DelayL~, DelayC~, CombN~, CombL~" ); //initialize objects @@ -213,6 +213,10 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(DelayL_ar); FLEXT_DSP_SETUP(DelayC_ar); + + FLEXT_DSP_SETUP(CombN_ar); + + FLEXT_DSP_SETUP(CombL_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 656b72dd1a85069ad57351147553e07226a990b6 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 4 Aug 2004 18:23:15 +0000 Subject: some allpass delay lines svn path=/trunk/externals/tb/; revision=1909 --- sc4pd/make-files.txt | 3 +- sc4pd/makefile.pd-linux | 2 +- sc4pd/pd/allpassc.pd | 20 +++ sc4pd/pd/allpassl.pd | 20 +++ sc4pd/pd/allpassn.pd | 20 +++ sc4pd/source/AllpassC.cpp | 315 +++++++++++++++++++++++++++++++++++++++++ sc4pd/source/AllpassL.cpp | 276 ++++++++++++++++++++++++++++++++++++ sc4pd/source/AllpassN.cpp | 348 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 13 +- 9 files changed, 1014 insertions(+), 3 deletions(-) create mode 100644 sc4pd/pd/allpassc.pd create mode 100644 sc4pd/pd/allpassl.pd create mode 100644 sc4pd/pd/allpassn.pd create mode 100644 sc4pd/source/AllpassC.cpp create mode 100644 sc4pd/source/AllpassL.cpp create mode 100644 sc4pd/source/AllpassN.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 99913e7..3f9038d 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -11,4 +11,5 @@ SRCS= \ difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ - DelayC.cpp CombN.cpp CombL.cpp + DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ + AllpassC.cpp diff --git a/sc4pd/makefile.pd-linux b/sc4pd/makefile.pd-linux index fc55ec6..99d62ef 100644 --- a/sc4pd/makefile.pd-linux +++ b/sc4pd/makefile.pd-linux @@ -45,7 +45,7 @@ TARGET=$(TARGDIR)/$(NAME).pd_linux all: $(TARGDIR) $(TARGET) $(patsubst %,$(SRCDIR)/%,$(SRCS)): $(patsubst %,$(SRCDIR)/%,$(HDRS)) $(MAKEFILE) $(CONFIG) - touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) +# touch $(patsubst %,$(SRCDIR)/%,$(SRCS)) $(TARGDIR): -mkdir $(TARGDIR) diff --git a/sc4pd/pd/allpassc.pd b/sc4pd/pd/allpassc.pd new file mode 100644 index 0000000..297cb91 --- /dev/null +++ b/sc4pd/pd/allpassc.pd @@ -0,0 +1,20 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 111 190 print~; +#X obj 128 170 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 316 107 decaytime \$1; +#X obj 77 138 AllpassC~ 1 0.001 0.2; +#X obj 79 57 Dust~ 55; +#X connect 0 0 2 0; +#X connect 2 0 7 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 7 0; +#X connect 7 0 1 0; +#X connect 7 0 1 1; +#X connect 7 0 3 0; +#X connect 8 0 7 0; diff --git a/sc4pd/pd/allpassl.pd b/sc4pd/pd/allpassl.pd new file mode 100644 index 0000000..e2f3251 --- /dev/null +++ b/sc4pd/pd/allpassl.pd @@ -0,0 +1,20 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 111 190 print~; +#X obj 128 170 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 316 107 decaytime \$1; +#X obj 79 57 Dust~ 4; +#X obj 77 138 AllpassL~ 1 0.001 0.2; +#X connect 0 0 2 0; +#X connect 2 0 8 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 1 1; +#X connect 8 0 3 0; diff --git a/sc4pd/pd/allpassn.pd b/sc4pd/pd/allpassn.pd new file mode 100644 index 0000000..c0406b9 --- /dev/null +++ b/sc4pd/pd/allpassn.pd @@ -0,0 +1,20 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 111 190 print~; +#X obj 128 170 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 316 107 decaytime \$1; +#X obj 77 138 AllpassN~ 1 0.001 0.2; +#X obj 79 57 Dust~ 4; +#X connect 0 0 2 0; +#X connect 2 0 7 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 7 0; +#X connect 7 0 1 0; +#X connect 7 0 1 1; +#X connect 7 0 3 0; +#X connect 8 0 7 0; diff --git a/sc4pd/source/AllpassC.cpp b/sc4pd/source/AllpassC.cpp new file mode 100644 index 0000000..72c05f5 --- /dev/null +++ b/sc4pd/source/AllpassC.cpp @@ -0,0 +1,315 @@ +/* sc4pd + AllpassC~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Rashid Ali & Frank Lowe: Duo Exchange + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class AllpassC_ar : public FeedbackDelay_ar +{ + FLEXT_HEADER(AllpassC_ar,FeedbackDelay_ar); + + AllpassC_ar (int argc, t_atom *argv); + ~AllpassC_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + delay_changed = decay_changed = false; + FeedbackDelay_Reset(); + } + + void m_delay(float f) + { + m_delaytime=f; + delay_changed = true; + } + + void m_decay(float f) + { + m_decaytime=f; + decay_changed = true; + } + +private: + bool delay_changed, decay_changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_delay); + FLEXT_CALLBACK_F(m_decay); +}; + +FLEXT_LIB_DSP_V("AllpassC~",AllpassC_ar); + +AllpassC_ar::AllpassC_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_delay); + FLEXT_ADDMETHOD_(0,"decaytime",m_decay); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("3 arguments are needed"); + return; + } + + m_maxdelaytime = sc_getfloatarg(Args,0); + m_delaytime = sc_getfloatarg(Args,1); + m_decaytime = sc_getfloatarg(Args,2); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +AllpassC_ar::~AllpassC_ar () +{ + DelayUnit_Dtor(); +} + +void AllpassC_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + float d0, d1, d2, d3; + + if (delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + + if (irdphase0 < 0) + { + dlybuf[iwrphase & mask] = ZXP(nin); + ZXP(nout) = 0.f; + } + else + { + if (irdphase1 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + } + else if (irdphase2 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + } + else if (irdphase3 < 0) + { + d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + } + else + { + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + d3 = dlybuf[irdphase3 & mask]; + } + float value = cubicinterp(frac, d0, d1, d2, d3); + float dwr = ZXP(nin) + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + for (int i = 0; i!= n;++i) + { + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + + if (irdphase0 < 0) + { + dlybuf[iwrphase & mask] = ZXP(nin); + ZXP(nout) = 0.f; + } + else + { + if (irdphase1 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + } + else if (irdphase2 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + } + else if (irdphase3 < 0) + { + d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + } + else + { + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + d3 = dlybuf[irdphase3 & mask]; + } + float value = cubicinterp(frac, d0, d1, d2, d3); + float dwr = ZXP(nin) + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + iwrphase++; + } + } + + m_iwrphase = iwrphase; + m_numoutput += n; + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void AllpassC_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + float d0, d1, d2, d3; + + if(delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for(int i=0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; + float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; + float value = cubicinterp(frac, d0, d1, d2, d3); + float dwr = ZXP(nin) + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + for(int i=0; i!= n;++i) + { + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; + float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; + float value = cubicinterp(frac, d0, d1, d2, d3); + float dwr = ZXP(nin) + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + iwrphase++; + } + } + m_iwrphase = iwrphase; +} + +/* todo: AllpassC for control rate ? */ diff --git a/sc4pd/source/AllpassL.cpp b/sc4pd/source/AllpassL.cpp new file mode 100644 index 0000000..2353df3 --- /dev/null +++ b/sc4pd/source/AllpassL.cpp @@ -0,0 +1,276 @@ +/* sc4pd + AllpassL~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Rashid Ali & Frank Lowe: Duo Exchange + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class AllpassL_ar : public FeedbackDelay_ar +{ + FLEXT_HEADER(AllpassL_ar,FeedbackDelay_ar); + + AllpassL_ar (int argc, t_atom *argv); + ~AllpassL_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + delay_changed = decay_changed = false; + FeedbackDelay_Reset(); + } + + void m_delay(float f) + { + m_delaytime=f; + delay_changed = true; + } + + void m_decay(float f) + { + m_decaytime=f; + decay_changed = true; + } + +private: + bool delay_changed, decay_changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_delay); + FLEXT_CALLBACK_F(m_decay); +}; + +FLEXT_LIB_DSP_V("AllpassL~",AllpassL_ar); + +AllpassL_ar::AllpassL_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_delay); + FLEXT_ADDMETHOD_(0,"decaytime",m_decay); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("3 arguments are needed"); + return; + } + + m_maxdelaytime = sc_getfloatarg(Args,0); + m_delaytime = sc_getfloatarg(Args,1); + m_decaytime = sc_getfloatarg(Args,2); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +AllpassL_ar::~AllpassL_ar () +{ + DelayUnit_Dtor(); +} + +void AllpassL_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if (delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + + float zin = ZXP(nin); + if (irdphase < 0) + { + dlybuf[iwrphase & mask] = zin; + ZXP(nout) = - feedbk * zin; //check: probably a bug = 0? + } + else if (irdphaseb < 0) + { + float d1 = dlybuf[irdphase & mask]; + float value = d1 - frac * d1; + float dwr = zin + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + else + { + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + float dwr = zin + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + float zin = ZXP(nin); + for (int i = 0; i!= n;++i) + { + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + + float zin = ZXP(nin); + if (irdphase < 0) + { + dlybuf[iwrphase & mask] = zin; + ZXP(nout) = - feedbk * zin; + } + else if (irdphaseb < 0) + { + float d1 = dlybuf[irdphase & mask]; + float value = d1 - frac * d1; + float dwr = zin + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + else + { + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + float dwr = zin + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + iwrphase++; + } + } + + m_iwrphase = iwrphase; + m_numoutput += n; + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void AllpassL_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if(delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for(int i=0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + float dwr = ZXP(nin) + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + for(int i=0; i!= n;++i) + { + long irdphase = iwrphase - idsamp; + long irdphaseb = irdphase - 1; + float d1 = dlybuf[irdphase & mask]; + float d2 = dlybuf[irdphaseb & mask]; + float value = lininterp(frac, d1, d2); + float dwr = ZXP(nin) + feedbk * value; + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + iwrphase++; + } + } + m_iwrphase = iwrphase; +} + +/* todo: AllpassL for control rate ? */ diff --git a/sc4pd/source/AllpassN.cpp b/sc4pd/source/AllpassN.cpp new file mode 100644 index 0000000..a03130b --- /dev/null +++ b/sc4pd/source/AllpassN.cpp @@ -0,0 +1,348 @@ +/* sc4pd + AllpassN~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Efzeg: Boogie + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class AllpassN_ar : public FeedbackDelay_ar +{ + FLEXT_HEADER(AllpassN_ar,FeedbackDelay_ar); + + AllpassN_ar (int argc, t_atom *argv); + ~AllpassN_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + delay_changed = decay_changed = false; + FeedbackDelay_Reset(); + } + + void m_delay(float f) + { + m_delaytime=f; + delay_changed = true; + } + + void m_decay(float f) + { + m_decaytime=f; + decay_changed = true; + } + +private: + bool delay_changed, decay_changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_delay); + FLEXT_CALLBACK_F(m_decay); +}; + +FLEXT_LIB_DSP_V("AllpassN~",AllpassN_ar); + +AllpassN_ar::AllpassN_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_delay); + FLEXT_ADDMETHOD_(0,"decaytime",m_decay); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("3 arguments are needed"); + return; + } + + m_maxdelaytime = sc_getfloatarg(Args,0); + m_delaytime = sc_getfloatarg(Args,1); + m_decaytime = sc_getfloatarg(Args,2); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +AllpassN_ar::~AllpassN_ar () +{ + DelayUnit_Dtor(); +} + +void AllpassN_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if (delay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long irdphase = iwrphase - (long)dsamp; + + if (irdphase < 0) + { + float dwr = ZXP(nin); + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = -feedbk * dwr; + } + else + { + float value = dlybuf[irdphase & mask]; + float dwr = feedbk * value + ZXP(nin); + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + } + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyN = dlybuf1 + m_idelaylen; + if (decay_changed) + { + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + long remain = n; + while (remain) + { + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyrd = dlybuf1 + (irdphase & mask); + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + if (irdphase < 0) + { + dlyrd += nsmps; + for (int i = 0; i!= nsmps;++i) + { + float dwr = ZXP(nin); + ZXP(dlywr) = dwr; + ZXP(nout) = -feedbk * dwr; + feedbk += feedbk_slope; + } + } + else + { + for (int i = 0; i!= nsmps;++i) + { + float x1 = ZXP(dlyrd); + float dwr = x1 * feedbk + ZXP(nin); + ZXP(dlywr) = dwr; + ZXP(nout) = x1 - feedbk * dwr; + feedbk += feedbk_slope; + } + } + iwrphase += nsmps; + irdphase += nsmps; + } + decay_changed=false; + } + else + { + long remain = n; + while (remain) + { + float* dlyrd = dlybuf1 + (irdphase & mask); + float* dlywr = dlybuf1 + (iwrphase & mask); + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + + if (irdphase < 0) + { + feedbk = -feedbk; + for (int i = 0; i!= nsmps;++i) + { + float dwr = ZXP(nin); + ZXP(dlywr) = dwr; + ZXP(nout) = feedbk * dwr; + } + feedbk = -feedbk; + } + else + { + for (int i = 0; i!= nsmps;++i) + { + float x1 = ZXP(dlyrd); + float dwr = x1 * feedbk + ZXP(nin); + ZXP(dlywr) = dwr; + ZXP(nout) = x1 - feedbk * dwr; + } + } + iwrphase += nsmps; + irdphase += nsmps; + } + m_feedbk = feedbk; + } + } + + m_iwrphase = iwrphase; + m_numoutput += n; + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void AllpassN_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + + if(delay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for(int i=0; i!= n;++i) + { + dsamp += dsamp_slope; + ++iwrphase; + long irdphase = iwrphase - (long)dsamp; + float value = dlybuf[irdphase & mask]; + float dwr = value * feedbk + ZXP(nin); + dlybuf[iwrphase & mask] = dwr; + ZXP(nout) = value - feedbk * dwr; + feedbk += feedbk_slope; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long irdphase = iwrphase - (long)dsamp; + float* dlybuf1 = dlybuf - ZOFF; + float* dlyrd = dlybuf1 + (irdphase & mask); + float* dlywr = dlybuf1 + (iwrphase & mask); + float* dlyN = dlybuf1 + m_idelaylen; + + if(decay_changed) + { + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + long remain = n; + while (remain) + { + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + + for(int i=0; i!= nsmps;++i) + { + float value = ZXP(dlyrd); + float dwr = value * feedbk + ZXP(nin); + ZXP(dlywr) = dwr; + ZXP(nout) = value - feedbk * dwr; + feedbk += feedbk_slope; + } + if (dlyrd == dlyN) dlyrd = dlybuf1; + if (dlywr == dlyN) dlywr = dlybuf1; + } + m_feedbk = feedbk; + decay_changed = false; + } + else + { + long remain = n; + while (remain) + { + long rdspace = dlyN - dlyrd; + long wrspace = dlyN - dlywr; + long nsmps = sc_min(rdspace, wrspace); + nsmps = sc_min(remain, nsmps); + remain -= nsmps; + + for (int i = 0; i!= nsmps; ++i) + { + float value = ZXP(dlyrd); + float dwr = value * feedbk + ZXP(nin); + ZXP(dlywr) = dwr; + ZXP(nout) = value - feedbk * dwr; + } + if (dlyrd == dlyN) dlyrd = dlybuf1; + if (dlywr == dlyN) dlywr = dlybuf1; + } + + } + iwrphase += n; + } + m_iwrphase = iwrphase; +} + +/* todo: AllpassN for control rate ? */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 79e67a9..77a620c 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -60,7 +60,10 @@ void sc4pd_library_setup() " sqrsum(~), absdif(~), LFSaw(~), LFPulse(~), Impulse(~),\n" " Integrator(~), Decay~, Decay2~, Lag~, Lag2~, LinExp(~), " "DelayN~,\n" - " DelayL~, DelayC~, CombN~, CombL~" + " DelayL~, DelayC~, CombN~, CombL~, CombC~, AllpassN~, " + "AllpassL~,\n" + " AllpassC~" + "\n" ); //initialize objects @@ -217,6 +220,14 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(CombN_ar); FLEXT_DSP_SETUP(CombL_ar); + + FLEXT_DSP_SETUP(CombC_ar); + + FLEXT_DSP_SETUP(AllpassN_ar); + + FLEXT_DSP_SETUP(AllpassL_ar); + + FLEXT_DSP_SETUP(AllpassC_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 7aeb7943f00f3331868fdefa082df504e4cd11cd Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 4 Aug 2004 18:50:54 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1910 --- sc4pd/pd/combc.pd | 20 ++++ sc4pd/source/CombC.cpp | 314 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 334 insertions(+) create mode 100644 sc4pd/pd/combc.pd create mode 100644 sc4pd/source/CombC.cpp diff --git a/sc4pd/pd/combc.pd b/sc4pd/pd/combc.pd new file mode 100644 index 0000000..4baf6ef --- /dev/null +++ b/sc4pd/pd/combc.pd @@ -0,0 +1,20 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X msg 185 88 delaytime \$1; +#X obj 111 190 print~; +#X obj 128 170 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 316 107 decaytime \$1; +#X obj 79 57 WhiteNoise~; +#X obj 77 138 CombN~ 1 0.001 0.2; +#X connect 0 0 2 0; +#X connect 2 0 8 0; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 1 1; +#X connect 8 0 3 0; diff --git a/sc4pd/source/CombC.cpp b/sc4pd/source/CombC.cpp new file mode 100644 index 0000000..bed7384 --- /dev/null +++ b/sc4pd/source/CombC.cpp @@ -0,0 +1,314 @@ +/* sc4pd + CombC~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Butcher/Charles/Doerner: The Contest Of Pleasures + +*/ + +#include "sc4pd.hpp" +#include "DelayUnit.hpp" + +class CombC_ar : public FeedbackDelay_ar +{ + FLEXT_HEADER(CombC_ar,FeedbackDelay_ar); + + CombC_ar (int argc, t_atom *argv); + ~CombC_ar (); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + delay_changed = decay_changed = false; + FeedbackDelay_Reset(); + } + + void m_delay(float f) + { + m_delaytime=f; + delay_changed = true; + } + + void m_decay(float f) + { + m_decaytime=f; + decay_changed = true; + } + +private: + bool delay_changed, decay_changed; + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_delay); + FLEXT_CALLBACK_F(m_decay); +}; + +FLEXT_LIB_DSP_V("CombC~",CombC_ar); + +CombC_ar::CombC_ar (int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"delaytime",m_delay); + FLEXT_ADDMETHOD_(0,"decaytime",m_decay); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count() != 3) + { + post("3 arguments are needed"); + return; + } + + m_maxdelaytime = sc_getfloatarg(Args,0); + m_delaytime = sc_getfloatarg(Args,1); + m_decaytime = sc_getfloatarg(Args,2); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + + AddOutSignal(); +} + +CombC_ar::~CombC_ar () +{ + DelayUnit_Dtor(); +} + +void CombC_ar::m_signal_z(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + float d0, d1, d2, d3; + + if (delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for (int i = 0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + + + if (irdphase0 < 0) + { + dlybuf[iwrphase & mask] = ZXP(nin); + ZXP(nout) = 0.f; + } + else + { + if (irdphase1 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + } + else if (irdphase2 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + } + else if (irdphase3 < 0) + { + d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + } + else + { + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + d3 = dlybuf[irdphase3 & mask]; + } + float value = cubicinterp(frac, d0, d1, d2, d3); + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + } + + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + for (int i = 0; i!= n;++i) + { + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + + if (irdphase0 < 0) + { + dlybuf[iwrphase & mask] = ZXP(nin); + ZXP(nout) = 0.f; + } + else + { + if (irdphase1 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + } + else if (irdphase2 < 0) + { + d1 = d2 = d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + } + else if (irdphase3 < 0) + { + d3 = 0.f; + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + } + else + { + d0 = dlybuf[irdphase0 & mask]; + d1 = dlybuf[irdphase1 & mask]; + d2 = dlybuf[irdphase2 & mask]; + d3 = dlybuf[irdphase3 & mask]; + } + float value = cubicinterp(frac, d0, d1, d2, d3); + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + } + iwrphase++; + } + } + + m_iwrphase = iwrphase; + m_numoutput += n; + if (m_numoutput >= m_idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_)); + } +} + +void CombC_ar::m_signal_(int n, t_sample *const *in, t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float *dlybuf = m_dlybuf; + long iwrphase = m_iwrphase; + float dsamp = m_dsamp; + float feedbk = m_feedbk; + long mask = m_mask; + float d0, d1, d2, d3; + + if(delay_changed || decay_changed) + { + float next_dsamp = CalcDelay(m_delaytime); + float dsamp_slope = CALCSLOPE(next_dsamp, dsamp); + + float next_feedbk = CalcFeedback(m_delaytime, m_decaytime); + float feedbk_slope = CALCSLOPE(next_feedbk, feedbk); + + for(int i=0; i!= n;++i) + { + dsamp += dsamp_slope; + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; + float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; + float value = cubicinterp(frac, d0, d1, d2, d3); + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + feedbk += feedbk_slope; + iwrphase++; + } + m_feedbk = feedbk; + m_dsamp = dsamp; + delay_changed = decay_changed = false; + } + else + { + long idsamp = (long)dsamp; + float frac = dsamp - idsamp; + + for(int i=0; i!= n;++i) + { + long irdphase1 = iwrphase - idsamp; + long irdphase2 = irdphase1 - 1; + long irdphase3 = irdphase1 - 2; + long irdphase0 = irdphase1 + 1; + float d0 = dlybuf[irdphase0 & mask]; + float d1 = dlybuf[irdphase1 & mask]; + float d2 = dlybuf[irdphase2 & mask]; + float d3 = dlybuf[irdphase3 & mask]; + float value = cubicinterp(frac, d0, d1, d2, d3); + dlybuf[iwrphase & mask] = ZXP(nin) + feedbk * value; + ZXP(nout) = value; + iwrphase++; + } + } + m_iwrphase = iwrphase; +} + +/* todo: CombC for control rate ? */ -- cgit v1.2.1 From 305c08085dc742d591640f0078638b44878103be Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 6 Aug 2004 08:34:42 +0000 Subject: checkin of PitchShift~ svn path=/trunk/externals/tb/; revision=1911 --- sc4pd/make-files.txt | 2 +- sc4pd/source/PitchShift.cpp | 638 ++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 2 +- 3 files changed, 640 insertions(+), 2 deletions(-) create mode 100644 sc4pd/source/PitchShift.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 3f9038d..3dc0de4 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -12,4 +12,4 @@ SRCS= \ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ - AllpassC.cpp + AllpassC.cpp PitchShift.cpp diff --git a/sc4pd/source/PitchShift.cpp b/sc4pd/source/PitchShift.cpp new file mode 100644 index 0000000..d182681 --- /dev/null +++ b/sc4pd/source/PitchShift.cpp @@ -0,0 +1,638 @@ +/* sc4pd + PitchShift~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ PitchShift~ -----------------------------*/ + +class PitchShift_ar + :public flext_dsp +{ + FLEXT_HEADER(PitchShift_ar,flext_dsp); + +public: + PitchShift_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_set_windowsize(float f) + { + m_windowsize = f; + } + + void m_set_pitchratio (float f) + { + m_pitchratio = f; + } + + void m_set_pitchdispersion (float f) + { + m_pitchdispersion = f; + } + + void m_set_timedispersion (float f) + { + m_timedispersion = f; + } + +private: + float m_windowsize, m_pitchratio,m_pitchdispersion,m_timedispersion; + RGen rgen; + + + float *m_dlybuf; + float m_dsamp1, m_dsamp1_slope, m_ramp1, m_ramp1_slope; + float m_dsamp2, m_dsamp2_slope, m_ramp2, m_ramp2_slope; + float m_dsamp3, m_dsamp3_slope, m_ramp3, m_ramp3_slope; + float m_dsamp4, m_dsamp4_slope, m_ramp4, m_ramp4_slope; + float m_fdelaylen, m_slope; + long m_iwrphase, m_idelaylen, m_mask; + long m_counter, m_stage, m_numoutput, m_framesize; + + DEFSIGCALL(m_signal_fun); + DEFSIGFUN(m_signal_); + DEFSIGFUN(m_signal_z); + + FLEXT_CALLBACK_F(m_set_windowsize); + FLEXT_CALLBACK_F(m_set_pitchratio); + FLEXT_CALLBACK_F(m_set_pitchdispersion); + FLEXT_CALLBACK_F(m_set_timedispersion); +}; + +FLEXT_LIB_DSP_V("PitchShift~",PitchShift_ar); + +PitchShift_ar::PitchShift_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"windowSize",m_set_windowsize); + FLEXT_ADDMETHOD_(0,"pitchRatio",m_set_pitchratio); + FLEXT_ADDMETHOD_(0,"pitchDispersion",m_set_pitchdispersion); + FLEXT_ADDMETHOD_(0,"timeDispersion",m_set_timedispersion); + + AtomList Args(argc,argv); + + if (Args.Count() != 4) + { + post("4 arguments needed"); + return; + } + m_windowsize = sc_getfloatarg(Args,0); + m_pitchratio = sc_getfloatarg(Args,1); + m_pitchdispersion = sc_getfloatarg(Args,2); + m_timedispersion = sc_getfloatarg(Args,3); + + rgen.init(timeseed()); + + AddOutSignal(); + + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); +} + +void PitchShift_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) +{ + /* initialization from PitchShift_Ctor(PitchShift *unit) */ + + long delaybufsize; + float /* *out, *in,*/ *dlybuf; + float winsize, pchratio; + float fdelaylen, slope; + long framesize, last; + + //out = ZOUT(0); + //in = ZIN(0); + pchratio = m_pitchratio; + winsize = m_windowsize; + + delaybufsize = (long)ceil(winsize * SAMPLERATE * 3.f + 3.f); + fdelaylen = delaybufsize - 3; + + delaybufsize = delaybufsize + BUFLENGTH; + delaybufsize = NEXTPOWEROFTWO(delaybufsize); // round up to next power of two + dlybuf = new float[delaybufsize]; + //(float*)RTAlloc(unit->mWorld, delaybufsize * sizeof(float)); + + *dlybuf = 0; + + m_dlybuf = dlybuf; + m_idelaylen = delaybufsize; + m_fdelaylen = fdelaylen; + m_iwrphase = 0; + m_numoutput = 0; + m_mask = last = (delaybufsize - 1); + + m_framesize = framesize = ((long)(winsize * SAMPLERATE) + 2) & ~3; + m_slope = slope = 2.f / framesize; + m_stage = 3; + m_counter = framesize >> 2; + m_ramp1 = 0.5; + m_ramp2 = 1.0; + m_ramp3 = 0.5; + m_ramp4 = 0.0; + + m_ramp1_slope = -slope; + m_ramp2_slope = -slope; + m_ramp3_slope = slope; + m_ramp4_slope = slope; + + dlybuf[last ] = 0.f; // put a few zeroes where we start the read heads + dlybuf[last-1] = 0.f; + dlybuf[last-2] = 0.f; + + m_numoutput = 0; + + // start all read heads 2 samples behind the write head + m_dsamp1 = m_dsamp2 = m_dsamp3 = m_dsamp4 = 2.f; + // pch ratio is initially zero for the read heads + m_dsamp1_slope = m_dsamp2_slope = m_dsamp3_slope = m_dsamp4_slope = 1.f; +} + + +void PitchShift_ar::m_signal_z(int n, t_sample *const *in, + t_sample *const *out) +{ + + float *nout, *nin, *dlybuf; + float disppchratio, pchratio, pchratio1, value; + float dsamp1, dsamp1_slope, ramp1, ramp1_slope; + float dsamp2, dsamp2_slope, ramp2, ramp2_slope; + float dsamp3, dsamp3_slope, ramp3, ramp3_slope; + float dsamp4, dsamp4_slope, ramp4, ramp4_slope; + float fdelaylen, d1, d2, frac, slope, samp_slope, startpos, + winsize, pchdisp, timedisp; + long remain, nsmps, idelaylen, irdphase, irdphaseb, iwrphase; + long mask, idsamp; + long counter, stage, framesize, numoutput; + + RGET; + + nout = *out; + nin = *in; + + pchratio = m_pitchratio; + winsize = m_windowsize; + pchdisp = m_pitchdispersion; + timedisp = m_timedispersion; + timedisp = sc_clip(timedisp, 0.f, winsize) * SAMPLERATE; + + dlybuf = m_dlybuf; + fdelaylen = m_fdelaylen; + idelaylen = m_idelaylen; + iwrphase = m_iwrphase; + numoutput = m_numoutput; + + counter = m_counter; + stage = m_stage; + mask = m_mask; + framesize = m_framesize; + + dsamp1 = m_dsamp1; + dsamp2 = m_dsamp2; + dsamp3 = m_dsamp3; + dsamp4 = m_dsamp4; + + dsamp1_slope = m_dsamp1_slope; + dsamp2_slope = m_dsamp2_slope; + dsamp3_slope = m_dsamp3_slope; + dsamp4_slope = m_dsamp4_slope; + + ramp1 = m_ramp1; + ramp2 = m_ramp2; + ramp3 = m_ramp3; + ramp4 = m_ramp4; + + ramp1_slope = m_ramp1_slope; + ramp2_slope = m_ramp2_slope; + ramp3_slope = m_ramp3_slope; + ramp4_slope = m_ramp4_slope; + + slope = m_slope; + + remain = n; + while (remain) + { + if (counter <= 0) + { + counter = framesize >> 2; + m_stage = stage = (stage + 1) & 3; + disppchratio = pchratio; + if (pchdisp != 0.f) + { + disppchratio += (pchdisp * frand2(s1,s2,s3)); + } + disppchratio = sc_clip(disppchratio, 0.f, 4.f); + pchratio1 = disppchratio - 1.f; + samp_slope = -pchratio1; + startpos = pchratio1 < 0.f ? 2.f : framesize * pchratio1 + 2.f; + startpos += (timedisp * frand(s1,s2,s3)); + switch(stage) + { + case 0 : + m_dsamp1_slope = dsamp1_slope = samp_slope; + dsamp1 = startpos; + ramp1 = 0.0; + m_ramp1_slope = ramp1_slope = slope; + m_ramp3_slope = ramp3_slope = -slope; + break; + case 1 : + m_dsamp2_slope = dsamp2_slope = samp_slope; + dsamp2 = startpos; + ramp2 = 0.0; + m_ramp2_slope = ramp2_slope = slope; + m_ramp4_slope = ramp4_slope = -slope; + break; + case 2 : + m_dsamp3_slope = dsamp3_slope = samp_slope; + dsamp3 = startpos; + ramp3 = 0.0; + m_ramp3_slope = ramp3_slope = slope; + m_ramp1_slope = ramp1_slope = -slope; + break; + case 3 : + m_dsamp4_slope = dsamp4_slope = samp_slope; + dsamp4 = startpos; + ramp4 = 0.0; + m_ramp2_slope = ramp2_slope = -slope; + m_ramp4_slope = ramp4_slope = slope; + break; + } + } + nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + while (nsmps--) { + numoutput++; + iwrphase = (iwrphase + 1) & mask; + + dsamp1 += dsamp1_slope; + idsamp = (long)dsamp1; + frac = dsamp1 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + if (numoutput < idelaylen) + { + if (irdphase > iwrphase) + { + value = 0.f; + } + else if (irdphaseb > iwrphase) + { + d1 = dlybuf[irdphase]; + value = (d1 - frac * d1) * ramp1; + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value = (d1 + frac * (d2 - d1)) * ramp1; + } + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value = (d1 + frac * (d2 - d1)) * ramp1; + } + ramp1 += ramp1_slope; + + dsamp2 += dsamp2_slope; + idsamp = (long)dsamp2; + frac = dsamp2 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + if (numoutput < idelaylen) + { + if (irdphase > iwrphase) + { + //value += 0.f; + } + else if (irdphaseb > iwrphase) + { + d1 = dlybuf[irdphase]; + value += (d1 - frac * d1) * ramp2; + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp2; + + } + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp2; + } + ramp2 += ramp2_slope; + + dsamp3 += dsamp3_slope; + idsamp = (long)dsamp3; + frac = dsamp3 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + if (numoutput < idelaylen) + { + if (irdphase > iwrphase) + { + //value += 0.f; + } + else if (irdphaseb > iwrphase) + { + d1 = dlybuf[irdphase]; + value += (d1 - frac * d1) * ramp3; + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp3; + } + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp3; + } + ramp3 += ramp3_slope; + + dsamp4 += dsamp4_slope; + idsamp = (long)dsamp4; + frac = dsamp4 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + + if (numoutput < idelaylen) + { + if (irdphase > iwrphase) + { + //value += 0.f; + } else if (irdphaseb > iwrphase) { + d1 = dlybuf[irdphase]; + value += (d1 - frac * d1) * ramp4; + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp4; + } + } + else + { + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp4; + } + ramp4 += ramp4_slope; + + dlybuf[iwrphase] = ZXP(nin); + ZXP(nout) = value *= 0.5; + } + } + + m_counter = counter; + m_stage = stage; + m_mask = mask; + + m_dsamp1 = dsamp1; + m_dsamp2 = dsamp2; + m_dsamp3 = dsamp3; + m_dsamp4 = dsamp4; + + m_ramp1 = ramp1; + m_ramp2 = ramp2; + m_ramp3 = ramp3; + m_ramp4 = ramp4; + + m_numoutput = numoutput; + m_iwrphase = iwrphase; + + if (numoutput >= idelaylen) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_z)); + } + RPUT; +} + +void PitchShift_ar::m_signal_(int n, t_sample *const *in, + t_sample *const *out) +{ + float *nout, *nin, *dlybuf; + float disppchratio, pchratio, pchratio1, value; + float dsamp1, dsamp1_slope, ramp1, ramp1_slope; + float dsamp2, dsamp2_slope, ramp2, ramp2_slope; + float dsamp3, dsamp3_slope, ramp3, ramp3_slope; + float dsamp4, dsamp4_slope, ramp4, ramp4_slope; + float fdelaylen, d1, d2, frac, slope, samp_slope, startpos, + winsize, pchdisp, timedisp; + long remain, nsmps, idelaylen, irdphase, irdphaseb, iwrphase, mask, idsamp; + long counter, stage, framesize; + + RGET; + + nout = *out; + nin = *in; + + pchratio = m_pitchratio; + winsize = m_windowsize; + pchdisp = m_pitchdispersion; + timedisp = m_timedispersion; + + timedisp = sc_clip(timedisp, 0.f, winsize) * SAMPLERATE; + + dlybuf = m_dlybuf; + fdelaylen = m_fdelaylen; + idelaylen = m_idelaylen; + iwrphase = m_iwrphase; + + counter = m_counter; + stage = m_stage; + mask = m_mask; + framesize = m_framesize; + + dsamp1 = m_dsamp1; + dsamp2 = m_dsamp2; + dsamp3 = m_dsamp3; + dsamp4 = m_dsamp4; + + dsamp1_slope = m_dsamp1_slope; + dsamp2_slope = m_dsamp2_slope; + dsamp3_slope = m_dsamp3_slope; + dsamp4_slope = m_dsamp4_slope; + + ramp1 = m_ramp1; + ramp2 = m_ramp2; + ramp3 = m_ramp3; + ramp4 = m_ramp4; + + ramp1_slope = m_ramp1_slope; + ramp2_slope = m_ramp2_slope; + ramp3_slope = m_ramp3_slope; + ramp4_slope = m_ramp4_slope; + + slope = m_slope; + + remain = n; + while (remain) + { + if (counter <= 0) + { + counter = framesize >> 2; + m_stage = stage = (stage + 1) & 3; + disppchratio = pchratio; + if (pchdisp != 0.f) + { + disppchratio += (pchdisp * frand2(s1,s2,s3)); + } + disppchratio = sc_clip(disppchratio, 0.f, 4.f); + pchratio1 = disppchratio - 1.f; + samp_slope = -pchratio1; + startpos = pchratio1 < 0.f ? 2.f : framesize * pchratio1 + 2.f; + startpos += (timedisp * frand(s1,s2,s3)); + switch(stage) + { + case 0 : + m_dsamp1_slope = dsamp1_slope = samp_slope; + dsamp1 = startpos; + ramp1 = 0.0; + m_ramp1_slope = ramp1_slope = slope; + m_ramp3_slope = ramp3_slope = -slope; + break; + case 1 : + m_dsamp2_slope = dsamp2_slope = samp_slope; + dsamp2 = startpos; + ramp2 = 0.0; + m_ramp2_slope = ramp2_slope = slope; + m_ramp4_slope = ramp4_slope = -slope; + break; + case 2 : + m_dsamp3_slope = dsamp3_slope = samp_slope; + dsamp3 = startpos; + ramp3 = 0.0; + m_ramp3_slope = ramp3_slope = slope; + m_ramp1_slope = ramp1_slope = -slope; + break; + case 3 : + m_dsamp4_slope = dsamp4_slope = samp_slope; + dsamp4 = startpos; + ramp4 = 0.0; + m_ramp2_slope = ramp2_slope = -slope; + m_ramp4_slope = ramp4_slope = slope; + break; + } + } + + nsmps = sc_min(remain, counter); + remain -= nsmps; + counter -= nsmps; + + for (int i = 0; i!= nsmps;++i) + { + iwrphase = (iwrphase + 1) & mask; + + dsamp1 += dsamp1_slope; + idsamp = (long)dsamp1; + frac = dsamp1 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value = (d1 + frac * (d2 - d1)) * ramp1; + ramp1 += ramp1_slope; + + dsamp2 += dsamp2_slope; + idsamp = (long)dsamp2; + frac = dsamp2 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp2; + ramp2 += ramp2_slope; + + dsamp3 += dsamp3_slope; + idsamp = (long)dsamp3; + frac = dsamp3 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp3; + ramp3 += ramp3_slope; + + dsamp4 += dsamp4_slope; + idsamp = (long)dsamp4; + frac = dsamp4 - idsamp; + irdphase = (iwrphase - idsamp) & mask; + irdphaseb = (irdphase - 1) & mask; + d1 = dlybuf[irdphase]; + d2 = dlybuf[irdphaseb]; + value += (d1 + frac * (d2 - d1)) * ramp4; + ramp4 += ramp4_slope; + + dlybuf[iwrphase] = ZXP(nin); + ZXP(nout) = value *= 0.5; + } + } + + m_counter = counter; + + m_dsamp1 = dsamp1; + m_dsamp2 = dsamp2; + m_dsamp3 = dsamp3; + m_dsamp4 = dsamp4; + + m_ramp1 = ramp1; + m_ramp2 = ramp2; + m_ramp3 = ramp3; + m_ramp4 = ramp4; + + m_iwrphase = iwrphase; + + RPUT; +} + + +/* todo: does a control rate PitchShift make sense? */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 77a620c..332afa8 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -62,7 +62,7 @@ void sc4pd_library_setup() "DelayN~,\n" " DelayL~, DelayC~, CombN~, CombL~, CombC~, AllpassN~, " "AllpassL~,\n" - " AllpassC~" + " AllpassC~, PitchShift~" "\n" ); -- cgit v1.2.1 From 89f570e5ebeab979202acf679974bafd05072692 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Aug 2004 14:01:31 +0000 Subject: sc4pd_dsp class and other changes svn path=/trunk/externals/tb/; revision=1912 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/headers/plugin_interface/SC_Constants.h | 2 +- sc4pd/make-files.txt | 2 +- sc4pd/source/BrownNoise.cpp | 4 +- sc4pd/source/ClipNoise.cpp | 4 +- sc4pd/source/Crackle.cpp | 4 +- sc4pd/source/Decay.cpp | 4 +- sc4pd/source/Decay2.cpp | 4 +- sc4pd/source/DelayUnit.cpp | 4 +- sc4pd/source/DelayUnit.hpp | 6 ++- sc4pd/source/Dust.cpp | 4 +- sc4pd/source/Dust2.cpp | 4 +- sc4pd/source/ExpRand.cpp | 4 +- sc4pd/source/GrayNoise.cpp | 4 +- sc4pd/source/Hasher.cpp | 6 +-- sc4pd/source/IRand.cpp | 4 +- sc4pd/source/Impulse.cpp | 4 +- sc4pd/source/Integrator.cpp | 4 +- sc4pd/source/LFClipNoise.cpp | 4 +- sc4pd/source/LFNoise0.cpp | 4 +- sc4pd/source/LFNoise1.cpp | 4 +- sc4pd/source/LFNoise2.cpp | 4 +- sc4pd/source/LFPulse.cpp | 4 +- sc4pd/source/LFSaw.cpp | 4 +- sc4pd/source/Lag.cpp | 4 +- sc4pd/source/Lag2.cpp | 4 +- sc4pd/source/Lag3.cpp | 4 +- sc4pd/source/Latoocarfian.cpp | 4 +- sc4pd/source/LinCong.cpp | 4 +- sc4pd/source/LinExp.cpp | 4 +- sc4pd/source/LinRand.cpp | 4 +- sc4pd/source/Logistic.cpp | 4 +- sc4pd/source/MantissaMask.cpp | 6 +-- sc4pd/source/Median.cpp | 8 ++-- sc4pd/source/NRand.cpp | 4 +- sc4pd/source/PinkNoise.cpp | 4 +- sc4pd/source/PitchShift.cpp | 37 ++++++---------- sc4pd/source/Rand.cpp | 4 +- sc4pd/source/TExpRand.cpp | 4 +- sc4pd/source/TIRand.cpp | 4 +- sc4pd/source/TRand.cpp | 4 +- sc4pd/source/WhiteNoise.cpp | 4 +- sc4pd/source/absdif.cpp | 4 +- sc4pd/source/amclip.cpp | 4 +- sc4pd/source/difsqr.cpp | 4 +- sc4pd/source/excess.cpp | 4 +- sc4pd/source/hypot.cpp | 4 +- sc4pd/source/main.cpp | 9 +++- sc4pd/source/ring1.cpp | 4 +- sc4pd/source/ring2.cpp | 4 +- sc4pd/source/ring3.cpp | 4 +- sc4pd/source/ring4.cpp | 4 +- sc4pd/source/sc4pd.hpp | 61 ++++++++++++++++++++++++--- sc4pd/source/scaleneg.cpp | 4 +- sc4pd/source/sqrdif.cpp | 4 +- sc4pd/source/sqrsum.cpp | 4 +- sc4pd/source/sumsqr.cpp | 4 +- 57 files changed, 189 insertions(+), 138 deletions(-) diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 9b46ed4..1e95392 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) -# CXX=icc + CXX=icc # where does the PD installation reside? diff --git a/sc4pd/headers/plugin_interface/SC_Constants.h b/sc4pd/headers/plugin_interface/SC_Constants.h index b827cad..b9e49bf 100755 --- a/sc4pd/headers/plugin_interface/SC_Constants.h +++ b/sc4pd/headers/plugin_interface/SC_Constants.h @@ -43,4 +43,4 @@ const double truncDouble = 3. * pow(2,51); const float kBadValue = 1e20f; // used in the secant table for values very close to 1/0 -#endif \ No newline at end of file +#endif diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 3dc0de4..475dc94 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -12,4 +12,4 @@ SRCS= \ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ - AllpassC.cpp PitchShift.cpp + AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp diff --git a/sc4pd/source/BrownNoise.cpp b/sc4pd/source/BrownNoise.cpp index ad8a275..316ee42 100644 --- a/sc4pd/source/BrownNoise.cpp +++ b/sc4pd/source/BrownNoise.cpp @@ -40,9 +40,9 @@ /* ------------------------ BrownNoise~ -------------------------------*/ class BrownNoise_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(BrownNoise_ar,flext_dsp); + FLEXT_HEADER(BrownNoise_ar,sc4pd_dsp); public: BrownNoise_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/ClipNoise.cpp b/sc4pd/source/ClipNoise.cpp index 32d8c94..39c0d61 100644 --- a/sc4pd/source/ClipNoise.cpp +++ b/sc4pd/source/ClipNoise.cpp @@ -41,9 +41,9 @@ /* ------------------------ ClipNoise~ -------------------------------*/ class ClipNoise_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(ClipNoise_ar,flext_dsp); + FLEXT_HEADER(ClipNoise_ar,sc4pd_dsp); public: ClipNoise_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Crackle.cpp b/sc4pd/source/Crackle.cpp index a013a1a..8f6c28f 100644 --- a/sc4pd/source/Crackle.cpp +++ b/sc4pd/source/Crackle.cpp @@ -40,9 +40,9 @@ /* ------------------------ Crackle~ -------------------------------*/ class Crackle_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Crackle_ar,flext_dsp); + FLEXT_HEADER(Crackle_ar,sc4pd_dsp); public: Crackle_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Decay.cpp b/sc4pd/source/Decay.cpp index 467611c..c11a7a8 100644 --- a/sc4pd/source/Decay.cpp +++ b/sc4pd/source/Decay.cpp @@ -41,9 +41,9 @@ /* ------------------------ Decay~ -----------------------------*/ class Decay_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Decay_ar,flext_dsp); + FLEXT_HEADER(Decay_ar,sc4pd_dsp); public: Decay_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/Decay2.cpp b/sc4pd/source/Decay2.cpp index 001eb31..a78a180 100644 --- a/sc4pd/source/Decay2.cpp +++ b/sc4pd/source/Decay2.cpp @@ -41,9 +41,9 @@ /* ------------------------ Decay2~ -----------------------------*/ class Decay2_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Decay2_ar,flext_dsp); + FLEXT_HEADER(Decay2_ar,sc4pd_dsp); public: Decay2_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp index 45b05d5..bbd5a2d 100644 --- a/sc4pd/source/DelayUnit.cpp +++ b/sc4pd/source/DelayUnit.cpp @@ -30,12 +30,12 @@ http://www.parasitaere-kapazitaeten.net/ext SuperCollider by James McCartney http://www.audiosynth.com - Coded while listening to: + Coded while listening to: */ -#include "sc4pd.hpp" +// #include "sc4pd.hpp" #include "DelayUnit.hpp" void DelayUnit_ar::DelayUnit_AllocDelayLine() diff --git a/sc4pd/source/DelayUnit.hpp b/sc4pd/source/DelayUnit.hpp index a15a8c3..e9db066 100644 --- a/sc4pd/source/DelayUnit.hpp +++ b/sc4pd/source/DelayUnit.hpp @@ -37,9 +37,11 @@ #include "sc4pd.hpp" -class DelayUnit_ar : public flext_dsp +class DelayUnit_ar + : public sc4pd_dsp { - FLEXT_HEADER(DelayUnit_ar, flext_dsp); + FLEXT_HEADER(DelayUnit_ar,sc4pd_dsp); + public: /* functions */ void DelayUnit_AllocDelayLine(); diff --git a/sc4pd/source/Dust.cpp b/sc4pd/source/Dust.cpp index c44572e..f7b27a1 100644 --- a/sc4pd/source/Dust.cpp +++ b/sc4pd/source/Dust.cpp @@ -39,9 +39,9 @@ /* ------------------------ Dust~ -------------------------------------*/ class Dust_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Dust_ar,flext_dsp); + FLEXT_HEADER(Dust_ar,sc4pd_dsp); public: Dust_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Dust2.cpp b/sc4pd/source/Dust2.cpp index 19013ee..2db7981 100644 --- a/sc4pd/source/Dust2.cpp +++ b/sc4pd/source/Dust2.cpp @@ -40,9 +40,9 @@ /* ------------------------ Dust2~ -------------------------------------*/ class Dust2_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Dust2_ar,flext_dsp); + FLEXT_HEADER(Dust2_ar,sc4pd_dsp); public: Dust2_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/ExpRand.cpp b/sc4pd/source/ExpRand.cpp index 9f1f4a7..a08f6fa 100644 --- a/sc4pd/source/ExpRand.cpp +++ b/sc4pd/source/ExpRand.cpp @@ -40,9 +40,9 @@ /* ------------------------ ExpRand~ -------------------------------*/ class ExpRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(ExpRand_ar,flext_dsp); + FLEXT_HEADER(ExpRand_ar,sc4pd_dsp); public: ExpRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/GrayNoise.cpp b/sc4pd/source/GrayNoise.cpp index 4fa7b23..b9c3e40 100644 --- a/sc4pd/source/GrayNoise.cpp +++ b/sc4pd/source/GrayNoise.cpp @@ -40,9 +40,9 @@ /* ------------------------ GrayNoise~ -------------------------------*/ class GrayNoise_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(GrayNoise_ar,flext_dsp); + FLEXT_HEADER(GrayNoise_ar,sc4pd_dsp); public: GrayNoise_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Hasher.cpp b/sc4pd/source/Hasher.cpp index 8c43c8c..1fc8085 100644 --- a/sc4pd/source/Hasher.cpp +++ b/sc4pd/source/Hasher.cpp @@ -35,14 +35,14 @@ */ -#include "support.hpp" +#include "sc4pd.hpp" /* ------------------------ Hasher~ -----------------------------------*/ class Hasher_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Hasher_ar,flext_dsp); + FLEXT_HEADER(Hasher_ar,sc4pd_dsp); public: Hasher_ar(); diff --git a/sc4pd/source/IRand.cpp b/sc4pd/source/IRand.cpp index 18cf125..8b5c723 100644 --- a/sc4pd/source/IRand.cpp +++ b/sc4pd/source/IRand.cpp @@ -40,9 +40,9 @@ /* ------------------------ IRand~ -------------------------------*/ class IRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(IRand_ar,flext_dsp); + FLEXT_HEADER(IRand_ar,sc4pd_dsp); public: IRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Impulse.cpp b/sc4pd/source/Impulse.cpp index dbb07e2..86ca165 100644 --- a/sc4pd/source/Impulse.cpp +++ b/sc4pd/source/Impulse.cpp @@ -41,9 +41,9 @@ /* ------------------------ Impulse~ -------------------------------*/ class Impulse_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Impulse_ar,flext_dsp); + FLEXT_HEADER(Impulse_ar,sc4pd_dsp); public: Impulse_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Integrator.cpp b/sc4pd/source/Integrator.cpp index 97d2766..85253ee 100644 --- a/sc4pd/source/Integrator.cpp +++ b/sc4pd/source/Integrator.cpp @@ -40,9 +40,9 @@ /* ------------------------ Integrator~ -----------------------------*/ class Integrator_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Integrator_ar,flext_dsp); + FLEXT_HEADER(Integrator_ar,sc4pd_dsp); public: Integrator_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/LFClipNoise.cpp b/sc4pd/source/LFClipNoise.cpp index 60f5049..1583431 100644 --- a/sc4pd/source/LFClipNoise.cpp +++ b/sc4pd/source/LFClipNoise.cpp @@ -41,9 +41,9 @@ /* ------------------------ LFClipNoise~ -------------------------------*/ class LFClipNoise_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LFClipNoise_ar,flext_dsp); + FLEXT_HEADER(LFClipNoise_ar,sc4pd_dsp); public: LFClipNoise_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LFNoise0.cpp b/sc4pd/source/LFNoise0.cpp index a548e9e..9ee9ff6 100644 --- a/sc4pd/source/LFNoise0.cpp +++ b/sc4pd/source/LFNoise0.cpp @@ -41,9 +41,9 @@ /* ------------------------ LFNoise0~ -------------------------------*/ class LFNoise0_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LFNoise0_ar,flext_dsp); + FLEXT_HEADER(LFNoise0_ar,sc4pd_dsp); public: LFNoise0_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LFNoise1.cpp b/sc4pd/source/LFNoise1.cpp index d80b55b..c164942 100644 --- a/sc4pd/source/LFNoise1.cpp +++ b/sc4pd/source/LFNoise1.cpp @@ -41,9 +41,9 @@ /* ------------------------ LFNoise1~ -------------------------------*/ class LFNoise1_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LFNoise1_ar,flext_dsp); + FLEXT_HEADER(LFNoise1_ar,sc4pd_dsp); public: LFNoise1_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LFNoise2.cpp b/sc4pd/source/LFNoise2.cpp index 891a0f3..3b1fd37 100644 --- a/sc4pd/source/LFNoise2.cpp +++ b/sc4pd/source/LFNoise2.cpp @@ -41,9 +41,9 @@ /* ------------------------ LFNoise2~ -------------------------------*/ class LFNoise2_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LFNoise2_ar,flext_dsp); + FLEXT_HEADER(LFNoise2_ar,sc4pd_dsp); public: LFNoise2_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LFPulse.cpp b/sc4pd/source/LFPulse.cpp index 020fb57..ad16e65 100644 --- a/sc4pd/source/LFPulse.cpp +++ b/sc4pd/source/LFPulse.cpp @@ -41,9 +41,9 @@ /* ------------------------ LFPulse~ -------------------------------*/ class LFPulse_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LFPulse_ar,flext_dsp); + FLEXT_HEADER(LFPulse_ar,sc4pd_dsp); public: LFPulse_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LFSaw.cpp b/sc4pd/source/LFSaw.cpp index c442a89..0e406d0 100644 --- a/sc4pd/source/LFSaw.cpp +++ b/sc4pd/source/LFSaw.cpp @@ -41,9 +41,9 @@ /* ------------------------ LFSaw~ -------------------------------*/ class LFSaw_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LFSaw_ar,flext_dsp); + FLEXT_HEADER(LFSaw_ar,sc4pd_dsp); public: LFSaw_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Lag.cpp b/sc4pd/source/Lag.cpp index 81482a8..5daf6d1 100644 --- a/sc4pd/source/Lag.cpp +++ b/sc4pd/source/Lag.cpp @@ -40,9 +40,9 @@ /* ------------------------ Lag~ -----------------------------*/ class Lag_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Lag_ar,flext_dsp); + FLEXT_HEADER(Lag_ar,sc4pd_dsp); public: Lag_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/Lag2.cpp b/sc4pd/source/Lag2.cpp index 2e3096b..dc85fcb 100644 --- a/sc4pd/source/Lag2.cpp +++ b/sc4pd/source/Lag2.cpp @@ -40,9 +40,9 @@ /* ------------------------ Lag2~ -----------------------------*/ class Lag2_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Lag2_ar,flext_dsp); + FLEXT_HEADER(Lag2_ar,sc4pd_dsp); public: Lag2_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/Lag3.cpp b/sc4pd/source/Lag3.cpp index bedd625..8865555 100644 --- a/sc4pd/source/Lag3.cpp +++ b/sc4pd/source/Lag3.cpp @@ -40,9 +40,9 @@ /* ------------------------ Lag3~ -----------------------------*/ class Lag3_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Lag3_ar,flext_dsp); + FLEXT_HEADER(Lag3_ar,sc4pd_dsp); public: Lag3_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/Latoocarfian.cpp b/sc4pd/source/Latoocarfian.cpp index 3fdb0b2..1e20632 100644 --- a/sc4pd/source/Latoocarfian.cpp +++ b/sc4pd/source/Latoocarfian.cpp @@ -41,9 +41,9 @@ /* ------------------------ Latoocarfian~ -------------------------------*/ class Latoocarfian_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Latoocarfian_ar,flext_dsp); + FLEXT_HEADER(Latoocarfian_ar,sc4pd_dsp); public: Latoocarfian_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LinCong.cpp b/sc4pd/source/LinCong.cpp index 4f0b327..fdead9c 100644 --- a/sc4pd/source/LinCong.cpp +++ b/sc4pd/source/LinCong.cpp @@ -41,9 +41,9 @@ /* ------------------------ LinCong~ -------------------------------*/ class LinCong_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LinCong_ar,flext_dsp); + FLEXT_HEADER(LinCong_ar,sc4pd_dsp); public: LinCong_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/LinExp.cpp b/sc4pd/source/LinExp.cpp index 6be19f3..69e9e0a 100644 --- a/sc4pd/source/LinExp.cpp +++ b/sc4pd/source/LinExp.cpp @@ -42,9 +42,9 @@ /* ------------------------ LinExp~ -----------------------------*/ class LinExp_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(LinExp_ar,flext_dsp); + FLEXT_HEADER(LinExp_ar,sc4pd_dsp); public: LinExp_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/LinRand.cpp b/sc4pd/source/LinRand.cpp index f5acb00..80266f1 100644 --- a/sc4pd/source/LinRand.cpp +++ b/sc4pd/source/LinRand.cpp @@ -41,9 +41,9 @@ /* ------------------------ LinRand~ -------------------------------*/ class LinRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(LinRand_ar,flext_dsp); + FLEXT_HEADER(LinRand_ar,sc4pd_dsp); public: LinRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/Logistic.cpp b/sc4pd/source/Logistic.cpp index 89c6c2e..a956fda 100644 --- a/sc4pd/source/Logistic.cpp +++ b/sc4pd/source/Logistic.cpp @@ -41,9 +41,9 @@ /* ------------------------ Logistic~ -------------------------------*/ class Logistic_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Logistic_ar,flext_dsp); + FLEXT_HEADER(Logistic_ar,sc4pd_dsp); public: Logistic_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/MantissaMask.cpp b/sc4pd/source/MantissaMask.cpp index dfbf605..c7c70c2 100644 --- a/sc4pd/source/MantissaMask.cpp +++ b/sc4pd/source/MantissaMask.cpp @@ -35,14 +35,14 @@ */ -#include "support.hpp" +#include "sc4pd.hpp" /* ------------------------ MantissaMask~ -----------------------------*/ class MantissaMask_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(MantissaMask_ar,flext_dsp); + FLEXT_HEADER(MantissaMask_ar,sc4pd_dsp); public: MantissaMask_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp index f15ce63..f89f934 100644 --- a/sc4pd/source/Median.cpp +++ b/sc4pd/source/Median.cpp @@ -107,9 +107,9 @@ inline float median_shared::Insert(float value) /* ------------------------ Median~ -----------------------------------*/ class Median_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Median_ar,flext_dsp); + FLEXT_HEADER(Median_ar,sc4pd_dsp); public: Median_ar(int argc, t_atom * argv); @@ -166,9 +166,9 @@ void Median_ar::m_signal(int n, t_sample *const *in, t_sample *const *out) /* ------------------------ Median ------------------------------------*/ class Median_kr - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(Median_kr,flext_dsp); + FLEXT_HEADER(Median_kr,sc4pd_dsp); public: Median_kr(int argc, t_atom * argv); diff --git a/sc4pd/source/NRand.cpp b/sc4pd/source/NRand.cpp index 84a4374..e91ad71 100644 --- a/sc4pd/source/NRand.cpp +++ b/sc4pd/source/NRand.cpp @@ -41,9 +41,9 @@ /* ------------------------ NRand~ -------------------------------*/ class NRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(NRand_ar,flext_dsp); + FLEXT_HEADER(NRand_ar,sc4pd_dsp); public: NRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/PinkNoise.cpp b/sc4pd/source/PinkNoise.cpp index 513d02a..296f383 100644 --- a/sc4pd/source/PinkNoise.cpp +++ b/sc4pd/source/PinkNoise.cpp @@ -40,9 +40,9 @@ /* ------------------------ PinkNoise~ -------------------------------*/ class PinkNoise_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(PinkNoise_ar,flext_dsp); + FLEXT_HEADER(PinkNoise_ar,sc4pd_dsp); public: PinkNoise_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/PitchShift.cpp b/sc4pd/source/PitchShift.cpp index d182681..8a3f265 100644 --- a/sc4pd/source/PitchShift.cpp +++ b/sc4pd/source/PitchShift.cpp @@ -31,7 +31,7 @@ SuperCollider by James McCartney http://www.audiosynth.com - Coded while listening to: + Coded while listening to: Bernhard Lang: Differenz / Wiederholung 2 */ @@ -40,9 +40,9 @@ /* ------------------------ PitchShift~ -----------------------------*/ class PitchShift_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(PitchShift_ar,flext_dsp); + FLEXT_HEADER(PitchShift_ar,sc4pd_dsp); public: PitchShift_ar(int argc,t_atom * argv); @@ -55,11 +55,6 @@ protected: virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); - void m_set_windowsize(float f) - { - m_windowsize = f; - } - void m_set_pitchratio (float f) { m_pitchratio = f; @@ -76,7 +71,7 @@ protected: } private: - float m_windowsize, m_pitchratio,m_pitchdispersion,m_timedispersion; + float m_windowsize,m_pitchratio,m_pitchdispersion,m_timedispersion; RGen rgen; @@ -93,7 +88,6 @@ private: DEFSIGFUN(m_signal_); DEFSIGFUN(m_signal_z); - FLEXT_CALLBACK_F(m_set_windowsize); FLEXT_CALLBACK_F(m_set_pitchratio); FLEXT_CALLBACK_F(m_set_pitchdispersion); FLEXT_CALLBACK_F(m_set_timedispersion); @@ -103,7 +97,6 @@ FLEXT_LIB_DSP_V("PitchShift~",PitchShift_ar); PitchShift_ar::PitchShift_ar(int argc,t_atom * argv) { - FLEXT_ADDMETHOD_(0,"windowSize",m_set_windowsize); FLEXT_ADDMETHOD_(0,"pitchRatio",m_set_pitchratio); FLEXT_ADDMETHOD_(0,"pitchDispersion",m_set_pitchdispersion); FLEXT_ADDMETHOD_(0,"timeDispersion",m_set_timedispersion); @@ -115,6 +108,7 @@ PitchShift_ar::PitchShift_ar(int argc,t_atom * argv) post("4 arguments needed"); return; } + m_windowsize = sc_getfloatarg(Args,0); m_pitchratio = sc_getfloatarg(Args,1); m_pitchdispersion = sc_getfloatarg(Args,2); @@ -132,17 +126,16 @@ void PitchShift_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) /* initialization from PitchShift_Ctor(PitchShift *unit) */ long delaybufsize; - float /* *out, *in,*/ *dlybuf; - float winsize, pchratio; + float *dlybuf; + float pchratio; float fdelaylen, slope; long framesize, last; //out = ZOUT(0); //in = ZIN(0); pchratio = m_pitchratio; - winsize = m_windowsize; - delaybufsize = (long)ceil(winsize * SAMPLERATE * 3.f + 3.f); + delaybufsize = (long)ceil(m_windowsize * SAMPLERATE * 3.f + 3.f); fdelaylen = delaybufsize - 3; delaybufsize = delaybufsize + BUFLENGTH; @@ -159,7 +152,7 @@ void PitchShift_ar::m_dsp(int n, t_sample *const *in, t_sample *const *out) m_numoutput = 0; m_mask = last = (delaybufsize - 1); - m_framesize = framesize = ((long)(winsize * SAMPLERATE) + 2) & ~3; + m_framesize = framesize = ((long)(m_windowsize * SAMPLERATE) + 2) & ~3; m_slope = slope = 2.f / framesize; m_stage = 3; m_counter = framesize >> 2; @@ -197,7 +190,7 @@ void PitchShift_ar::m_signal_z(int n, t_sample *const *in, float dsamp3, dsamp3_slope, ramp3, ramp3_slope; float dsamp4, dsamp4_slope, ramp4, ramp4_slope; float fdelaylen, d1, d2, frac, slope, samp_slope, startpos, - winsize, pchdisp, timedisp; + pchdisp, timedisp; long remain, nsmps, idelaylen, irdphase, irdphaseb, iwrphase; long mask, idsamp; long counter, stage, framesize, numoutput; @@ -208,10 +201,9 @@ void PitchShift_ar::m_signal_z(int n, t_sample *const *in, nin = *in; pchratio = m_pitchratio; - winsize = m_windowsize; pchdisp = m_pitchdispersion; timedisp = m_timedispersion; - timedisp = sc_clip(timedisp, 0.f, winsize) * SAMPLERATE; + timedisp = sc_clip(timedisp, 0.f, m_windowsize) * SAMPLERATE; dlybuf = m_dlybuf; fdelaylen = m_fdelaylen; @@ -466,7 +458,7 @@ void PitchShift_ar::m_signal_(int n, t_sample *const *in, float dsamp3, dsamp3_slope, ramp3, ramp3_slope; float dsamp4, dsamp4_slope, ramp4, ramp4_slope; float fdelaylen, d1, d2, frac, slope, samp_slope, startpos, - winsize, pchdisp, timedisp; + pchdisp, timedisp; long remain, nsmps, idelaylen, irdphase, irdphaseb, iwrphase, mask, idsamp; long counter, stage, framesize; @@ -476,11 +468,10 @@ void PitchShift_ar::m_signal_(int n, t_sample *const *in, nin = *in; pchratio = m_pitchratio; - winsize = m_windowsize; pchdisp = m_pitchdispersion; timedisp = m_timedispersion; - timedisp = sc_clip(timedisp, 0.f, winsize) * SAMPLERATE; + timedisp = sc_clip(timedisp, 0.f, m_windowsize) * SAMPLERATE; dlybuf = m_dlybuf; fdelaylen = m_fdelaylen; @@ -635,4 +626,4 @@ void PitchShift_ar::m_signal_(int n, t_sample *const *in, } -/* todo: does a control rate PitchShift make sense? */ +/* a control rate PitchShift doesn't make sense */ diff --git a/sc4pd/source/Rand.cpp b/sc4pd/source/Rand.cpp index 791db68..c310aa9 100644 --- a/sc4pd/source/Rand.cpp +++ b/sc4pd/source/Rand.cpp @@ -41,9 +41,9 @@ /* ------------------------ Rand~ -------------------------------*/ class Rand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(Rand_ar,flext_dsp); + FLEXT_HEADER(Rand_ar,sc4pd_dsp); public: Rand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/TExpRand.cpp b/sc4pd/source/TExpRand.cpp index 6e2b1c6..a0087e7 100644 --- a/sc4pd/source/TExpRand.cpp +++ b/sc4pd/source/TExpRand.cpp @@ -41,9 +41,9 @@ /* ------------------------ TExpRand~ -------------------------------*/ class TExpRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(TExpRand_ar,flext_dsp); + FLEXT_HEADER(TExpRand_ar,sc4pd_dsp); public: TExpRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/TIRand.cpp b/sc4pd/source/TIRand.cpp index 1995e46..1c59a6e 100644 --- a/sc4pd/source/TIRand.cpp +++ b/sc4pd/source/TIRand.cpp @@ -41,9 +41,9 @@ /* ------------------------ TIRand~ -------------------------------*/ class TIRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(TIRand_ar,flext_dsp); + FLEXT_HEADER(TIRand_ar,sc4pd_dsp); public: TIRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/TRand.cpp b/sc4pd/source/TRand.cpp index d761dc4..d54c196 100644 --- a/sc4pd/source/TRand.cpp +++ b/sc4pd/source/TRand.cpp @@ -41,9 +41,9 @@ /* ------------------------ TRand~ -------------------------------*/ class TRand_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(TRand_ar,flext_dsp); + FLEXT_HEADER(TRand_ar,sc4pd_dsp); public: TRand_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/WhiteNoise.cpp b/sc4pd/source/WhiteNoise.cpp index 779cb2f..5def735 100644 --- a/sc4pd/source/WhiteNoise.cpp +++ b/sc4pd/source/WhiteNoise.cpp @@ -41,9 +41,9 @@ /* ------------------------ WhiteNoise~ -------------------------------*/ class WhiteNoise_ar: - public flext_dsp + public sc4pd_dsp { - FLEXT_HEADER(WhiteNoise_ar,flext_dsp); + FLEXT_HEADER(WhiteNoise_ar,sc4pd_dsp); public: WhiteNoise_ar(int argc, t_atom *argv); diff --git a/sc4pd/source/absdif.cpp b/sc4pd/source/absdif.cpp index 1af9473..e31a3dd 100644 --- a/sc4pd/source/absdif.cpp +++ b/sc4pd/source/absdif.cpp @@ -48,9 +48,9 @@ inline float sc_absdif (float a, float b) /* ------------------------ absdif~ -----------------------------*/ class absdif_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(absdif_ar,flext_dsp); + FLEXT_HEADER(absdif_ar,sc4pd_dsp); public: absdif_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/amclip.cpp b/sc4pd/source/amclip.cpp index 4a3b194..8bd2edf 100644 --- a/sc4pd/source/amclip.cpp +++ b/sc4pd/source/amclip.cpp @@ -41,9 +41,9 @@ /* ------------------------ amclip~ -----------------------------*/ class amclip_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(amclip_ar,flext_dsp); + FLEXT_HEADER(amclip_ar,sc4pd_dsp); public: amclip_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/difsqr.cpp b/sc4pd/source/difsqr.cpp index 807eefc..26051f4 100644 --- a/sc4pd/source/difsqr.cpp +++ b/sc4pd/source/difsqr.cpp @@ -47,9 +47,9 @@ inline float sc_difsqr (float a, float b) /* ------------------------ difsqr~ -----------------------------*/ class difsqr_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(difsqr_ar,flext_dsp); + FLEXT_HEADER(difsqr_ar,sc4pd_dsp); public: difsqr_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/excess.cpp b/sc4pd/source/excess.cpp index 2aca853..eeefb3d 100644 --- a/sc4pd/source/excess.cpp +++ b/sc4pd/source/excess.cpp @@ -40,9 +40,9 @@ /* ------------------------ excess~ -----------------------------*/ class excess_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(excess_ar,flext_dsp); + FLEXT_HEADER(excess_ar,sc4pd_dsp); public: excess_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/hypot.cpp b/sc4pd/source/hypot.cpp index 1e2dd1a..83f9a89 100644 --- a/sc4pd/source/hypot.cpp +++ b/sc4pd/source/hypot.cpp @@ -41,9 +41,9 @@ /* ------------------------ hypot~ -----------------------------*/ class hypot_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(hypot_ar,flext_dsp); + FLEXT_HEADER(hypot_ar,sc4pd_dsp); public: hypot_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 332afa8..8f0eafa 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -62,7 +62,7 @@ void sc4pd_library_setup() "DelayN~,\n" " DelayL~, DelayC~, CombN~, CombL~, CombC~, AllpassN~, " "AllpassL~,\n" - " AllpassC~, PitchShift~" + " AllpassC~, PitchShift~, Resonz~, OnePole(~)" "\n" ); @@ -228,6 +228,13 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(AllpassL_ar); FLEXT_DSP_SETUP(AllpassC_ar); + + FLEXT_DSP_SETUP(PitchShift_ar); + + FLEXT_DSP_SETUP(Resonz_ar); + + FLEXT_DSP_SETUP(OnePole_ar); + FLEXT_SETUP(OnePole_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/ring1.cpp b/sc4pd/source/ring1.cpp index f3bce43..9c09e40 100644 --- a/sc4pd/source/ring1.cpp +++ b/sc4pd/source/ring1.cpp @@ -46,9 +46,9 @@ inline float sc_ring1 (float a, float b) /* ------------------------ ring1~ -----------------------------*/ class ring1_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(ring1_ar,flext_dsp); + FLEXT_HEADER(ring1_ar,sc4pd_dsp); public: ring1_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/ring2.cpp b/sc4pd/source/ring2.cpp index e5c48cf..c2432e9 100644 --- a/sc4pd/source/ring2.cpp +++ b/sc4pd/source/ring2.cpp @@ -46,9 +46,9 @@ inline float sc_ring2 (float a, float b) /* ------------------------ ring2~ -----------------------------*/ class ring2_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(ring2_ar,flext_dsp); + FLEXT_HEADER(ring2_ar,sc4pd_dsp); public: ring2_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/ring3.cpp b/sc4pd/source/ring3.cpp index adb13c2..d8de166 100644 --- a/sc4pd/source/ring3.cpp +++ b/sc4pd/source/ring3.cpp @@ -46,9 +46,9 @@ inline float sc_ring3 (float a, float b) /* ------------------------ ring3~ -----------------------------*/ class ring3_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(ring3_ar,flext_dsp); + FLEXT_HEADER(ring3_ar,sc4pd_dsp); public: ring3_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/ring4.cpp b/sc4pd/source/ring4.cpp index 5bd2af4..f9c6035 100644 --- a/sc4pd/source/ring4.cpp +++ b/sc4pd/source/ring4.cpp @@ -47,9 +47,9 @@ inline float sc_ring4 (float a, float b) /* ------------------------ ring4~ -----------------------------*/ class ring4_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(ring4_ar,flext_dsp); + FLEXT_HEADER(ring4_ar,sc4pd_dsp); public: ring4_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp index f1f90e2..eacbfff 100644 --- a/sc4pd/source/sc4pd.hpp +++ b/sc4pd/source/sc4pd.hpp @@ -35,7 +35,6 @@ */ #ifndef _SC4PD_HPP -#define _SC$PD_HPP #include @@ -63,8 +62,6 @@ #undef BUFLENGTH #define BUFLENGTH Blocksize() - - /* to make sure the behaviour is consistent: */ #undef ZXP @@ -72,6 +69,60 @@ - - +class sc4pd_dsp + : public flext_dsp +{ + FLEXT_HEADER(sc4pd_dsp,flext_dsp); + + +/* some initialisation functions, adapted from SC_Rate.cpp*/ + + inline float sc_sampledur() + { + return 1 / Samplerate(); + } + + inline float sc_radianspersample() + { + return twopi / Samplerate(); + } + + inline float sc_bufduration() + { + return Blocksize() / Samplerate(); + } + + inline float sc_bufrate() + { + return 1 / sc_bufduration(); + } + + inline float sc_slopefactor() + { + return 1 / Blocksize(); + } + + inline float sc_filterloops() + { + return Blocksize() / 3; + } + + inline float sc_filterremain() + { + return Blocksize() % 3; + } + + inline float sc_filterslope() + { + float f = sc_filterloops(); + if (f == 0) + return 0; + else + return 1. / f; + } + +}; + + +#define _SC$PD_HPP #endif diff --git a/sc4pd/source/scaleneg.cpp b/sc4pd/source/scaleneg.cpp index abd316f..d91b324 100644 --- a/sc4pd/source/scaleneg.cpp +++ b/sc4pd/source/scaleneg.cpp @@ -41,9 +41,9 @@ /* ------------------------ scaleneg~ -----------------------------*/ class scaleneg_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(scaleneg_ar,flext_dsp); + FLEXT_HEADER(scaleneg_ar,sc4pd_dsp); public: scaleneg_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/sqrdif.cpp b/sc4pd/source/sqrdif.cpp index 2762fe5..165ee2b 100644 --- a/sc4pd/source/sqrdif.cpp +++ b/sc4pd/source/sqrdif.cpp @@ -48,9 +48,9 @@ inline float sc_sqrdif (float a, float b) /* ------------------------ sqrdif~ -----------------------------*/ class sqrdif_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(sqrdif_ar,flext_dsp); + FLEXT_HEADER(sqrdif_ar,sc4pd_dsp); public: sqrdif_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/sqrsum.cpp b/sc4pd/source/sqrsum.cpp index 265c909..756c07e 100644 --- a/sc4pd/source/sqrsum.cpp +++ b/sc4pd/source/sqrsum.cpp @@ -48,9 +48,9 @@ inline float sc_sqrsum (float a, float b) /* ------------------------ sqrsum~ -----------------------------*/ class sqrsum_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(sqrsum_ar,flext_dsp); + FLEXT_HEADER(sqrsum_ar,sc4pd_dsp); public: sqrsum_ar(int argc,t_atom * argv); diff --git a/sc4pd/source/sumsqr.cpp b/sc4pd/source/sumsqr.cpp index 4b2564d..518eb01 100644 --- a/sc4pd/source/sumsqr.cpp +++ b/sc4pd/source/sumsqr.cpp @@ -47,9 +47,9 @@ inline float sc_sumsqr (float a, float b) /* ------------------------ sumsqr~ -----------------------------*/ class sumsqr_ar - :public flext_dsp + :public sc4pd_dsp { - FLEXT_HEADER(sumsqr_ar,flext_dsp); + FLEXT_HEADER(sumsqr_ar,sc4pd_dsp); public: sumsqr_ar(int argc,t_atom * argv); -- cgit v1.2.1 From 1c90c506bb91c8ba80390d81a168e7425190e2bb Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Aug 2004 14:05:40 +0000 Subject: checkins svn path=/trunk/externals/tb/; revision=1913 --- sc4pd/pd/onepole.pd | 28 ++++++ sc4pd/pd/pitchshift.pd | 19 ++++ sc4pd/pd/resonz.pd | 15 +++ sc4pd/source/OnePole.cpp | 245 +++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/Resonz.cpp | 190 ++++++++++++++++++++++++++++++++++++ 5 files changed, 497 insertions(+) create mode 100644 sc4pd/pd/onepole.pd create mode 100644 sc4pd/pd/pitchshift.pd create mode 100644 sc4pd/pd/resonz.pd create mode 100644 sc4pd/source/OnePole.cpp create mode 100644 sc4pd/source/Resonz.cpp diff --git a/sc4pd/pd/onepole.pd b/sc4pd/pd/onepole.pd new file mode 100644 index 0000000..cd816f5 --- /dev/null +++ b/sc4pd/pd/onepole.pd @@ -0,0 +1,28 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 112 20 5 0 0 0 - - -; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X msg 89 60 coef \$1; +#X obj 18 86 OnePole~ 0.3; +#X obj 85 251 dac~; +#X obj 94 211 OnePole~ 0.3 ar; +#X obj 94 171 Dust~ 444; +#X obj 266 78 OnePole 0.3; +#X connect 2 0 1 0; +#X connect 3 0 7 0; +#X connect 4 0 12 0; +#X connect 6 0 8 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 0 0; +#X connect 8 0 0 1; +#X connect 10 0 9 0; +#X connect 10 0 9 1; +#X connect 11 0 10 1; +#X connect 11 0 10 0; +#X connect 12 0 5 0; diff --git a/sc4pd/pd/pitchshift.pd b/sc4pd/pd/pitchshift.pd new file mode 100644 index 0000000..e7653bc --- /dev/null +++ b/sc4pd/pd/pitchshift.pd @@ -0,0 +1,19 @@ +#N canvas 317 183 450 300 10; +#X floatatom 152 51 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X floatatom 264 55 5 0 0 0 - - -; +#X obj 76 55 osc~ 440; +#X msg 152 80 pitchRatio \$1; +#X msg 264 79 pitchDispersion \$1; +#X floatatom 264 101 5 0 0 0 - - -; +#X msg 264 125 timeDispersion \$1; +#X obj 62 129 PitchShift~ 0.02 0.5 0 0; +#X connect 0 0 4 0; +#X connect 2 0 5 0; +#X connect 3 0 8 0; +#X connect 4 0 8 0; +#X connect 5 0 8 0; +#X connect 6 0 7 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 1 1; diff --git a/sc4pd/pd/resonz.pd b/sc4pd/pd/resonz.pd new file mode 100644 index 0000000..e23cf4e --- /dev/null +++ b/sc4pd/pd/resonz.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X floatatom 188 40 5 0 0 0 - - -; +#X obj 67 187 dac~; +#X floatatom 316 83 5 0 0 0 - - -; +#X msg 185 88 freq \$1; +#X msg 316 107 rq \$1; +#X obj 79 57 Dust~ 44; +#X obj 77 138 Resonz~ 440 20; +#X connect 0 0 3 0; +#X connect 2 0 4 0; +#X connect 3 0 6 0; +#X connect 4 0 6 0; +#X connect 5 0 6 0; +#X connect 6 0 1 0; +#X connect 6 0 1 1; diff --git a/sc4pd/source/OnePole.cpp b/sc4pd/source/OnePole.cpp new file mode 100644 index 0000000..310bf54 --- /dev/null +++ b/sc4pd/source/OnePole.cpp @@ -0,0 +1,245 @@ +/* sc4pd + OnePole, OnePole~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ OnePole~ -------------------------------*/ + +class OnePole_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(OnePole_ar,sc4pd_dsp); + +public: + OnePole_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + void m_set(float f) + { + n_b1=f; + changed = true; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + float m_b1, m_y1; + float n_b1; + bool changed; + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("OnePole~",OnePole_ar); + +OnePole_ar::OnePole_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"coef",m_set); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + + if(sc_ar(Args)) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + AddInSignal(); + AddInSignal(); + } + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); + + m_y1 = 0.f; +} + +void OnePole_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + float *b1p = *(in+1); + + float y1 = m_y1; + + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + float b1 = ZXP(b1p); + ZXP(nout) = y1 = y0 + b1 * (y1 - y0); + } + m_y1 = zapgremlins(y1); +} + + +void OnePole_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float b1 = m_b1; + float y1 = m_y1; + + if (changed) + { + m_b1=n_b1; + float b1_slope = CALCSLOPE(m_b1, b1); + if (b1 >= 0.f && m_b1 >= 0) + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = y0 + b1 * (y1 - y0); + b1 += b1_slope; + } + } + else if (b1 <= 0.f && m_b1 <= 0) + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = y0 + b1 * (y1 + y0); + b1 += b1_slope; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = (1.f - fabs(b1)) * y0 + b1 * y1; + b1 += b1_slope; + } + } + changed = false; + } + else + { + if (b1 >= 0.f) + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = y0 + b1 * (y1 - y0); + } + } + else + { + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin); + ZXP(nout) = y1 = y0 + b1 * (y1 + y0); + } + } + + } + m_y1 = zapgremlins(y1); +} + +/* ------------------------ OnePole ---------------------------------*/ + + +class OnePole_kr: + public flext_base +{ + FLEXT_HEADER(OnePole_kr,flext_base); + +public: + OnePole_kr(int argc, t_atom *argv); + +protected: + void m_perform(float f); + + void m_set(float f) + { + m_b1=f; + } + +private: + float m_b1, m_y1; + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); +}; + + +FLEXT_LIB_V("OnePole",OnePole_kr); + +OnePole_kr::OnePole_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"set",m_set); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + + m_y1=0; +} + +void OnePole_kr::m_perform(float f) +{ + m_y1= f + m_b1 * (m_y1 - f); + ToOutFloat(0,m_y1); +} diff --git a/sc4pd/source/Resonz.cpp b/sc4pd/source/Resonz.cpp new file mode 100644 index 0000000..4561b9a --- /dev/null +++ b/sc4pd/source/Resonz.cpp @@ -0,0 +1,190 @@ +/* sc4pd + Resonz~, Resonz + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: MIMEO: Electric Chair And Table + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ Resonz~ -----------------------------*/ + +class Resonz_ar + :public sc4pd_dsp +{ + FLEXT_HEADER(Resonz_ar,sc4pd_dsp); + +public: + Resonz_ar(int argc,t_atom * argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_set_freq(float f) + { + m_freq = f; + m_ffreq = m_freq * mRadiansPerSample; + changed = true; + } + void m_set_rq(float f) + { + m_rq = f; + changed = true; + } + +private: + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_rq); + float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_rq, m_ffreq; + bool changed; + + float mRadiansPerSample, mFilterSlope, mFilterLoops, mFilterRemain; +}; + +FLEXT_LIB_DSP_V("Resonz~",Resonz_ar); + +Resonz_ar::Resonz_ar(int argc,t_atom * argv) +{ + FLEXT_ADDMETHOD_(0,"freq",m_set_freq); + FLEXT_ADDMETHOD_(0,"rq",m_set_rq); + + AtomList Args(argc,argv); + m_freq = sc_getfloatarg(Args,0); + m_rq = sc_getfloatarg(Args,1); + + AddOutSignal(); + + m_a0 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; + changed = false; +} + +void Resonz_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + + m_ffreq = m_freq * mRadiansPerSample; +} + +void Resonz_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + t_sample *nin = *in; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float b1 = m_b1; + float b2 = m_b2; + + if (changed = true) + { + float B = m_ffreq * m_rq; + float R = 1.f - B * 0.5f; + float twoR = 2.f * R; + float R2 = R * R; + float cost = (twoR * cos(m_ffreq)) / (1.f + R2); + float b1_next = twoR * cost; + float b2_next = -R2; + float a0_next = (1.f - R2) * 0.5f; + float a0_slope = (a0_next - a0) * mFilterSlope; + float b1_slope = (b1_next - b1) * mFilterSlope; + float b2_slope = (b2_next - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 - y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 - y0); + + a0 += a0_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + y2 = y1; + y1 = y0; + } + + m_a0 = a0_next; + m_b1 = b1_next; + m_b2 = b2_next; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 - y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 - y0); + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + + +/* no control rate resonz */ -- cgit v1.2.1 From 13803d97db1f5f234cb2358d255b86571f93cdb9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Aug 2004 20:45:34 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1914 --- sc4pd/make-files.txt | 3 +- sc4pd/pd/onezero.pd | 21 +++++ sc4pd/pd/twopole.pd | 15 ++++ sc4pd/source/OnePole.cpp | 4 +- sc4pd/source/OneZero.cpp | 200 +++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/TwoPole.cpp | 167 +++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 9 ++- sc4pd/source/sc4pd.hpp | 4 +- 8 files changed, 417 insertions(+), 6 deletions(-) create mode 100644 sc4pd/pd/onezero.pd create mode 100644 sc4pd/pd/twopole.pd create mode 100644 sc4pd/source/OneZero.cpp create mode 100644 sc4pd/source/TwoPole.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 475dc94..a9b154f 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -12,4 +12,5 @@ SRCS= \ LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ - AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp + AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ + TwoPole.cpp diff --git a/sc4pd/pd/onezero.pd b/sc4pd/pd/onezero.pd new file mode 100644 index 0000000..2d68a0b --- /dev/null +++ b/sc4pd/pd/onezero.pd @@ -0,0 +1,21 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X obj 89 131 print~; +#X obj 144 112 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X floatatom 112 20 5 0 0 0 - - -; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X msg 89 60 coef \$1; +#X obj 18 86 OneZero~ 0.3; +#X obj 266 78 OneZero 0.3; +#X connect 2 0 1 0; +#X connect 3 0 7 0; +#X connect 4 0 9 0; +#X connect 6 0 8 0; +#X connect 7 0 8 0; +#X connect 8 0 1 0; +#X connect 8 0 0 0; +#X connect 8 0 0 1; +#X connect 9 0 5 0; diff --git a/sc4pd/pd/twopole.pd b/sc4pd/pd/twopole.pd new file mode 100644 index 0000000..b781655 --- /dev/null +++ b/sc4pd/pd/twopole.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X obj 130 147 TwoPole~ 440 0.5; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X msg 271 121 kradius \$1; +#X connect 1 0 4 0; +#X connect 2 0 3 0; +#X connect 3 0 0 0; +#X connect 3 0 0 1; +#X connect 4 0 3 0; +#X connect 5 0 6 0; +#X connect 6 0 3 0; diff --git a/sc4pd/source/OnePole.cpp b/sc4pd/source/OnePole.cpp index 310bf54..3de6ef4 100644 --- a/sc4pd/source/OnePole.cpp +++ b/sc4pd/source/OnePole.cpp @@ -31,7 +31,7 @@ SuperCollider by James McCartney http://www.audiosynth.com - Coded while listening to: + Coded while listening to: Goh Lee Kwang: Internal Pleasures */ @@ -240,6 +240,6 @@ OnePole_kr::OnePole_kr(int argc, t_atom *argv) void OnePole_kr::m_perform(float f) { - m_y1= f + m_b1 * (m_y1 - f); + m_y1= ((1-abs(m_b1))*f)+m_b1*m_y1; ToOutFloat(0,m_y1); } diff --git a/sc4pd/source/OneZero.cpp b/sc4pd/source/OneZero.cpp new file mode 100644 index 0000000..82c9ad5 --- /dev/null +++ b/sc4pd/source/OneZero.cpp @@ -0,0 +1,200 @@ +/* sc4pd + OneZero, OneZero~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Goh Lee Kwang: Internal Pleasures + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ OneZero~ -------------------------------*/ + +class OneZero_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(OneZero_ar,sc4pd_dsp); + +public: + OneZero_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + n_b1=f; + changed = true; + } + +private: + float m_b1, m_x1; + float n_b1; + bool changed; + + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("OneZero~",OneZero_ar); + +OneZero_ar::OneZero_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"coef",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + + AddOutSignal(); + + m_x1 = 0.f; +} + +void OneZero_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float b1 = m_b1; + float x1 = m_x1; + + if (changed) + { + m_b1=n_b1; + float b1_slope = CALCSLOPE(m_b1, b1); + if (b1 >= 0.f && m_b1 >= 0) + { + for (int i = 0; i!= n;++i) + { + float x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * (x1 - x0); + x1 = x0; + b1 += b1_slope; + } + } + else if (b1 <= 0.f && m_b1 <= 0) + { + for (int i = 0; i!= n;++i) + { + float x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * (x1 + x0); + x1 = x0; + b1 += b1_slope; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float x0 = ZXP(nin); + ZXP(nout) = (1.f - fabs(b1)) * x0 + b1 * x1; + x1 = x0; + b1 += b1_slope; + } + } + changed = false; + } + else + { + if (b1 >= 0.f) + { + for (int i = 0; i!= n;++i) + { + float x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * (x1 - x0); + x1 = x0; + } + } + else + { + for (int i = 0; i!= n;++i) + { + float x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * (x1 + x0); + x1 = x0; + } + } + } + m_x1 = x1; +} + +/* ------------------------ OneZero ---------------------------------*/ + + +class OneZero_kr: + public flext_base +{ + FLEXT_HEADER(OneZero_kr,flext_base); + +public: + OneZero_kr(int argc, t_atom *argv); + +protected: + void m_perform(float f); + + void m_set(float f) + { + m_b1=f; + } + +private: + float m_b1, m_x1; + + FLEXT_CALLBACK_F(m_set); + FLEXT_CALLBACK_F(m_perform); +}; + + +FLEXT_LIB_V("OneZero",OneZero_kr); + +OneZero_kr::OneZero_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"set",m_set); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + m_b1 = sc_getfloatarg(Args,0); + + m_x1=0; +} + +void OneZero_kr::m_perform(float f) +{ + ToOutFloat(0,((1-abs(m_b1))*f)+m_b1*m_x1); + m_x1=f; +} diff --git a/sc4pd/source/TwoPole.cpp b/sc4pd/source/TwoPole.cpp new file mode 100644 index 0000000..b37d17f --- /dev/null +++ b/sc4pd/source/TwoPole.cpp @@ -0,0 +1,167 @@ +/* sc4pd + TwoPole~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: VA: Insight + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ TwoPole~ -------------------------------*/ + +class TwoPole_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(TwoPole_ar,sc4pd_dsp); + +public: + TwoPole_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_radius(float f) + { + m_reson=f; + changed = true; + } + + +private: + float m_b1, m_b2, m_y1, m_y2, m_freq, m_reson; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_radius); +}; + +FLEXT_LIB_DSP_V("TwoPole~",TwoPole_ar); + +TwoPole_ar::TwoPole_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"kradius",m_set_radius); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_reson = sc_getfloatarg(Args,1); + changed = false; + + AddOutSignal(); + + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void TwoPole_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + + if (changed) + { + float b1 = m_b1; + float b2 = m_b2; + float b1_next = 2.f * m_reson * cos(m_freq * mRadiansPerSample); + float b2_next = -(m_reson * m_reson); + float b1_slope = (b1_next - b1) * mFilterSlope; + float b2_slope = (b2_next - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + ZXP(nout) = y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = y1 = ZXP(nin) + b1 * y2 + b2 * y0; + + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + ZXP(nout) = y0 = ZXP(nin) + b1 * y1 + b2 * y2; + y2 = y1; + y1 = y0; + } + + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + float b1 = m_b1; + float b2 = m_b2; + + for (int i = 0; i!= mFilterLoops;++i) + { + ZXP(nout) = y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = y1 = ZXP(nin) + b1 * y2 + b2 * y0; + } + for (int i = 0; i!= mFilterRemain;++i) + { + ZXP(nout) = y0 = ZXP(nin) + b1 * y1 + b2 * y2; + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate two pole filter */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 8f0eafa..2cac635 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -62,7 +62,9 @@ void sc4pd_library_setup() "DelayN~,\n" " DelayL~, DelayC~, CombN~, CombL~, CombC~, AllpassN~, " "AllpassL~,\n" - " AllpassC~, PitchShift~, Resonz~, OnePole(~)" + " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~)" + "TwoPole~" + "\n" ); @@ -235,6 +237,11 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(OnePole_ar); FLEXT_SETUP(OnePole_kr); + + FLEXT_DSP_SETUP(OneZero_ar); + FLEXT_SETUP(OneZero_kr); + + FLEXT_DSP_SETUP(TwoPole_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp index eacbfff..f80b177 100644 --- a/sc4pd/source/sc4pd.hpp +++ b/sc4pd/source/sc4pd.hpp @@ -102,12 +102,12 @@ class sc4pd_dsp return 1 / Blocksize(); } - inline float sc_filterloops() + inline int sc_filterloops() { return Blocksize() / 3; } - inline float sc_filterremain() + inline int sc_filterremain() { return Blocksize() % 3; } -- cgit v1.2.1 From ea10413727c241467ab729cee102dd68534f4db9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Aug 2004 22:57:36 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1915 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/make-files.txt | 2 +- sc4pd/makefile.pd-linux | 2 +- sc4pd/pd/fos.pd | 45 ++++++++ sc4pd/pd/sos.pd | 38 +++++++ sc4pd/pd/twozero.pd | 15 +++ sc4pd/source/DelayUnit.cpp | 2 +- sc4pd/source/DelayUnit.hpp | 2 +- sc4pd/source/FOS.cpp | 258 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/SOS.cpp | 258 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/TwoZero.cpp | 175 ++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 13 ++- 12 files changed, 804 insertions(+), 8 deletions(-) create mode 100644 sc4pd/pd/fos.pd create mode 100644 sc4pd/pd/sos.pd create mode 100644 sc4pd/pd/twozero.pd create mode 100644 sc4pd/source/FOS.cpp create mode 100644 sc4pd/source/SOS.cpp create mode 100644 sc4pd/source/TwoZero.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 1e95392..9b46ed4 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) - CXX=icc +# CXX=icc # where does the PD installation reside? diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index a9b154f..d6e04d5 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -13,4 +13,4 @@ SRCS= \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ - TwoPole.cpp + TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp diff --git a/sc4pd/makefile.pd-linux b/sc4pd/makefile.pd-linux index 99d62ef..f1deedb 100644 --- a/sc4pd/makefile.pd-linux +++ b/sc4pd/makefile.pd-linux @@ -24,7 +24,7 @@ LIBS=m ifdef FLEXT_SHARED CFLAGS+=-DFLEXT_SHARED -DFLEXT_THREADS LDFLAGS+=-Bdynamic -LINKFLEXT=-lflext +LINKFLEXT=-lflext_d else LINKFLEXT=$(FLEXTLIB) endif diff --git a/sc4pd/pd/fos.pd b/sc4pd/pd/fos.pd new file mode 100644 index 0000000..f03f45b --- /dev/null +++ b/sc4pd/pd/fos.pd @@ -0,0 +1,45 @@ +#N canvas 0 0 539 300 10; +#X obj 12 159 dac~; +#X floatatom 112 20 5 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 37 269 dac~; +#X obj 95 174 Dust~ 444; +#X obj 18 86 FOS~ 0.3 0.3 0.3; +#X msg 89 60 a0 \$1; +#X floatatom 161 20 5 0 0 0 - - -; +#X msg 138 60 a1 \$1; +#X floatatom 215 20 5 0 0 0 - - -; +#X msg 192 60 b1 \$1; +#X obj 46 229 FOS~ 0.3 0.3 0.3 ar; +#X floatatom 374 26 5 0 0 0 - - -; +#X msg 351 66 a0 \$1; +#X floatatom 423 26 5 0 0 0 - - -; +#X msg 400 66 a1 \$1; +#X floatatom 477 26 5 0 0 0 - - -; +#X msg 454 66 b1 \$1; +#X obj 280 92 FOS 0.3 0.3 0.3; +#X floatatom 282 129 5 0 0 0 - - -; +#X floatatom 283 36 5 0 0 0 - - -; +#X connect 1 0 6 0; +#X connect 2 0 5 0; +#X connect 4 0 11 1; +#X connect 4 0 11 0; +#X connect 4 0 11 2; +#X connect 4 0 11 3; +#X connect 5 0 0 0; +#X connect 5 0 0 1; +#X connect 6 0 5 0; +#X connect 7 0 8 0; +#X connect 8 0 5 0; +#X connect 9 0 10 0; +#X connect 10 0 5 0; +#X connect 11 0 3 0; +#X connect 11 0 3 1; +#X connect 12 0 13 0; +#X connect 13 0 18 0; +#X connect 14 0 15 0; +#X connect 15 0 18 0; +#X connect 16 0 17 0; +#X connect 17 0 18 0; +#X connect 18 0 19 0; +#X connect 20 0 18 0; diff --git a/sc4pd/pd/sos.pd b/sc4pd/pd/sos.pd new file mode 100644 index 0000000..b09be69 --- /dev/null +++ b/sc4pd/pd/sos.pd @@ -0,0 +1,38 @@ +#N canvas 0 0 539 300 10; +#X obj 12 159 dac~; +#X floatatom 112 20 5 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 90 262 dac~; +#X obj 206 145 Dust~ 444; +#X msg 89 60 a0 \$1; +#X floatatom 161 20 5 0 0 0 - - -; +#X msg 138 60 a1 \$1; +#X floatatom 262 20 5 0 0 0 - - -; +#X msg 239 60 b1 \$1; +#X obj 18 87 SOS~ 0.3 0.3 0.3 0.3 0.3; +#X floatatom 212 20 5 0 0 0 - - -; +#X floatatom 313 20 5 0 0 0 - - -; +#X msg 189 60 a2 \$1; +#X msg 290 60 b2 \$1; +#X obj 85 208 SOS~ 0.3 0.3 0.3 0.3 0.3 ar; +#X connect 1 0 5 0; +#X connect 2 0 10 0; +#X connect 4 0 15 0; +#X connect 4 0 15 1; +#X connect 4 0 15 2; +#X connect 4 0 15 3; +#X connect 4 0 15 4; +#X connect 4 0 15 5; +#X connect 5 0 10 0; +#X connect 6 0 7 0; +#X connect 7 0 10 0; +#X connect 8 0 9 0; +#X connect 9 0 10 0; +#X connect 10 0 0 0; +#X connect 10 0 0 1; +#X connect 11 0 13 0; +#X connect 12 0 14 0; +#X connect 13 0 10 0; +#X connect 14 0 10 0; +#X connect 15 0 3 1; +#X connect 15 0 3 0; diff --git a/sc4pd/pd/twozero.pd b/sc4pd/pd/twozero.pd new file mode 100644 index 0000000..3cd2c63 --- /dev/null +++ b/sc4pd/pd/twozero.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X msg 271 121 kradius \$1; +#X obj 130 160 TwoZero~ 440 0.5; +#X connect 1 0 3 0; +#X connect 2 0 6 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; diff --git a/sc4pd/source/DelayUnit.cpp b/sc4pd/source/DelayUnit.cpp index bbd5a2d..bd57f7d 100644 --- a/sc4pd/source/DelayUnit.cpp +++ b/sc4pd/source/DelayUnit.cpp @@ -35,7 +35,7 @@ */ -// #include "sc4pd.hpp" +#include "sc4pd.hpp" #include "DelayUnit.hpp" void DelayUnit_ar::DelayUnit_AllocDelayLine() diff --git a/sc4pd/source/DelayUnit.hpp b/sc4pd/source/DelayUnit.hpp index e9db066..a5951e5 100644 --- a/sc4pd/source/DelayUnit.hpp +++ b/sc4pd/source/DelayUnit.hpp @@ -35,7 +35,7 @@ */ -#include "sc4pd.hpp" +//#include "sc4pd.hpp" class DelayUnit_ar : public sc4pd_dsp diff --git a/sc4pd/source/FOS.cpp b/sc4pd/source/FOS.cpp new file mode 100644 index 0000000..6bd3c26 --- /dev/null +++ b/sc4pd/source/FOS.cpp @@ -0,0 +1,258 @@ +/* sc4pd + FOS, FOS~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Susie Ibarra & Assif Tsahar: Home Cookin' + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ FOS~ -------------------------------*/ + +class FOS_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(FOS_ar,sc4pd_dsp); + +public: + FOS_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + void m_set_a0(float f) + { + next_a0=f; + } + + void m_set_a1(float f) + { + next_a1=f; + } + + void m_set_b1(float f) + { + next_b1=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + float next_a0, next_a1, next_b1; + float m_y1, m_a0, m_a1, m_b1; + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set_a0); + FLEXT_CALLBACK_F(m_set_a1); + FLEXT_CALLBACK_F(m_set_b1); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("FOS~",FOS_ar); + +FOS_ar::FOS_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"a0",m_set_a0); + FLEXT_ADDMETHOD_(0,"a1",m_set_a1); + FLEXT_ADDMETHOD_(0,"b1",m_set_b1); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()<3) + { + post("needs at least 3 arguments"); + return; + } + m_a0 = sc_getfloatarg(Args,0); + m_a1 = sc_getfloatarg(Args,1); + m_b1 = sc_getfloatarg(Args,2); + + if(sc_ar(Args)) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + } + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); + + m_y1 = 0.f; + m_a0 = 0.f; + m_a1 = 0.f; + m_b1 = 0.f; +} + +void FOS_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + float *a0 = *(in+1); + float *a1 = *(in+2); + float *b1 = *(in+3); + + float y1 = m_y1; + + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin) + ZXP(b1) * y1; + ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1; + y1 = y0; + } + m_y1 = zapgremlins(y1); +} + + +void FOS_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y1 = m_y1; + float a0 = m_a0; + float a1 = m_a1; + float b1 = m_b1; + float a0_slope = CALCSLOPE(next_a0, a0); + float a1_slope = CALCSLOPE(next_a1, a1); + float b1_slope = CALCSLOPE(next_b1, b1); + + for (int i = 0; i!= n;++i) + { + float y0 = ZXP(nin) + b1 * y1; + ZXP(nout) = a0 * y0 + a1 * y1; + y1 = y0; + + a0 += a0_slope; + a1 += a1_slope; + b1 += b1_slope; + } +} + +/* ------------------------ FOS ---------------------------------*/ + + +class FOS_kr: + public flext_base +{ + FLEXT_HEADER(FOS_kr,flext_base); + +public: + FOS_kr(int argc, t_atom *argv); + +protected: + void m_perform(float f); + + void m_set_a0(float f) + { + m_a0=f; + } + + void m_set_a1(float f) + { + m_a1=f; + } + + void m_set_b1(float f) + { + m_b1=f; + } + + +private: + float m_y1, m_a0, m_a1, m_b1; + + FLEXT_CALLBACK_F(m_set_a0); + FLEXT_CALLBACK_F(m_set_a1); + FLEXT_CALLBACK_F(m_set_b1); + FLEXT_CALLBACK_F(m_perform); +}; + + +FLEXT_LIB_V("FOS",FOS_kr); + +FOS_kr::FOS_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + FLEXT_ADDMETHOD_(0,"a0",m_set_a0); + FLEXT_ADDMETHOD_(0,"a1",m_set_a1); + FLEXT_ADDMETHOD_(0,"b1",m_set_b1); + + AddOutFloat(); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()!=3) + { + post("needs 3 arguments"); + return; + } + + m_a0 = sc_getfloatarg(Args,0); + m_a1 = sc_getfloatarg(Args,1); + m_b1 = sc_getfloatarg(Args,2); + + m_y1 = 0.f; + m_a0 = 0.f; + m_a1 = 0.f; + m_b1 = 0.f; +} + +void FOS_kr::m_perform(float f) +{ + m_y1 = m_a0 * (f + m_b1 * m_y1) + m_a1 * m_y1; + ToOutFloat(0,m_y1); +} diff --git a/sc4pd/source/SOS.cpp b/sc4pd/source/SOS.cpp new file mode 100644 index 0000000..996833a --- /dev/null +++ b/sc4pd/source/SOS.cpp @@ -0,0 +1,258 @@ +/* sc4pd + SOS~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Susie Ibarra & Assif Tsahar: Home Cookin' + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ SOS~ -------------------------------*/ + +class SOS_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(SOS_ar,sc4pd_dsp); + +public: + SOS_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out) + { + m_signal_fun(n,in,out); + } + + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + mFilterSlope = sc_filterslope(); + } + + void m_set_a0(float f) + { + next_a0=f; + } + + void m_set_a1(float f) + { + next_a1=f; + } + + void m_set_a2(float f) + { + next_a2=f; + } + + void m_set_b1(float f) + { + next_b1=f; + } + + void m_set_b2(float f) + { + next_b2=f; + } + + void m_ar() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + } + + void m_kr() + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + } + +private: + float next_a0, next_a1, next_a2, next_b1, next_b2; + float m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2; + + float mFilterSlope; + int mFilterLoops, mFilterRemain; + + DEFSIGCALL (m_signal_fun); + DEFSIGFUN (m_signal_ar); + DEFSIGFUN (m_signal_kr); + + FLEXT_CALLBACK_F(m_set_a0); + FLEXT_CALLBACK_F(m_set_a1); + FLEXT_CALLBACK_F(m_set_a2); + FLEXT_CALLBACK_F(m_set_b1); + FLEXT_CALLBACK_F(m_set_b2); + FLEXT_CALLBACK(m_ar); + FLEXT_CALLBACK(m_kr); +}; + +FLEXT_LIB_DSP_V("SOS~",SOS_ar); + +SOS_ar::SOS_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"a0",m_set_a0); + FLEXT_ADDMETHOD_(0,"a1",m_set_a1); + FLEXT_ADDMETHOD_(0,"a2",m_set_a2); + FLEXT_ADDMETHOD_(0,"b1",m_set_b1); + FLEXT_ADDMETHOD_(0,"b2",m_set_b2); + FLEXT_ADDMETHOD_(0,"ar",m_ar); + FLEXT_ADDMETHOD_(0,"kr",m_kr); + + //parse arguments + AtomList Args(argc,argv); + + if (Args.Count()<5) + { + post("needs at least 5 arguments"); + return; + } + m_a0 = sc_getfloatarg(Args,0); + m_a1 = sc_getfloatarg(Args,1); + m_a2 = sc_getfloatarg(Args,2); + m_b1 = sc_getfloatarg(Args,3); + m_b2 = sc_getfloatarg(Args,4); + + if(sc_ar(Args)) + { + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + AddInSignal(); + } + else // if not given, use control rate + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); + + AddOutSignal(); + + m_y1 = 0.f; + m_a0 = 0.f; + m_a1 = 0.f; + m_a2 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; +} + +void SOS_ar::m_signal_ar(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + float *a0 = *(in+1); + float *a1 = *(in+2); + float *a2 = *(in+3); + float *b1 = *(in+4); + float *b2 = *(in+5); + + float y0; + float y1 = m_y1; + float y2 = m_y2; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + ZXP(b1) * y1 + ZXP(b2) * y2; + ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2; + + y2 = ZXP(nin) + ZXP(b1) * y0 + ZXP(b2) * y1; + ZXP(nout) = ZXP(a0) * y2 + ZXP(a1) * y0 + ZXP(a2) * y1; + + y1 = ZXP(nin) + ZXP(b1) * y2 + ZXP(b2) * y0; + ZXP(nout) = ZXP(a0) * y1 + ZXP(a1) * y2 + ZXP(a2) * y0; + } + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + ZXP(b1) * y1 + ZXP(b2) * y2; + ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2; + y2 = y1; + y1 = y0; + } + + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); + +} + + +void SOS_ar::m_signal_kr(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float a1 = m_a1; + float a2 = m_a2; + float b1 = m_b1; + float b2 = m_b2; + float a0_slope = (next_a0 - a0) * mFilterSlope; + float a1_slope = (next_a1 - a1) * mFilterSlope; + float a2_slope = (next_a2 - a2) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * y0 + a1 * y1 + a2 * y2; + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * y2 + a1 * y0 + a2 * y1; + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * y1 + a1 * y2 + a2 * y0; + + a0 += a0_slope; + a1 += a1_slope; + a2 += a2_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * y0 + a1 * y1 + a2 * y2; + y2 = y1; + y1 = y0; + } + + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no kr SOS */ diff --git a/sc4pd/source/TwoZero.cpp b/sc4pd/source/TwoZero.cpp new file mode 100644 index 0000000..85a7633 --- /dev/null +++ b/sc4pd/source/TwoZero.cpp @@ -0,0 +1,175 @@ +/* sc4pd + TwoZero~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: VA: Insight + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ TwoZero~ -------------------------------*/ + +class TwoZero_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(TwoZero_ar,sc4pd_dsp); + +public: + TwoZero_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_radius(float f) + { + m_reson=f; + changed = true; + } + + +private: + float m_b1, m_b2, m_x1, m_x2, m_freq, m_reson; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_radius); +}; + +FLEXT_LIB_DSP_V("TwoZero~",TwoZero_ar); + +TwoZero_ar::TwoZero_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"kradius",m_set_radius); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_reson = sc_getfloatarg(Args,1); + changed = false; + + AddOutSignal(); + + m_b1 = 0.f; + m_b2 = 0.f; + m_x1 = 0.f; + m_x2 = 0.f; +} + +void TwoZero_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + float x2 = m_x2; + + if (changed) + { + float b1 = m_b1; + float b2 = m_b2; + float b1_next = -2.f * m_reson * cos(m_freq * mRadiansPerSample); + float b2_next = (m_reson * m_reson); + float b1_slope = (b1_next - b1) * mFilterSlope; + float b2_slope = (b2_next - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = ZXP(nin); + ZXP(nout) = x2 + b1 * x0 + b2 * x1; + x1 = ZXP(nin); + ZXP(nout) = x1 + b1 * x2 + b2 * x0; + + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = x1; + x1 = x0; + } + + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + float b1 = m_b1; + float b2 = m_b2; + + for (int i = 0; i!= mFilterLoops;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = ZXP(nin); + ZXP(nout) = x2 + b1 * x0 + b2 * x1; + x1 = ZXP(nin); + ZXP(nout) = x1 + b1 * x2 + b2 * x0; + } + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = x0 + b1 * x1 + b2 * x2; + x2 = x1; + x1 = x0; + } + } + m_x1 = x1; + m_x2 = x2; +} + +/* no control rate twozero filter */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 2cac635..3430ee4 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -62,9 +62,9 @@ void sc4pd_library_setup() "DelayN~,\n" " DelayL~, DelayC~, CombN~, CombL~, CombC~, AllpassN~, " "AllpassL~,\n" - " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~)" - "TwoPole~" - + " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~), " + "TwoPole~, \n" + " TwoZero~, FOS(~), SOS~" "\n" ); @@ -242,6 +242,13 @@ void sc4pd_library_setup() FLEXT_SETUP(OneZero_kr); FLEXT_DSP_SETUP(TwoPole_ar); + + FLEXT_DSP_SETUP(TwoZero_ar); + + FLEXT_DSP_SETUP(FOS_ar); + FLEXT_SETUP(FOS_kr); + + FLEXT_DSP_SETUP(SOS_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From db776d8e3f345623f03c3cc7703b30719304498f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 8 Aug 2004 11:10:30 +0000 Subject: some filters svn path=/trunk/externals/tb/; revision=1917 --- sc4pd/config-pd-linux.txt | 2 +- sc4pd/make-files.txt | 3 +- sc4pd/pd/hpf.pd | 11 +++ sc4pd/pd/lpf.pd | 11 +++ sc4pd/pd/rhpf.pd | 15 ++++ sc4pd/pd/rlpf.pd | 15 ++++ sc4pd/source/HPF.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/LPF.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/RHPF.cpp | 192 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/RLPF.cpp | 192 ++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/SOS.cpp | 10 +-- sc4pd/source/main.cpp | 10 ++- sc4pd/source/support.hpp | 9 +++ 13 files changed, 822 insertions(+), 8 deletions(-) create mode 100644 sc4pd/pd/hpf.pd create mode 100644 sc4pd/pd/lpf.pd create mode 100644 sc4pd/pd/rhpf.pd create mode 100644 sc4pd/pd/rlpf.pd create mode 100644 sc4pd/source/HPF.cpp create mode 100644 sc4pd/source/LPF.cpp create mode 100644 sc4pd/source/RHPF.cpp create mode 100644 sc4pd/source/RLPF.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 9b46ed4..1e95392 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) -# CXX=icc + CXX=icc # where does the PD installation reside? diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index d6e04d5..6e6c552 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -13,4 +13,5 @@ SRCS= \ Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ - TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp + TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp RLPF.cpp RHPF.cpp LPF.cpp \ + HPF.cpp diff --git a/sc4pd/pd/hpf.pd b/sc4pd/pd/hpf.pd new file mode 100644 index 0000000..82de175 --- /dev/null +++ b/sc4pd/pd/hpf.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X obj 130 147 HPF~ 10000; +#X connect 1 0 3 0; +#X connect 2 0 4 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; diff --git a/sc4pd/pd/lpf.pd b/sc4pd/pd/lpf.pd new file mode 100644 index 0000000..1b952d6 --- /dev/null +++ b/sc4pd/pd/lpf.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X obj 130 147 LPF~ 440; +#X connect 1 0 3 0; +#X connect 2 0 4 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; diff --git a/sc4pd/pd/rhpf.pd b/sc4pd/pd/rhpf.pd new file mode 100644 index 0000000..228f368 --- /dev/null +++ b/sc4pd/pd/rhpf.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X msg 271 121 kradius \$1; +#X obj 130 147 RHPF~ 10000 0; +#X connect 1 0 3 0; +#X connect 2 0 6 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; diff --git a/sc4pd/pd/rlpf.pd b/sc4pd/pd/rlpf.pd new file mode 100644 index 0000000..1203edb --- /dev/null +++ b/sc4pd/pd/rlpf.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X msg 271 121 kradius \$1; +#X obj 130 147 RLPF~ 440 0.5; +#X connect 1 0 3 0; +#X connect 2 0 6 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; diff --git a/sc4pd/source/HPF.cpp b/sc4pd/source/HPF.cpp new file mode 100644 index 0000000..85de643 --- /dev/null +++ b/sc4pd/source/HPF.cpp @@ -0,0 +1,180 @@ +/* sc4pd + HPF~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Peter Kowald & Tatsuya Nakatani: + 13 Definitions of Truth + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ HPF~ -------------------------------*/ + +class HPF_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(HPF_ar,sc4pd_dsp); + +public: + HPF_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + +private: + float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); +}; + +FLEXT_LIB_DSP_V("HPF~",HPF_ar); + +HPF_ar::HPF_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + changed = true; + + AddOutSignal(); + + m_a0 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void HPF_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float b1 = m_b1; + float b2 = m_b2; + + if (changed) + { + float pfreq = m_freq * mRadiansPerSample * 0.5; + + float C = tan(pfreq); + float C2 = C * C; + float sqrt2C = C * sqrt2; + float next_a0 = 1.f / (1.f + sqrt2C + C2); + float next_b1 = 2.f * (1.f - C2) * next_a0 ; + float next_b2 = -(1.f - sqrt2C + C2) * next_a0; + + float a0_slope = (next_a0 - a0) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 - 2.f * y0 + y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 - 2.f * y2 + y0); + + a0 += a0_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); + y2 = y1; + y1 = y0; + } + + m_a0 = a0; + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 - 2.f * y0 + y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 - 2.f * y2 + y0); + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - 2.f * y1 + y2); + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate HPF filter */ diff --git a/sc4pd/source/LPF.cpp b/sc4pd/source/LPF.cpp new file mode 100644 index 0000000..a11e784 --- /dev/null +++ b/sc4pd/source/LPF.cpp @@ -0,0 +1,180 @@ +/* sc4pd + LPF~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Peter Kowald & Tatsuya Nakatani: + 13 Definitions of Truth + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ LPF~ -------------------------------*/ + +class LPF_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(LPF_ar,sc4pd_dsp); + +public: + LPF_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + +private: + float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); +}; + +FLEXT_LIB_DSP_V("LPF~",LPF_ar); + +LPF_ar::LPF_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + changed = true; + + AddOutSignal(); + + m_a0 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void LPF_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float b1 = m_b1; + float b2 = m_b2; + + if (changed) + { + float pfreq = m_freq * mRadiansPerSample * 0.5; + + float C = 1.f / tan(pfreq); + float C2 = C * C; + float sqrt2C = C * sqrt2; + float next_a0 = 1.f / (1.f + sqrt2C + C2); + float next_b1 = -2.f * (1.f - C2) * next_a0 ; + float next_b2 = -(1.f - sqrt2C + C2) * next_a0; + + float a0_slope = (next_a0 - a0) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 + 2.f * y1 + y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 + 2.f * y0 + y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 + 2.f * y2 + y0); + + a0 += a0_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 + 2.f * y1 + y2); + y2 = y1; + y1 = y0; + } + + m_a0 = a0; + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 + 2.f * y1 + y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 + 2.f * y0 + y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 + 2.f * y2 + y0); + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 + 2.f * y1 + y2); + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate LPF filter */ diff --git a/sc4pd/source/RHPF.cpp b/sc4pd/source/RHPF.cpp new file mode 100644 index 0000000..fb79d2b --- /dev/null +++ b/sc4pd/source/RHPF.cpp @@ -0,0 +1,192 @@ +/* sc4pd + RHPF~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Peter Kowald & Tatsuya Nakatani: + 13 Definitions of Truth + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ RHPF~ -------------------------------*/ + +class RHPF_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(RHPF_ar,sc4pd_dsp); + +public: + RHPF_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_rq(float f) + { + m_reson=f; + changed = true; + } + + +private: + float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_reson; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_rq); +}; + +FLEXT_LIB_DSP_V("RHPF~",RHPF_ar); + +RHPF_ar::RHPF_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"krq",m_set_rq); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_reson = sc_getfloatarg(Args,1); + changed = true; + + AddOutSignal(); + + m_a0 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void RHPF_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float b1 = m_b1; + float b2 = m_b2; + + if (changed) + { + float qres = sc_max(0.001, m_reson); + float pfreq = m_freq * mRadiansPerSample; + + float D = tan(pfreq * qres * 0.5); + float C = ((1.f-D)/(1.f+D)); + float cosf = cos(pfreq); + + float next_b1 = (1.f + C) * cosf; + float next_b2 = -C; + float next_a0 = (1.f + C + next_b1) * .25; + + float a0_slope = (next_a0 - a0) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 - 2.f * y1 + y2; + + y2 = a0 * ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = y2 - 2.f * y0 + y1; + + y1 = a0 * ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = y1 - 2.f * y2 + y0; + + a0 += a0_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 - 2.f * y1 + y2; + y2 = y1; + y1 = y0; + } + + m_a0 = a0; + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 - 2.f * y1 + y2; + + y2 = a0 * ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = y2 - 2.f * y0 + y1; + + y1 = a0 * ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = y1 - 2.f * y2 + y0; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 - 2.f * y1 + y2; + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate RHPF filter */ diff --git a/sc4pd/source/RLPF.cpp b/sc4pd/source/RLPF.cpp new file mode 100644 index 0000000..89fc46c --- /dev/null +++ b/sc4pd/source/RLPF.cpp @@ -0,0 +1,192 @@ +/* sc4pd + RLPF~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Peter Kowald & Tatsuya Nakatani: + 13 Definitions of Truth + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ RLPF~ -------------------------------*/ + +class RLPF_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(RLPF_ar,sc4pd_dsp); + +public: + RLPF_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_rq(float f) + { + m_reson=f; + changed = true; + } + + +private: + float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_reson; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_rq); +}; + +FLEXT_LIB_DSP_V("RLPF~",RLPF_ar); + +RLPF_ar::RLPF_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"rq",m_set_rq); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_reson = sc_getfloatarg(Args,1); + changed = true; + + AddOutSignal(); + + m_a0 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void RLPF_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float b1 = m_b1; + float b2 = m_b2; + + if (changed) + { + float qres = sc_max(0.001, m_reson); + float pfreq = m_freq * mRadiansPerSample; + + float D = tan(pfreq * qres * 0.5); + float C = ((1.f-D)/(1.f+D)); + float cosf = cos(pfreq); + + float next_b1 = (1.f + C) * cosf; + float next_b2 = -C; + float next_a0 = (1.f + C - next_b1) * .25; + + float a0_slope = (next_a0 - a0) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 + 2.f * y1 + y2; + + y2 = a0 * ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = y2 + 2.f * y0 + y1; + + y1 = a0 * ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = y1 + 2.f * y2 + y0; + + a0 += a0_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 + 2.f * y1 + y2; + y2 = y1; + y1 = y0; + } + + m_a0 = a0; + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 + 2.f * y1 + y2; + + y2 = a0 * ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = y2 + 2.f * y0 + y1; + + y1 = a0 * ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = y1 + 2.f * y2 + y0; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = a0 * ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = y0 + 2.f * y1 + y2; + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate RLPF filter */ diff --git a/sc4pd/source/SOS.cpp b/sc4pd/source/SOS.cpp index 996833a..29aaecb 100644 --- a/sc4pd/source/SOS.cpp +++ b/sc4pd/source/SOS.cpp @@ -143,13 +143,13 @@ SOS_ar::SOS_ar(int argc, t_atom *argv) if(sc_ar(Args)) { - SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); AddInSignal(); AddInSignal(); AddInSignal(); AddInSignal(); AddInSignal(); AddInSignal(); + SETSIGFUN(m_signal_fun,SIGFUN(m_signal_ar)); } else // if not given, use control rate SETSIGFUN(m_signal_fun,SIGFUN(m_signal_kr)); @@ -190,15 +190,15 @@ void SOS_ar::m_signal_ar(int n, t_sample *const *in, y1 = ZXP(nin) + ZXP(b1) * y2 + ZXP(b2) * y0; ZXP(nout) = ZXP(a0) * y1 + ZXP(a1) * y2 + ZXP(a2) * y0; } - - for (int i = 0; i!= mFilterLoops;++i) + + for (int i = 0; i!= mFilterRemain;++i) { y0 = ZXP(nin) + ZXP(b1) * y1 + ZXP(b2) * y2; ZXP(nout) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2; y2 = y1; y1 = y0; } - + m_y1 = zapgremlins(y1); m_y2 = zapgremlins(y2); @@ -243,7 +243,7 @@ void SOS_ar::m_signal_kr(int n, t_sample *const *in, b2 += b2_slope; } - for (int i = 0; i!= mFilterLoops;++i) + for (int i = 0; i!= mFilterRemain;++i) { y0 = ZXP(nin) + b1 * y1 + b2 * y2; ZXP(nout) = a0 * y0 + a1 * y1 + a2 * y2; diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 3430ee4..f01a7ad 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -64,7 +64,7 @@ void sc4pd_library_setup() "AllpassL~,\n" " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~), " "TwoPole~, \n" - " TwoZero~, FOS(~), SOS~" + " TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~" "\n" ); @@ -249,6 +249,14 @@ void sc4pd_library_setup() FLEXT_SETUP(FOS_kr); FLEXT_DSP_SETUP(SOS_ar); + + FLEXT_DSP_SETUP(RLPF_ar); + + FLEXT_DSP_SETUP(RHPF_ar); + + FLEXT_DSP_SETUP(LPF_ar); + + FLEXT_DSP_SETUP(HPF_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index 6b51f2b..3972c83 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -122,5 +122,14 @@ WARRANTIES, see the file, "license.txt," in this distribution. #define SIGFUN(FUN) &thisType::FUN +#undef F +#undef D +#undef I +#undef L +#undef C +#undef V +#undef BL +#undef S + #endif -- cgit v1.2.1 From 0929d45ec8791bed5f9e48a9232f30504b77dde9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 8 Aug 2004 16:29:26 +0000 Subject: brf & bpf svn path=/trunk/externals/tb/; revision=1919 --- sc4pd/make-files.txt | 2 +- sc4pd/pd/bpf.pd | 15 ++++ sc4pd/pd/brf.pd | 15 ++++ sc4pd/source/BPF.cpp | 190 +++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/BRF.cpp | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 7 +- 6 files changed, 426 insertions(+), 2 deletions(-) create mode 100644 sc4pd/pd/bpf.pd create mode 100644 sc4pd/pd/brf.pd create mode 100644 sc4pd/source/BPF.cpp create mode 100644 sc4pd/source/BRF.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 6e6c552..3f7bdc8 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -14,4 +14,4 @@ SRCS= \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp RLPF.cpp RHPF.cpp LPF.cpp \ - HPF.cpp + HPF.cpp BPF.cpp BRF.cpp diff --git a/sc4pd/pd/bpf.pd b/sc4pd/pd/bpf.pd new file mode 100644 index 0000000..5255af9 --- /dev/null +++ b/sc4pd/pd/bpf.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X obj 130 147 BPF~ 440 0.5; +#X msg 271 121 krq \$1; +#X connect 1 0 3 0; +#X connect 2 0 5 0; +#X connect 3 0 5 0; +#X connect 4 0 6 0; +#X connect 5 0 0 0; +#X connect 5 0 0 1; +#X connect 6 0 5 0; diff --git a/sc4pd/pd/brf.pd b/sc4pd/pd/brf.pd new file mode 100644 index 0000000..df92c7c --- /dev/null +++ b/sc4pd/pd/brf.pd @@ -0,0 +1,15 @@ +#N canvas 0 0 450 300 10; +#X obj 124 220 dac~; +#X floatatom 224 81 5 0 0 0 - - -; +#X obj 130 89 WhiteNoise~; +#X msg 201 121 kfreq \$1; +#X floatatom 294 81 5 0 0 0 - - -; +#X msg 271 121 krq \$1; +#X obj 130 147 BRF~ 4440 4.3; +#X connect 1 0 3 0; +#X connect 2 0 6 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 6 0 0 0; +#X connect 6 0 0 1; diff --git a/sc4pd/source/BPF.cpp b/sc4pd/source/BPF.cpp new file mode 100644 index 0000000..f998dd4 --- /dev/null +++ b/sc4pd/source/BPF.cpp @@ -0,0 +1,190 @@ +/* sc4pd + BPF~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Jo Kondo: Works For Piano + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ BPF~ -------------------------------*/ + +class BPF_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(BPF_ar,sc4pd_dsp); + +public: + BPF_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_rq(float f) + { + m_bw=f; + changed = true; + } + + +private: + float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_bw; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_rq); +}; + +FLEXT_LIB_DSP_V("BPF~",BPF_ar); + +BPF_ar::BPF_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"krq",m_set_rq); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_bw = sc_getfloatarg(Args,1); + changed = true; + + AddOutSignal(); + + m_a0 = 0.f; + m_b1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void BPF_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float b1 = m_b1; + float b2 = m_b2; + + if (changed) + { + float pfreq = m_freq * mRadiansPerSample; + float pbw = m_bw * pfreq * 0.5; + + float C = 1.f / tan(pbw); + float D = 2.f * cos(pfreq); + + float next_a0 = 1.f / (1.f + C); + float next_b1 = C * D * next_a0 ; + float next_b2 = (1.f - C) * next_a0; + + float a0_slope = (next_a0 - a0) * mFilterSlope; + float b1_slope = (next_b1 - b1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 - y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 - y0); + + a0 += a0_slope; + b1 += b1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + y2 = y1; + y1 = y0; + } + + m_a0 = a0; + m_b1 = b1; + m_b2 = b2; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + + y2 = ZXP(nin) + b1 * y0 + b2 * y1; + ZXP(nout) = a0 * (y2 - y1); + + y1 = ZXP(nin) + b1 * y2 + b2 * y0; + ZXP(nout) = a0 * (y1 - y0); + } + + for (int i = 0; i!= mFilterRemain;++i) + { + y0 = ZXP(nin) + b1 * y1 + b2 * y2; + ZXP(nout) = a0 * (y0 - y2); + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate BPF filter */ diff --git a/sc4pd/source/BRF.cpp b/sc4pd/source/BRF.cpp new file mode 100644 index 0000000..e6db680 --- /dev/null +++ b/sc4pd/source/BRF.cpp @@ -0,0 +1,199 @@ +/* sc4pd + BRF~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Jo Kondo: Works For Piano + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ BRF~ -------------------------------*/ + +class BRF_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(BRF_ar,sc4pd_dsp); + +public: + BRF_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mRadiansPerSample = sc_radianspersample(); + mFilterSlope = sc_filterslope(); + mFilterLoops = sc_filterloops(); + mFilterRemain = sc_filterremain(); + } + + void m_set_freq(float f) + { + m_freq=f; + changed = true; + } + + void m_set_rq(float f) + { + m_bw=f; + changed = true; + } + + +private: + float m_y1, m_y2, m_a0, m_a1, m_b2, m_freq, m_bw; + bool changed; + float mRadiansPerSample, mFilterSlope; + int mFilterLoops, mFilterRemain; + + FLEXT_CALLBACK_F(m_set_freq); + FLEXT_CALLBACK_F(m_set_rq); +}; + +FLEXT_LIB_DSP_V("BRF~",BRF_ar); + +BRF_ar::BRF_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"kfreq",m_set_freq); + FLEXT_ADDMETHOD_(0,"krq",m_set_rq); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + m_bw = sc_getfloatarg(Args,1); + changed = true; + + AddOutSignal(); + + m_a0 = 0.f; + m_a1 = 0.f; + m_b2 = 0.f; + m_y1 = 0.f; + m_y2 = 0.f; +} + +void BRF_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float ay; + float y0; + float y1 = m_y1; + float y2 = m_y2; + float a0 = m_a0; + float a1 = m_a1; + float b2 = m_b2; + + if (changed) + { + float pfreq = m_freq * mRadiansPerSample; + float pbw = m_bw * pfreq * 0.5; + + float C = tan(pbw); + float D = 2.f * cos(pfreq); + + float next_a0 = 1.f / (1.f + C); + float next_a1 = -D * next_a0; + float next_b2 = (1.f - C) * next_a0; + + float a0_slope = (next_a0 - a0) * mFilterSlope; + float a1_slope = (next_a1 - a1) * mFilterSlope; + float b2_slope = (next_b2 - b2) * mFilterSlope; + + for (int i = 0; i!= mFilterLoops;++i) + { + ay = a1 * y1; + y0 = ZXP(nin) - ay - b2 * y2; + ZXP(nout) = a0 * (y0 + y2) + ay; + + ay = a1 * y0; + y2 = ZXP(nin) - ay - b2 * y1; + ZXP(nout) = a0 * (y2 + y1) + ay; + + ay = a1 * y2; + y1 = ZXP(nin) - ay - b2 * y0; + ZXP(nout) = a0 * (y1 + y0) + ay; + + a0 += a0_slope; + a1 += a1_slope; + b2 += b2_slope; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + ay = a1 * y1; + y0 = ZXP(nin) - ay - b2 * y2; + ZXP(nout) = a0 * (y0 + y2) + ay; + y2 = y1; + y1 = y0; + } + + m_a0 = a0; + m_a1 = a1; + m_b2 = b2; + changed = false; + } + else + { + for (int i = 0; i!= mFilterLoops;++i) + { + ay = a1 * y1; + y0 = ZXP(nin) - ay - b2 * y2; + ZXP(nout) = a0 * (y0 + y2) + ay; + + ay = a1 * y0; + y2 = ZXP(nin) - ay - b2 * y1; + ZXP(nout) = a0 * (y2 + y1) + ay; + + ay = a1 * y2; + y1 = ZXP(nin) - ay - b2 * y0; + ZXP(nout) = a0 * (y1 + y0) + ay; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + ay = a1 * y1; + y0 = ZXP(nin) - ay - b2 * y2; + ZXP(nout) = a0 * (y0 + y2) + ay; + y2 = y1; + y1 = y0; + } + } + m_y1 = zapgremlins(y1); + m_y2 = zapgremlins(y2); +} + +/* no control rate BRF filter */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index f01a7ad..6d35894 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -64,7 +64,8 @@ void sc4pd_library_setup() "AllpassL~,\n" " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~), " "TwoPole~, \n" - " TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~" + " TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~, BPF~, " + "BRF~" "\n" ); @@ -257,6 +258,10 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(LPF_ar); FLEXT_DSP_SETUP(HPF_ar); + + FLEXT_DSP_SETUP(BPF_ar); + + FLEXT_DSP_SETUP(BRF_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From df2f875502b072f3e4cadb359bdec2bac8b0619f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 8 Aug 2004 17:30:20 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=1920 --- sc4pd/make-files.txt | 3 ++- sc4pd/source/main.cpp | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 3f7bdc8..69162da 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -14,4 +14,5 @@ SRCS= \ DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp RLPF.cpp RHPF.cpp LPF.cpp \ - HPF.cpp BPF.cpp BRF.cpp + HPF.cpp BPF.cpp BRF.cpp LPZ1.cpp HPZ1.cpp LPZ2.cpp HPZ2.cpp \ + BPZ2.cpp BRZ2.cpp diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 6d35894..8216421 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -65,7 +65,8 @@ void sc4pd_library_setup() " AllpassC~, PitchShift~, Resonz~, OnePole(~), OneZero(~), " "TwoPole~, \n" " TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~, BPF~, " - "BRF~" + "BRF~,\n" + " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~)" "\n" ); @@ -262,6 +263,24 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(BPF_ar); FLEXT_DSP_SETUP(BRF_ar); + + FLEXT_DSP_SETUP(LPZ1_ar); + FLEXT_SETUP(LPZ1_kr); + + FLEXT_DSP_SETUP(HPZ1_ar); + FLEXT_SETUP(HPZ1_kr); + + FLEXT_DSP_SETUP(LPZ2_ar); + FLEXT_SETUP(LPZ2_kr); + + FLEXT_DSP_SETUP(HPZ2_ar); + FLEXT_SETUP(HPZ2_kr); + + FLEXT_DSP_SETUP(BRZ2_ar); + FLEXT_SETUP(BRZ2_kr); + + FLEXT_DSP_SETUP(BPZ2_ar); + FLEXT_SETUP(BPZ2_kr); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); -- cgit v1.2.1 From 7c4d1b479aa72612d9fcab875a88b3ec6c218773 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 8 Aug 2004 17:34:16 +0000 Subject: some filters svn path=/trunk/externals/tb/; revision=1921 --- sc4pd/pd/bpz2.pd | 12 +++++ sc4pd/pd/brz2.pd | 12 +++++ sc4pd/pd/hpz1.pd | 12 +++++ sc4pd/pd/lpz1.pd | 12 +++++ sc4pd/pd/lpz2.pd | 12 +++++ sc4pd/source/BPZ2.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/BRZ2.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/HPZ1.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/HPZ2.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/LPZ1.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/LPZ2.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 884 insertions(+) create mode 100644 sc4pd/pd/bpz2.pd create mode 100644 sc4pd/pd/brz2.pd create mode 100644 sc4pd/pd/hpz1.pd create mode 100644 sc4pd/pd/lpz1.pd create mode 100644 sc4pd/pd/lpz2.pd create mode 100644 sc4pd/source/BPZ2.cpp create mode 100644 sc4pd/source/BRZ2.cpp create mode 100644 sc4pd/source/HPZ1.cpp create mode 100644 sc4pd/source/HPZ2.cpp create mode 100644 sc4pd/source/LPZ1.cpp create mode 100644 sc4pd/source/LPZ2.cpp diff --git a/sc4pd/pd/bpz2.pd b/sc4pd/pd/bpz2.pd new file mode 100644 index 0000000..ffa4c77 --- /dev/null +++ b/sc4pd/pd/bpz2.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 266 78 HPZ2; +#X obj 18 86 BPZ2~; +#X connect 1 0 4 0; +#X connect 3 0 5 0; +#X connect 4 0 2 0; +#X connect 5 0 0 0; +#X connect 5 0 0 1; diff --git a/sc4pd/pd/brz2.pd b/sc4pd/pd/brz2.pd new file mode 100644 index 0000000..5e61752 --- /dev/null +++ b/sc4pd/pd/brz2.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 18 86 BRZ2~; +#X obj 266 78 BRZ2; +#X connect 1 0 5 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 5 0 2 0; diff --git a/sc4pd/pd/hpz1.pd b/sc4pd/pd/hpz1.pd new file mode 100644 index 0000000..1396d40 --- /dev/null +++ b/sc4pd/pd/hpz1.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 266 78 HPZ1; +#X obj 18 86 HPZ1~; +#X obj 18 28 WhiteNoise~; +#X connect 1 0 3 0; +#X connect 3 0 2 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 5 0 4 0; diff --git a/sc4pd/pd/lpz1.pd b/sc4pd/pd/lpz1.pd new file mode 100644 index 0000000..fa413b3 --- /dev/null +++ b/sc4pd/pd/lpz1.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 86 LPZ1~; +#X obj 266 78 LPZ1; +#X obj 18 28 WhiteNoise~; +#X connect 1 0 4 0; +#X connect 3 0 0 0; +#X connect 3 0 0 1; +#X connect 4 0 2 0; +#X connect 5 0 3 0; diff --git a/sc4pd/pd/lpz2.pd b/sc4pd/pd/lpz2.pd new file mode 100644 index 0000000..a665b96 --- /dev/null +++ b/sc4pd/pd/lpz2.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 12 159 dac~; +#X floatatom 265 37 9 0 0 0 - - -; +#X floatatom 266 110 9 0 0 0 - - -; +#X obj 18 28 WhiteNoise~; +#X obj 18 86 LPZ2~; +#X obj 266 78 LPZ2; +#X connect 1 0 5 0; +#X connect 3 0 4 0; +#X connect 4 0 0 0; +#X connect 4 0 0 1; +#X connect 5 0 2 0; diff --git a/sc4pd/source/BPZ2.cpp b/sc4pd/source/BPZ2.cpp new file mode 100644 index 0000000..a18a9dc --- /dev/null +++ b/sc4pd/source/BPZ2.cpp @@ -0,0 +1,140 @@ +/* sc4pd + BPZ2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: William Parker: Compassion Seizes Bed-Stuy + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ BPZ2~ -------------------------------*/ + +class BPZ2_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(BPZ2_ar,sc4pd_dsp); + +public: + BPZ2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mFilterLoops=sc_filterloops(); + mFilterRemain=sc_filterremain(); + } + +private: + float m_x1, m_x2; + int mFilterLoops, mFilterRemain; +}; + +FLEXT_LIB_DSP_V("BPZ2~",BPZ2_ar); + +BPZ2_ar::BPZ2_ar(int argc, t_atom *argv) +{ + AddOutSignal(); + + m_x1=0; + m_x2=0; +} + +void BPZ2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + float x2 = m_x2; + + for (int i = 0; i!=mFilterLoops ;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 - x2) * 0.5f; + x2 = ZXP(nin); + ZXP(nout) = (x2 - x1) * 0.5f; + x1 = ZXP(nin); + ZXP(nout) = (x1 - x0) * 0.5f; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 - x2) * 0.5f; + x2 = x1; + x1 = x0; + } + m_x1 = x1; + m_x2 = x2; +} + +/* ------------------------ BPZ2 -------------------------------*/ + +class BPZ2_kr: + public flext_base +{ + FLEXT_HEADER(BPZ2_kr,flext_base); + +public: + BPZ2_kr(int argc, t_atom *argv); + +protected: + void m_perform (float f); + +private: + float m_x1; + float m_x2; + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("BPZ2",BPZ2_kr); + +BPZ2_kr::BPZ2_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + + AddOutFloat(); + + m_x2 = m_x1 = 0; +} + +void BPZ2_kr::m_perform(float f) +{ + ToOutFloat(0,(f - m_x2) * 0.5f); + m_x2=m_x1; + m_x1=f; +} + diff --git a/sc4pd/source/BRZ2.cpp b/sc4pd/source/BRZ2.cpp new file mode 100644 index 0000000..4c14fa2 --- /dev/null +++ b/sc4pd/source/BRZ2.cpp @@ -0,0 +1,140 @@ +/* sc4pd + BRZ2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: William Parker: Compassion Seizes Bed-Stuy + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ BRZ2~ -------------------------------*/ + +class BRZ2_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(BRZ2_ar,sc4pd_dsp); + +public: + BRZ2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mFilterLoops=sc_filterloops(); + mFilterRemain=sc_filterremain(); + } + +private: + float m_x1, m_x2; + int mFilterLoops, mFilterRemain; +}; + +FLEXT_LIB_DSP_V("BRZ2~",BRZ2_ar); + +BRZ2_ar::BRZ2_ar(int argc, t_atom *argv) +{ + AddOutSignal(); + + m_x1=0; + m_x2=0; +} + +void BRZ2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + float x2 = m_x2; + + for (int i = 0; i!=mFilterLoops ;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 + x2) * 0.5f; + x2 = ZXP(nin); + ZXP(nout) = (x2 + x1) * 0.5f; + x1 = ZXP(nin); + ZXP(nout) = (x1 + x0) * 0.5f; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 + x2) * 0.5f; + x2 = x1; + x1 = x0; + } + m_x1 = x1; + m_x2 = x2; +} + +/* ------------------------ BRZ2 -------------------------------*/ + +class BRZ2_kr: + public flext_base +{ + FLEXT_HEADER(BRZ2_kr,flext_base); + +public: + BRZ2_kr(int argc, t_atom *argv); + +protected: + void m_perform (float f); + +private: + float m_x1; + float m_x2; + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("BRZ2",BRZ2_kr); + +BRZ2_kr::BRZ2_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + + AddOutFloat(); + + m_x2 = m_x1 = 0; +} + +void BRZ2_kr::m_perform(float f) +{ + ToOutFloat(0,(f + m_x2) * 0.5f); + m_x2=m_x1; + m_x1=f; +} + diff --git a/sc4pd/source/HPZ1.cpp b/sc4pd/source/HPZ1.cpp new file mode 100644 index 0000000..0ab5f91 --- /dev/null +++ b/sc4pd/source/HPZ1.cpp @@ -0,0 +1,132 @@ +/* sc4pd + HPZ1~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: William Parker: Compassion Seizes Bed-Stuy + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ HPZ1~ -------------------------------*/ + +class HPZ1_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(HPZ1_ar,sc4pd_dsp); + +public: + HPZ1_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + float m_x1; +}; + +FLEXT_LIB_DSP_V("HPZ1~",HPZ1_ar); + +HPZ1_ar::HPZ1_ar(int argc, t_atom *argv) +{ + AddOutSignal(); + + m_x1=0; +} + +void HPZ1_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + + int t = n >> 2; + for (int i = 0; i!= t;++i) + { + x0 = ZXP(nin); + ZXP(nout) = 0.5f * (x0 - x1); + x1 = ZXP(nin); + ZXP(nout) = 0.5f * (x1 - x0); + x0 = ZXP(nin); + ZXP(nout) = 0.5f * (x0 - x1); + x1 = ZXP(nin); + ZXP(nout) = 0.5f * (x1 - x0); + } + + t = n & 3; + for (int i = 0; i!= t;++i) + { + x0 = ZXP(nin); + ZXP(nout) = 0.5f * (x0 - x1); + x1 = x0; + } + m_x1 = x1; +} + +/* ------------------------ HPZ1 -------------------------------*/ + +class HPZ1_kr: + public flext_base +{ + FLEXT_HEADER(HPZ1_kr,flext_base); + +public: + HPZ1_kr(int argc, t_atom *argv); + +protected: + void m_perform (float f); + +private: + float m_x1; + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("HPZ1",HPZ1_kr); + +HPZ1_kr::HPZ1_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + + AddOutFloat(); + + m_x1=0; +} + +void HPZ1_kr::m_perform(float f) +{ + ToOutFloat(0,0.5f * (f - m_x1)); + m_x1=f; +} + diff --git a/sc4pd/source/HPZ2.cpp b/sc4pd/source/HPZ2.cpp new file mode 100644 index 0000000..c561455 --- /dev/null +++ b/sc4pd/source/HPZ2.cpp @@ -0,0 +1,140 @@ +/* sc4pd + HPZ2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: William Parker: Compassion Seizes Bed-Stuy + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ HPZ2~ -------------------------------*/ + +class HPZ2_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(HPZ2_ar,sc4pd_dsp); + +public: + HPZ2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mFilterLoops=sc_filterloops(); + mFilterRemain=sc_filterremain(); + } + +private: + float m_x1, m_x2; + int mFilterLoops, mFilterRemain; +}; + +FLEXT_LIB_DSP_V("HPZ2~",HPZ2_ar); + +HPZ2_ar::HPZ2_ar(int argc, t_atom *argv) +{ + AddOutSignal(); + + m_x1=0; + m_x2=0; +} + +void HPZ2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + float x2 = m_x2; + + for (int i = 0; i!=mFilterLoops ;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 - 2.f * x1 + x2) * 0.25f; + x2 = ZXP(nin); + ZXP(nout) = (x2 - 2.f * x0 + x1) * 0.25f; + x1 = ZXP(nin); + ZXP(nout) = (x1 - 2.f * x2 + x0) * 0.25f; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 - 2.f * x1 + x2) * 0.25f; + x2 = x1; + x1 = x0; + } + m_x1 = x1; + m_x2 = x2; +} + +/* ------------------------ HPZ2 -------------------------------*/ + +class HPZ2_kr: + public flext_base +{ + FLEXT_HEADER(HPZ2_kr,flext_base); + +public: + HPZ2_kr(int argc, t_atom *argv); + +protected: + void m_perform (float f); + +private: + float m_x1; + float m_x2; + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("HPZ2",HPZ2_kr); + +HPZ2_kr::HPZ2_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + + AddOutFloat(); + + m_x2 = m_x1 = 0; +} + +void HPZ2_kr::m_perform(float f) +{ + ToOutFloat(0,(f - 2.f * m_x1 + m_x2) * 0.25f); + m_x2=m_x1; + m_x1=f; +} + diff --git a/sc4pd/source/LPZ1.cpp b/sc4pd/source/LPZ1.cpp new file mode 100644 index 0000000..70e495b --- /dev/null +++ b/sc4pd/source/LPZ1.cpp @@ -0,0 +1,132 @@ +/* sc4pd + LPZ1~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: William Parker: Compassion Seizes Bed-Stuy + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ LPZ1~ -------------------------------*/ + +class LPZ1_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(LPZ1_ar,sc4pd_dsp); + +public: + LPZ1_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + +private: + float m_x1; +}; + +FLEXT_LIB_DSP_V("LPZ1~",LPZ1_ar); + +LPZ1_ar::LPZ1_ar(int argc, t_atom *argv) +{ + AddOutSignal(); + + m_x1=0; +} + +void LPZ1_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + + int t = n >> 2; + for (int i = 0; i!= t;++i) + { + x0 = ZXP(nin); + ZXP(nout) = 0.5f * (x0 + x1); + x1 = ZXP(nin); + ZXP(nout) = 0.5f * (x1 + x0); + x0 = ZXP(nin); + ZXP(nout) = 0.5f * (x0 + x1); + x1 = ZXP(nin); + ZXP(nout) = 0.5f * (x1 + x0); + } + + t = n & 3; + for (int i = 0; i!= t;++i) + { + x0 = ZXP(nin); + ZXP(nout) = 0.5f * (x0 + x1); + x1 = x0; + } + m_x1 = x1; +} + +/* ------------------------ LPZ1 -------------------------------*/ + +class LPZ1_kr: + public flext_base +{ + FLEXT_HEADER(LPZ1_kr,flext_base); + +public: + LPZ1_kr(int argc, t_atom *argv); + +protected: + void m_perform (float f); + +private: + float m_x1; + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("LPZ1",LPZ1_kr); + +LPZ1_kr::LPZ1_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + + AddOutFloat(); + + m_x1=0; +} + +void LPZ1_kr::m_perform(float f) +{ + ToOutFloat(0,0.5f * (f + m_x1)); + m_x1=f; +} + diff --git a/sc4pd/source/LPZ2.cpp b/sc4pd/source/LPZ2.cpp new file mode 100644 index 0000000..4165690 --- /dev/null +++ b/sc4pd/source/LPZ2.cpp @@ -0,0 +1,140 @@ +/* sc4pd + LPZ2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: William Parker: Compassion Seizes Bed-Stuy + +*/ + +#include "sc4pd.hpp" + +/* ------------------------ LPZ2~ -------------------------------*/ + +class LPZ2_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(LPZ2_ar,sc4pd_dsp); + +public: + LPZ2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out) + { + mFilterLoops=sc_filterloops(); + mFilterRemain=sc_filterremain(); + } + +private: + float m_x1, m_x2; + int mFilterLoops, mFilterRemain; +}; + +FLEXT_LIB_DSP_V("LPZ2~",LPZ2_ar); + +LPZ2_ar::LPZ2_ar(int argc, t_atom *argv) +{ + AddOutSignal(); + + m_x1=0; + m_x2=0; +} + +void LPZ2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + float x0; + float x1 = m_x1; + float x2 = m_x2; + + for (int i = 0; i!=mFilterLoops ;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 + 2.f * x1 + x2) * 0.25f; + x2 = ZXP(nin); + ZXP(nout) = (x2 + 2.f * x0 + x1) * 0.25f; + x1 = ZXP(nin); + ZXP(nout) = (x1 + 2.f * x2 + x0) * 0.25f; + } + + for (int i = 0; i!= mFilterRemain;++i) + { + x0 = ZXP(nin); + ZXP(nout) = (x0 + 2.f * x1 + x2) * 0.25f; + x2 = x1; + x1 = x0; + } + m_x1 = x1; + m_x2 = x2; +} + +/* ------------------------ LPZ2 -------------------------------*/ + +class LPZ2_kr: + public flext_base +{ + FLEXT_HEADER(LPZ2_kr,flext_base); + +public: + LPZ2_kr(int argc, t_atom *argv); + +protected: + void m_perform (float f); + +private: + float m_x1; + float m_x2; + FLEXT_CALLBACK_F(m_perform); +}; + +FLEXT_LIB_V("LPZ2",LPZ2_kr); + +LPZ2_kr::LPZ2_kr(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(0,m_perform); + + AddOutFloat(); + + m_x2 = m_x1 = 0; +} + +void LPZ2_kr::m_perform(float f) +{ + ToOutFloat(0,(f + 2.f * m_x1 + m_x2) * 0.25f); + m_x2=m_x1; + m_x1=f; +} + -- cgit v1.2.1 From 652996b3720ddc909d1711b106618ae6d910d87f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 30 Aug 2004 13:52:39 +0000 Subject: removed some obsolete externals svn path=/trunk/externals/tb/; revision=1978 --- tbext/source/main.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index bb7c517..39ac8b2 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -48,17 +48,16 @@ void ttbext_setup() { - post("TBEXT: by tim blechmann"); + post("\nTBEXT: by tim blechmann"); post("version "TBEXT_VERSION); post("compiled on "__DATE__); - post("contains: tbroute(~), tbsig~, tbpow~, tbfft1~, tbfft2~, bufline~, fftgrrev~"); - post(" fftgrsort~, fftgrshuf~, him~"); + post("contains: tbroute(~), tbfft1~, tbfft2~, bufline~, fftgrrev~"); + post(" fftgrsort~, fftgrshuf~, him~\n"); FLEXT_SETUP(tbroute); FLEXT_DSP_SETUP(tbsroute); - FLEXT_DSP_SETUP(tbsig); - FLEXT_DSP_SETUP(tbpow); - // FLEXT_DSP_SETUP(tbg7xx); + /* obsolete: FLEXT_DSP_SETUP(tbsig); */ + /* obsolete: FLEXT_DSP_SETUP(tbpow); */ FLEXT_DSP_SETUP(tbfft1); FLEXT_DSP_SETUP(tbfft2); FLEXT_DSP_SETUP(fftbuf); -- cgit v1.2.1 From e37d21ff39bdb356591240aa338db903761379d0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 30 Aug 2004 13:55:11 +0000 Subject: obsolete svn path=/trunk/externals/tb/; revision=1979 --- tbext/source/tbpow~.cpp | 100 ------------------------------------------------ tbext/source/tbsig~.cpp | 85 ---------------------------------------- 2 files changed, 185 deletions(-) delete mode 100644 tbext/source/tbpow~.cpp delete mode 100644 tbext/source/tbsig~.cpp diff --git a/tbext/source/tbpow~.cpp b/tbext/source/tbpow~.cpp deleted file mode 100644 index 14a383c..0000000 --- a/tbext/source/tbpow~.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (c) 2003 Tim Blechmann. */ -/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ -/* WARRANTIES, see the file, "COPYING" in this distribution. */ -/* */ -/* */ -/* tbpow~ calculates the power of each sample. In fact i expected it to sound */ -/* better than it does. but maybe someone is interested in using it... */ -/* */ -/* */ -/* tbpow~ uses the flext C++ layer for Max/MSP and PD externals. */ -/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ -/* thanks to Thomas Grill */ -/* */ -/* */ -/* */ -/* This program is free software; you can redistribute it and/or */ -/* modify it under the terms of the GNU General Public License */ -/* as published by the Free Software Foundation; either version 2 */ -/* of the License, or (at your option) any later version. */ -/* */ -/* See file LICENSE for further informations on licensing terms. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* */ -/* Based on PureData by Miller Puckette and others. */ -/* */ -/* */ -/* */ -/* coded while listening to: Assif Tsahar & Susie Ibarra: Home Cookin' */ -/* Painkiller: Talisman */ -/* */ - - - -#include - -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) -#error upgrade your flext version!!!!!! -#endif - -class tbpow: public flext_dsp -{ - FLEXT_HEADER(tbpow,flext_dsp); - -public: // constructor - tbpow(); - -protected: - virtual void m_signal (int n, float *const *in, float *const *out); - - void set_power(float f); - -private: - float power; - - FLEXT_CALLBACK_1(set_power,float) - -}; - - -FLEXT_LIB_DSP("tbpow~",tbpow); - -tbpow::tbpow() -{ - AddInSignal(); - AddInFloat(); - AddOutSignal(); - - FLEXT_ADDMETHOD(1,set_power); - power=1; -} - - -void tbpow::m_signal(int n, float *const *in, float *const *out) -{ - const float *ins=in[0]; - float *outs = out[0]; - - while (n--) - { - *outs = pow(*ins,power); - *outs++; - *ins++; - } - -} - -void tbpow::set_power(float f) -{ - power=f; -} diff --git a/tbext/source/tbsig~.cpp b/tbext/source/tbsig~.cpp deleted file mode 100644 index cda79cc..0000000 --- a/tbext/source/tbsig~.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (c) 2003 Tim Blechmann. */ -/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ -/* WARRANTIES, see the file, "COPYING" in this distribution. */ -/* */ -/* */ -/* tbsig~ is gives you the sign of an audio signal. should be useful to create */ -/* a square oscillator or some noisy sounds */ -/* */ -/* */ -/* tbsig~ uses the flext C++ layer for Max/MSP and PD externals. */ -/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ -/* thanks to Thomas Grill */ -/* */ -/* */ -/* */ -/* This program is free software; you can redistribute it and/or */ -/* modify it under the terms of the GNU General Public License */ -/* as published by the Free Software Foundation; either version 2 */ -/* of the License, or (at your option) any later version. */ -/* */ -/* See file LICENSE for further informations on licensing terms. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* */ -/* Based on PureData by Miller Puckette and others. */ -/* */ -/* */ -/* */ -/* coded while listening to: Peter Broetzmann & Hamid Drake: The Dried Rat-Dog */ -/* */ -/* */ - - - -#include - -#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 401) -#error upgrade your flext version!!!!!! -#endif - -class tbsig: public flext_dsp -{ - FLEXT_HEADER(tbsig,flext_dsp); - -public: // constructor - tbsig(); - -protected: - virtual void m_signal (int n, float *const *in, float *const *out); - -}; - - -FLEXT_LIB_DSP("tbsig~",tbsig); - -tbsig::tbsig() -{ - AddInSignal(); - AddOutSignal(); -} - - -void tbsig::m_signal(int n, float *const *in, float *const *out) -{ - const float *ins=in[0]; - float *outs = out[0]; - - while (n--) - { - if (*ins>0) - *outs = 1; - else - *outs = -1; - *outs++; - *ins++; - } - -} -- cgit v1.2.1 From 08f5624a15d0064acc4ea985e6f9e5f8df845bce Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 4 Sep 2004 21:27:12 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2003, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=2004 --- volctl~/gpl.txt | 346 +++++++++++++++++++++++++++++++++++++++++++++++++++++ volctl~/makefile | 94 +++++++++++++++ volctl~/readme.txt | 24 ++++ volctl~/volctl~.c | 274 ++++++++++++++++++++++++++++++++++++++++++ volctl~/volctl~.pd | 24 ++++ 5 files changed, 762 insertions(+) create mode 100644 volctl~/gpl.txt create mode 100644 volctl~/makefile create mode 100644 volctl~/readme.txt create mode 100644 volctl~/volctl~.c create mode 100644 volctl~/volctl~.pd diff --git a/volctl~/gpl.txt b/volctl~/gpl.txt new file mode 100644 index 0000000..5ea29a7 --- /dev/null +++ b/volctl~/gpl.txt @@ -0,0 +1,346 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + diff --git a/volctl~/makefile b/volctl~/makefile new file mode 100644 index 0000000..9b4cc04 --- /dev/null +++ b/volctl~/makefile @@ -0,0 +1,94 @@ +NAME=volctl~ +CSYM=volctl~ + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations diff --git a/volctl~/readme.txt b/volctl~/readme.txt new file mode 100644 index 0000000..5707467 --- /dev/null +++ b/volctl~/readme.txt @@ -0,0 +1,24 @@ +volctl~ + +a fast and smooth volume control external ... + +volctl~ is doing more or less the same as + + + |line~ 0 10 +| | | | | +|*~ 0| = |volctl 0 10| +| | + +except that it is faster + +argument1: initial factor +argument2: interpolation time + + +volctl~ will only probably only compile against pd>=devel_0_37 with gcc. +i'm not planing to do a port to win/osx or any pd without aligned dsp blocks... + +todo: +- write complete volctl_perform_simd function in assembler +- check icc's segfault \ No newline at end of file diff --git a/volctl~/volctl~.c b/volctl~/volctl~.c new file mode 100644 index 0000000..9ef96de --- /dev/null +++ b/volctl~/volctl~.c @@ -0,0 +1,274 @@ +/* Copyright (c) 2004 Tim Blechmann. + *For information on usage and redistribution, and for a DISCLAIMER OF ALL + *WARRANTIES, see the file, "gpl.txt" in this distribution. + * + *This program is free software; you can redistribute it and/or + *modify it under the terms of the GNU General Public License + *as published by the Free Software Foundation; either version 2 + *of the License, or (at your option) any later version. + * + *See file LICENSE for further informations on licensing terms. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + *Based on PureData by Miller Puckette and others. + * + * coded while listening to: Julien Ottavi: Nervure Magnetique + * */ + + +#include "m_pd.h" + +#include "m_simd.h" + + +/* ----------------------------- volctl ----------------------------- */ + +static t_class *volctl_class; + +typedef struct _volctl +{ + t_object x_obj; + float x_f; + + float x_h; //interpolation time + float x_value; //current factor + + int x_ticksleft; //ticks to go + float x_mspersample; //ms per sample + float x_slope; //slope + + int x_line; + +} t_volctl; + +void *volctl_new(t_symbol *s, int argc, t_atom *argv) +{ + if (argc > 2) post("volctl~: extra arguments ignored"); + + t_volctl *x = (t_volctl *)pd_new(volctl_class); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("f1")); + inlet_settip(x->x_obj.ob_inlet,gensym("factor")); + x->x_value = atom_getfloatarg(0, argc, argv); + + t_inlet * time = floatinlet_new(&x->x_obj, &x->x_h); + inlet_settip(time,gensym("interpolation_time")); + x->x_h = atom_getfloatarg(1, argc, argv); + + x->x_mspersample = 1000.f / 44100; // assume default samplerate + + outlet_new(&x->x_obj, &s_signal); + x->x_f = 0; + return (x); +} + +t_int *volctl_perform(t_int *w) +{ + t_volctl * x = (t_volctl *)(w[1]); + t_float *in = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + int n = (int)(w[4]); + + float f = x->x_value; + + if (x->x_ticksleft) + { + float x_slope = x->x_slope; + if (x->x_ticksleft < n) + { + int remain = x->x_ticksleft; + n-=remain; + while (remain--) + { + f+=x_slope; + *out++ = *in++ * f; + } + while (n--) + { + *out++ = *in++ * f; + } + x->x_value = f; + x->x_ticksleft = 0; + } + else + { + x->x_ticksleft -=n; + while (n--) + { + f+=x_slope; + *out++ = *in++ * f; + } + x->x_value = f; + } + } + else + while (n--) *out++ = *in++ * f; + + return (w+5); +} + + +t_int *volctl_perf8(t_int *w) +{ + t_volctl * x = (t_volctl *)(w[1]); + t_float *in = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + int n = (int)(w[4]); + + float f = x->x_value; + + if (x->x_ticksleft) + { + float x_slope = x->x_slope; + if (x->x_ticksleft < n) + { + int remain = x->x_ticksleft; + n-=remain; + while (remain--) + { + *out++ = *in++ * f; + f+=x_slope; + } + while (n--) + { + *out++ = *in++ * f; + } + x->x_value = f; + x->x_ticksleft = 0; + } + else + { + x->x_ticksleft -= n; + while (n--) + { + *out++ = *in++ * f; + f+=x_slope; + } + x->x_value = f; + } + } + else + { + for (; n; n -= 8, in += 8, out += 8) + { + float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + + out[0] = f0 * f; out[1] = f1 * f; out[2] = f2 * f; out[3] = f3 * f; + out[4] = f4 * f; out[5] = f5 * f; out[6] = f6 * f; out[7] = f7 * f; + } + } + return (w+5); +} + +t_int *volctl_perf_simd(t_int *w) +{ + t_volctl * x = (t_volctl *)(w[1]); + t_float *in = (t_float *)(w[2]); + t_float *out = (t_float *)(w[3]); + + if (x->x_ticksleft) + { + int n = (int)(w[4]); + + float f = x->x_value; + + float x_slope = x->x_slope; + if (x->x_ticksleft < n) + { + int remain = x->x_ticksleft; + n-=remain; + while (remain--) + { + *out++ = *in++ * f; + f+=x_slope; + } + while (n--) + { + *out++ = *in++ * f; + } + x->x_value = f; + x->x_ticksleft = 0; + } + else + { + x->x_ticksleft -= n; + while (n--) + { + *out++ = *in++ * f; + f+=x_slope; + } + x->x_value = f; + } + } + else + { + asm( + ".set T_FLOAT,4 \n" + + "movss (%3), %%xmm0 \n" + "shufps $0, %%xmm0, %%xmm0 \n" + "shrl $4, %2 \n" + + "volctl_loop: \n" + "movaps (%0), %%xmm1 \n" + "mulps %%xmm0, %%xmm1 \n" + "movaps %%xmm1, (%1) \n" + "movaps 4*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm0, %%xmm2 \n" + "movaps %%xmm2, 4*T_FLOAT(%1) \n" + "movaps 8*T_FLOAT(%0), %%xmm3 \n" + "mulps %%xmm0, %%xmm3 \n" + "movaps %%xmm3, 8*T_FLOAT(%1) \n" + "movaps 12*T_FLOAT(%0), %%xmm4 \n" + "mulps %%xmm0, %%xmm4 \n" + "movaps %%xmm4, 12*T_FLOAT(%1) \n" + "addl $64, %0 \n" + "addl $64, %1 \n" + "loop volctl_loop \n" + : + : "r"(in), "r"(out), + "a"(w[4]),"r"(&(x->x_value)) + : "%xmm0","%xmm1","%xmm2","%xmm3","%xmm4"); + } + return (w+5); +} + + +void volctl_set(t_volctl *x, t_float f) +{ + x->x_ticksleft = x->x_h / x->x_mspersample; + x->x_slope = (f - x->x_value) / x->x_ticksleft; +} + +void volctl_dsp(t_volctl *x, t_signal **sp) +{ + const int n = sp[0]->s_n; + if (n&7) + dsp_add(volctl_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); + else + { + if(SIMD_CHECK2(n,sp[0]->s_vec,sp[1]->s_vec)) + dsp_add(volctl_perf_simd, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); + else + dsp_add(volctl_perf8, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); + } + x->x_mspersample = 1000.f / sp[0]->s_sr; +} + +void volctl_tilde_setup(void) +{ + volctl_class = class_new(gensym("volctl~"), (t_newmethod)volctl_new, 0, + sizeof(t_volctl), 0, A_GIMME, 0); + CLASS_MAINSIGNALIN(volctl_class, t_volctl, x_f); + class_addmethod(volctl_class, (t_method)volctl_dsp, gensym("dsp"), 0); + class_addmethod(volctl_class, (t_method)volctl_set, gensym("f1"),A_FLOAT,0); + class_settip(volctl_class,gensym("signal")); +} diff --git a/volctl~/volctl~.pd b/volctl~/volctl~.pd new file mode 100644 index 0000000..401b402 --- /dev/null +++ b/volctl~/volctl~.pd @@ -0,0 +1,24 @@ +#N canvas 0 0 450 300 10; +#X obj 54 101 volctl~ 1 10; +#X obj 53 18 osc~ 440; +#X obj 51 141 dac~; +#X floatatom 93 50 5 0 0 0 - - -; +#X obj 93 72 * 0.01; +#X floatatom 160 78 5 0 0 0 - - -; +#X text 131 36 factor; +#X text 185 61 interpolation time; +#X text 189 135 ==; +#X obj 266 197 *~; +#X obj 285 173 line~; +#X obj 285 145 pack 1 10; +#X text 107 241 but faster; +#X connect 0 0 2 0; +#X connect 0 0 2 1; +#X connect 1 0 0 0; +#X connect 3 0 4 0; +#X connect 4 0 0 1; +#X connect 4 0 11 0; +#X connect 5 0 0 2; +#X connect 5 0 11 1; +#X connect 10 0 9 1; +#X connect 11 0 10 0; -- cgit v1.2.1 From 11287cecd754c0e7181ee763aab44cf954526b61 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 5 Sep 2004 21:28:52 +0000 Subject: added crossfade svn path=/trunk/externals/tb/; revision=2005 --- tbext/source/him.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 11 deletions(-) diff --git a/tbext/source/him.cpp b/tbext/source/him.cpp index c6b1593..56872df 100644 --- a/tbext/source/him.cpp +++ b/tbext/source/him.cpp @@ -62,6 +62,7 @@ public: protected: virtual void m_signal (int n, float *const *in, float *const *out); + virtual void m_dsp (int n, float *const *in, float *const *out); void set_mu(t_float); void set_muv(t_float); @@ -78,7 +79,7 @@ private: t_float deriv(t_float x[],int eq); // 4th order Runge Kutta update of the dynamical variables - void runge_kutta_4(t_float dt); + void runge_kutta_4(t_float dt); //these are our data t_float data[4]; //mu, muv, nu, nuv (semi-parabolische koordinaten) @@ -88,6 +89,14 @@ private: t_float dt; bool regtime; //if true "regularisierte zeit" + bool xfade; + t_float newE; + t_float newdt; + bool newsystem; + bool newregtime; + + t_float * m_fader; + //Callbacks FLEXT_CALLBACK_1(set_mu,t_float); FLEXT_CALLBACK_1(set_muv,t_float); @@ -209,13 +218,21 @@ inline void him::runge_kutta_4(t_float dt) /* - the system might become unstable ... in this case, we'll reset the system + the system might become unstable ... in this case, we'll request a new system */ for(int i=0;i<=NUMB_EQ-1;i++) { if(data[i]>2) - reset(); + { + xfade = newsystem = true; + data[i] = 2; + } + if(data[i]<-2) + { + xfade = newsystem = true; + data[i] = -2; + } } } @@ -233,7 +250,7 @@ void him::m_signal(int n, t_float *const *in, t_float *const *out) if (regtime) { - for (int j=0;j!=n;++j) + for (int i=0;i!=n;++i) { runge_kutta_4(dt); (*(out0)++)=data[0]; @@ -246,7 +263,7 @@ void him::m_signal(int n, t_float *const *in, t_float *const *out) } else { - for (int j=0;j!=n;++j) + for (int i=0;i!=n;++i) { runge_kutta_4(dt/(2*sqrt(data[0]*data[0]+data[2]*data[2]))); (*(out0)++)=data[0]; @@ -257,8 +274,97 @@ void him::m_signal(int n, t_float *const *in, t_float *const *out) (*(out5)++)=(data[0]*data[0]-data[2]*data[2])*0.5; } } + + if (xfade) + { + /* fading */ + out0 = out[0]; + out1 = out[1]; + out2 = out[2]; + out3 = out[3]; + out4 = out[4]; + out5 = out[5]; + + t_float * fader = m_fader + n - 1; + for (int i=0;i!=n;++i) + { + (*(out0)++) *= *fader; + (*(out1)++) *= *fader; + (*(out2)++) *= *fader; + (*(out3)++) *= *fader; + (*(out4)++) *= *fader; + (*(out5)++) *= *fader--; + } + + if (newsystem) + { + reset(); + newsystem = false; + } + + E = newE; + dt = newdt; + regtime = newregtime; + + out0 = out[0]; + out1 = out[1]; + out2 = out[2]; + out3 = out[3]; + out4 = out[4]; + out5 = out[5]; + + fader = m_fader; + if (regtime) + { + for (int i=0;i!=n;++i) + { + runge_kutta_4(dt); + (*(out0)++)+= data[0]* *fader; + (*(out1)++)+= data[1]* *fader; + (*(out2)++)+= data[2]* *fader; + (*(out3)++)+= data[3]* *fader; + (*(out4)++)+= data[0]*data[2]* *fader; + (*(out5)++)+= (data[0]*data[0]-data[2]*data[2])*0.5* *fader++; + } + } + else + { + for (int i=0;i!=n;++i) + { + runge_kutta_4(dt/(2*sqrt(data[0]*data[0]+data[2]*data[2]))); + (*(out0)++)+= data[0]* *fader; + (*(out1)++)+= data[1]* *fader; + (*(out2)++)+= data[2]* *fader; + (*(out3)++)+= data[3]* *fader; + (*(out4)++)+= data[0]*data[2]* *fader; + (*(out5)++)+= (data[0]*data[0]-data[2]*data[2])*0.5* *fader++; + } + } + + xfade = false; + } + } +void him::m_dsp(int n, t_float *const *in, t_float *const *out) +{ + m_fader = new t_float[n]; + t_float on = 1.f/(n-1); + + t_float value = 0; + + t_float* localfader = m_fader; + + while (n--) + { + *localfader = value; + value += on; + ++localfader; + } + xfade = false; +} + + void him::set_mu(t_float f) { data[0]=f; @@ -281,23 +387,25 @@ void him::set_nuv(t_float f) { data[3]=f; reset_muv(); - post("resetting muv!!!"); } void him::set_etilde(t_float f) { - E=f; - reset_nuv(); + newE=f; + xfade = true; + //reset_nuv(); } void him::set_dt(t_float f) { - dt=f; + newdt=f; + xfade = true; } void him::set_regtime(bool b) { - regtime=b; + newregtime=b; + xfade = true; } @@ -316,5 +424,4 @@ void him::reset() data[1]=float(rand())/float(RAND_MAX); data[2]=float(rand())/float(RAND_MAX); reset_nuv(); - post("randomizing values"); } -- cgit v1.2.1 From 17bd73bf9c9da670727345b00e639398a8f3d296 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 7 Sep 2004 09:13:52 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=2015 --- tbext/him.pd | 13 +++++++++++-- tbext/source/fftgrrev.cpp | 13 ++++--------- tbext/source/fftgrshuf.cpp | 16 ++++------------ tbext/source/fftgrsort.cpp | 15 ++++++--------- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/tbext/him.pd b/tbext/him.pd index 7e15881..f287cdd 100644 --- a/tbext/him.pd +++ b/tbext/him.pd @@ -4,11 +4,11 @@ #X obj 125 122 tgl 15 1 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1; #X obj 51 15 hsl 128 15 1e-04 1 1 0 empty empty dt -2 -6 0 8 -262144 --1 -1 10400 0; +-1 -1 5100 0; #X msg 48 37 dt \$1; #X msg 80 84 e \$1; #X obj 83 65 hsl 128 15 -1 0 0 0 empty empty etilde -2 -6 0 8 -262144 --1 -1 6000 0; +-1 -1 7800 0; #X floatatom 122 85 5 0 0 0 - - -; #X floatatom 106 40 5 0 0 0 - - -; #X msg 158 177 reset; @@ -31,6 +31,11 @@ models of an atom in a magnetic field...; #X msg 607 252 mu -1.43572 \;; #X obj 608 228 t b b; #X msg 608 318 \; pd dsp 1; +#X obj 14 347 print~; +#X obj 14 292 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 262 236 fiddle~; +#X floatatom 263 273 5 0 0 0 - - -; #X connect 1 0 11 0; #X connect 2 0 1 0; #X connect 3 0 4 0; @@ -42,6 +47,8 @@ models of an atom in a magnetic field...; #X connect 9 0 11 0; #X connect 10 0 11 0; #X connect 11 0 0 0; +#X connect 11 0 24 0; +#X connect 11 0 26 0; #X connect 11 1 0 1; #X connect 11 2 0 0; #X connect 11 3 0 1; @@ -55,3 +62,5 @@ models of an atom in a magnetic field...; #X connect 22 1 21 0; #X connect 22 1 19 0; #X connect 22 1 20 0; +#X connect 25 0 24 0; +#X connect 26 3 27 0; diff --git a/tbext/source/fftgrrev.cpp b/tbext/source/fftgrrev.cpp index e26135c..fd844f0 100644 --- a/tbext/source/fftgrrev.cpp +++ b/tbext/source/fftgrrev.cpp @@ -68,14 +68,11 @@ private: t_int bs; //blocksize t_int bs1; //bs+1 - t_int counter; t_sample * data; //array with data t_sample * d1; //1. element in array with data t_sample * dend; //1 element after the last element - t_sample * ins; - t_sample * outs; bool reverse; @@ -85,7 +82,7 @@ private: FLEXT_LIB_DSP_1("fftgrrev~",fftgrrev,int) fftgrrev::fftgrrev(int arg): - grains(1),offset(0),counter(1) + grains(1),offset(0) { bs=arg/2; grainsize=bs; @@ -106,9 +103,8 @@ fftgrrev::fftgrrev(int arg): void fftgrrev::m_signal(int n, t_float * const *in, t_float *const *out) { - ins = in[0]; - outs = out[0]; - + t_sample * ins = in[0]; + t_sample * outs = out[0]; if (offset>0) { @@ -126,7 +122,7 @@ void fftgrrev::m_signal(int n, t_float * const *in, t_float *const *out) //grains - counter=1; + int counter=1; while (counter!=grains) { @@ -144,7 +140,6 @@ void fftgrrev::set_offset(t_int o) if (o-bs<0 && o+bs>0) { offset=-o; - post("offset %i",o); } else post("Offset out of range!"); diff --git a/tbext/source/fftgrshuf.cpp b/tbext/source/fftgrshuf.cpp index b490dcf..d9ecdfb 100644 --- a/tbext/source/fftgrshuf.cpp +++ b/tbext/source/fftgrshuf.cpp @@ -67,23 +67,17 @@ private: t_int bs; //blocksize t_int bs1; //bs+1 - t_int counter; t_sample * data; //array with data t_sample * d1; //1. element in array with data t_sample * dend; //1 element after the last element - - t_sample * ins; - t_sample * outs; - - }; FLEXT_LIB_DSP_1("fftgrshuf~",fftgrshuf,int) fftgrshuf::fftgrshuf(int arg): - grains(1),offset(0),counter(1) + grains(1),offset(0) { bs=arg/2; grainsize=bs; @@ -104,9 +98,8 @@ fftgrshuf::fftgrshuf(int arg): void fftgrshuf::m_signal(int n, t_float * const *in, t_float *const *out) { - ins = in[0]; - outs = out[0]; - + t_sample * ins = in[0]; + t_sample * outs = out[0]; if (offset>0) { @@ -124,7 +117,7 @@ void fftgrshuf::m_signal(int n, t_float * const *in, t_float *const *out) //grains - counter=1; + int counter=1; while (counter!=grains) { @@ -143,7 +136,6 @@ void fftgrshuf::set_offset(t_int o) if (o-bs<0 && o+bs>0) { offset=o; - post("offset %i",-o); } else post("offset out of range!"); diff --git a/tbext/source/fftgrsort.cpp b/tbext/source/fftgrsort.cpp index f24ed0f..1764c02 100644 --- a/tbext/source/fftgrsort.cpp +++ b/tbext/source/fftgrsort.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 Tim Blechmann. */ +/* Copyright (c) 2003-2004 Tim Blechmann. */ /* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ /* WARRANTIES, see the file, "COPYING" in this distribution. */ /* */ @@ -70,14 +70,11 @@ private: t_int bs; //blocksize t_int bs1; //bs+1 - t_int counter; t_sample * data; //array with data t_sample * d1; //1. element in array with data t_sample * dend; //1 element after the last element - t_sample * ins; - t_sample * outs; bool reverse; @@ -87,7 +84,7 @@ private: FLEXT_LIB_DSP_1("fftgrsort~",fftgrsort,int) fftgrsort::fftgrsort(int arg): - grains(1),offset(0),counter(1),reverse(0) + grains(1),offset(0),reverse(0) { bs=arg/2; grainsize=bs; @@ -109,8 +106,8 @@ fftgrsort::fftgrsort(int arg): void fftgrsort::m_signal(int n, t_float * const *in, t_float *const *out) { - ins = in[0]; - outs = out[0]; + t_sample * ins = in[0]; + t_sample * outs = out[0]; if (offset>0) @@ -129,7 +126,7 @@ void fftgrsort::m_signal(int n, t_float * const *in, t_float *const *out) //grains - counter=1; + int counter=1; while (counter!=grains) { @@ -152,7 +149,7 @@ void fftgrsort::set_offset(t_int o) if (o-bs<0 && o+bs>0) { offset=-o; - post("offset %i",o); + // post("offset %i",o); } else post("offset out of range!"); -- cgit v1.2.1 From 1a1d31d95b241dff59a11311b70be603742eeb32 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 7 Sep 2004 09:32:44 +0000 Subject: *** empty log message *** svn path=/trunk/externals/tb/; revision=2016 --- tbext/source/main.cpp | 3 +- tbext/source/sym2num.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tbext/source/sym2num.cpp diff --git a/tbext/source/main.cpp b/tbext/source/main.cpp index 39ac8b2..0c9285d 100644 --- a/tbext/source/main.cpp +++ b/tbext/source/main.cpp @@ -52,7 +52,7 @@ void ttbext_setup() post("version "TBEXT_VERSION); post("compiled on "__DATE__); post("contains: tbroute(~), tbfft1~, tbfft2~, bufline~, fftgrrev~"); - post(" fftgrsort~, fftgrshuf~, him~\n"); + post(" fftgrsort~, fftgrshuf~, him~, sym2num\n"); FLEXT_SETUP(tbroute); FLEXT_DSP_SETUP(tbsroute); @@ -65,6 +65,7 @@ void ttbext_setup() FLEXT_DSP_SETUP(fftgrshuf); FLEXT_DSP_SETUP(fftgrrev); FLEXT_DSP_SETUP(him); + FLEXT_SETUP(sym2num); diff --git a/tbext/source/sym2num.cpp b/tbext/source/sym2num.cpp new file mode 100644 index 0000000..8f7bece --- /dev/null +++ b/tbext/source/sym2num.cpp @@ -0,0 +1,90 @@ +/* Copyright (c) 2004 Tim Blechmann. */ +/* For information on usage and redistribution, and for a DISCLAIMER OF ALL */ +/* WARRANTIES, see the file, "COPYING" in this distribution. */ +/* */ +/* sym2num interpretes a symbol as decimal number that is related to the ascii */ +/* representation. */ +/* */ +/* */ +/* sym2num uses the flext C++ layer for Max/MSP and PD externals. */ +/* get it at http://www.parasitaere-kapazitaeten.de/PD/ext */ +/* thanks to Thomas Grill */ +/* */ +/* */ +/* */ +/* This program is free software; you can redistribute it and/or */ +/* modify it under the terms of the GNU General Public License */ +/* as published by the Free Software Foundation; either version 2 */ +/* of the License, or (at your option) any later version. */ +/* */ +/* See file LICENSE for further informations on licensing terms. */ +/* */ +/* This program is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* */ +/* Based on PureData by Miller Puckette and others. */ +/* */ +/* */ +/* */ +/* coded while listening to: Phil Minton & Veryan Weston: Ways */ +/* */ +/* */ +/* */ + + + +#include + +#include +#include + + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 400) +#error upgrade your flext version!!!!!! +#endif + +class sym2num: public flext_base +{ + FLEXT_HEADER(sym2num,flext_base); + +public: + sym2num(); + +protected: + void m_symbol(t_symbol *s); + +private: + + FLEXT_CALLBACK_S(m_symbol); +}; + +FLEXT_LIB("sym2num",sym2num); + +sym2num::sym2num() +{ + AddInSymbol(); + + FLEXT_ADDMETHOD(0,m_symbol); + + AddOutFloat(); +} + +void sym2num::m_symbol(t_symbol * s) +{ + const char* str = GetString(s); + + int length = strlen(str); + + int ret(0); + while (length--) + { + ret+=str[length]*pow(2,length); + } + ToOutFloat(0,ret); +} -- cgit v1.2.1 From 8e34dec617b67c4b8d8928188d175f850d6a69c4 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 9 Sep 2004 08:45:18 +0000 Subject: lfdnoises and interpolating vector/scalar operations svn path=/trunk/externals/tb/; revision=2021 --- sc4pd/config-pd-linux.txt | 5 +- sc4pd/make-files.txt | 3 +- sc4pd/pd/lfdnoise0.pd | 5 ++ sc4pd/source/LFDNoise0.cpp | 166 +++++++++++++++++++++++++++++++++++++++ sc4pd/source/LFDNoise1.cpp | 172 +++++++++++++++++++++++++++++++++++++++++ sc4pd/source/LFDNoise2.cpp | 188 +++++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/main.cpp | 19 ++++- sc4pd/source/sc*.cpp | 113 +++++++++++++++++++++++++++ sc4pd/source/sc+.cpp | 113 +++++++++++++++++++++++++++ sc4pd/source/sc-.cpp | 142 ++++++++++++++++++++++++++++++++++ sc4pd/source/sc4pd.hpp | 2 +- sc4pd/source/scdiv.cpp | 142 ++++++++++++++++++++++++++++++++++ sc4pd/source/support.cpp | 24 +++--- sc4pd/source/support.hpp | 26 ++----- 14 files changed, 1082 insertions(+), 38 deletions(-) create mode 100644 sc4pd/pd/lfdnoise0.pd create mode 100644 sc4pd/source/LFDNoise0.cpp create mode 100644 sc4pd/source/LFDNoise1.cpp create mode 100644 sc4pd/source/LFDNoise2.cpp create mode 100644 sc4pd/source/sc*.cpp create mode 100644 sc4pd/source/sc+.cpp create mode 100644 sc4pd/source/sc-.cpp create mode 100644 sc4pd/source/scdiv.cpp diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt index 1e95392..3d67664 100755 --- a/sc4pd/config-pd-linux.txt +++ b/sc4pd/config-pd-linux.txt @@ -1,7 +1,7 @@ # config file for sc4pd, adapted from Thomas Grill's xsample makefile # your c++ compiler (if not g++) - CXX=icc +# CXX=icc # where does the PD installation reside? @@ -29,8 +29,7 @@ HELPDIR=${PD}/doc/5.reference # additional compiler flags # (check whether they fit to your system!) #UFLAGS=-xN -tpp7 -ip -ipo_obj # icc -UFLAGS=-g -mcpu=pentium4 -mmmx -msse2 -msse -mfpmath=sse # gcc 3.2 - +UFLAGS=-march=pentium4 -mmmx -msse2 -msse -mfpmath=sse -g # gcc 3.2 # define to link against shared flext library (flext version >= 0.5.0) FLEXT_SHARED=1 diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index 69162da..ea7e551 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -15,4 +15,5 @@ SRCS= \ AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp RLPF.cpp RHPF.cpp LPF.cpp \ HPF.cpp BPF.cpp BRF.cpp LPZ1.cpp HPZ1.cpp LPZ2.cpp HPZ2.cpp \ - BPZ2.cpp BRZ2.cpp + BPZ2.cpp BRZ2.cpp LFDNoise0.cpp LFDNoise1.cpp LFDNoise2.cpp \ + sc+.cpp sc-.cpp diff --git a/sc4pd/pd/lfdnoise0.pd b/sc4pd/pd/lfdnoise0.pd new file mode 100644 index 0000000..138cd66 --- /dev/null +++ b/sc4pd/pd/lfdnoise0.pd @@ -0,0 +1,5 @@ +#N canvas 0 0 450 300 10; +#X obj 133 22 LFDNoise0~ 100; +#X obj 131 56 dac~; +#X connect 0 0 1 0; +#X connect 0 0 1 1; diff --git a/sc4pd/source/LFDNoise0.cpp b/sc4pd/source/LFDNoise0.cpp new file mode 100644 index 0000000..316b5a4 --- /dev/null +++ b/sc4pd/source/LFDNoise0.cpp @@ -0,0 +1,166 @@ +/* sc4pd + LFDNoise0~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + * + * DynNoiseUGens.cpp + * xSC3plugins + * + * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004. + * Copyright (c) 2004 HfbK. All rights reserved. + * + * + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways Past + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ LFDNoise0~ -------------------------------*/ + +class LFDNoise0_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(LFDNoise0_ar,sc4pd_dsp); + +public: + LFDNoise0_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_level; + float m_phase; + float m_smpdur; + + bool m_ar; + + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFDNoise0~",LFDNoise0_ar); + +LFDNoise0_ar::LFDNoise0_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + m_phase=0.f; + m_level=0.f; + + rgen.init(timeseed()); + + m_ar = sc_ar(Args); + + if (m_ar) + AddInSignal("freqency"); + else + AddInSignal("\"set\" frequency"); + AddOutSignal(); +} + +void LFDNoise0_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_smpdur = sc_sampledur(); +} + + +void LFDNoise0_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float level = m_level; + float phase = m_phase; + + RGET; + + if (m_ar) + { + t_sample *nin = *in; + float smpdur = m_smpdur; + for (int i = 0; i!= n; ++i) + { + phase -= ZXP(nin) * smpdur; + if (phase <= 0) + { + phase = sc_wrap(phase, 0.f, 1.f); + level = frand2(s1,s2,s3); + } + ZXP(nout) = level; + } + } + else + { + float dphase = m_smpdur * m_freq; + for (int i = 0; i!= n; ++i) + { + phase -= dphase; + if (phase <= 0) + { + phase = sc_wrap(phase, 0.f, 1.f); + level = frand2(s1,s2,s3); + } + ZXP(nout) = level; + } + } + + + m_level = level; + m_phase = phase; + + RPUT; +} + + diff --git a/sc4pd/source/LFDNoise1.cpp b/sc4pd/source/LFDNoise1.cpp new file mode 100644 index 0000000..8336b80 --- /dev/null +++ b/sc4pd/source/LFDNoise1.cpp @@ -0,0 +1,172 @@ +/* sc4pd + LFDNoise1~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + * + * DynNoiseUGens.cpp + * xSC3plugins + * + * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004. + * Copyright (c) 2004 HfbK. All rights reserved. + * + * + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways Past + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ LFDNoise1~ -------------------------------*/ + +class LFDNoise1_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(LFDNoise1_ar,sc4pd_dsp); + +public: + LFDNoise1_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_prevlevel; + float m_nextlevel; + float m_phase; + float m_smpdur; + + bool m_ar; + + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFDNoise1~",LFDNoise1_ar); + +LFDNoise1_ar::LFDNoise1_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + rgen.init(timeseed()); + + m_phase=0.f; + m_prevlevel=0.f; + m_nextlevel = rgen.frand2(); + + + m_ar = sc_ar(Args); + + if (m_ar) + AddInSignal("freqency"); + else + AddInSignal("\"set\" frequency"); + AddOutSignal(); +} + +void LFDNoise1_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_smpdur = sc_sampledur(); +} + + +void LFDNoise1_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float prevLevel = m_prevlevel; + float nextLevel = m_nextlevel; + float phase = m_phase; + + RGET; + + if (m_ar) + { + t_sample *nin = *in; + float smpdur = m_smpdur; + for (int i = 0; i!= n; ++i) + { + phase -= ZXP(nin) * smpdur; + if (phase <= 0) + { + phase = sc_wrap(phase, 0.f, 1.f); + prevLevel = nextLevel; + nextLevel = frand2(s1,s2,s3); + } + ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) ); + } + } + else + { + float dphase = m_smpdur * m_freq; + for (int i = 0; i!= n; ++i) + { + phase -= dphase; + if (phase <= 0) + { + phase = sc_wrap(phase, 0.f, 1.f); + prevLevel = nextLevel; + nextLevel = frand2(s1,s2,s3); + } + ZXP(nout) = nextLevel + ( phase * (prevLevel - nextLevel) ); + } + } + + m_prevlevel = prevLevel; + m_nextlevel = nextLevel; + m_phase = phase; + + RPUT; +} + + diff --git a/sc4pd/source/LFDNoise2.cpp b/sc4pd/source/LFDNoise2.cpp new file mode 100644 index 0000000..136b1c9 --- /dev/null +++ b/sc4pd/source/LFDNoise2.cpp @@ -0,0 +1,188 @@ +/* sc4pd + LFDNoise2~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + * + * DynNoiseUGens.cpp + * xSC3plugins + * + * Created by Alberto de Campo, Sekhar Ramacrishnan, Julian Rohrhuber on Sun May 30 2004. + * Copyright (c) 2004 HfbK. All rights reserved. + * + * + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways Past + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ LFDNoise2~ -------------------------------*/ + +class LFDNoise2_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(LFDNoise2_ar,sc4pd_dsp); + +public: + LFDNoise2_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + + void m_seed(int i) + { + rgen.init(i); + } + + void m_set(float f) + { + m_freq = f; + } + +private: + RGen rgen; + float m_freq; + float m_levela, m_levelb, m_levelc, m_leveld; + float m_phase; + float m_smpdur; + + bool m_ar; + + FLEXT_CALLBACK_I(m_seed); + FLEXT_CALLBACK_F(m_set); +}; + +FLEXT_LIB_DSP_V("LFDNoise2~",LFDNoise2_ar); + +LFDNoise2_ar::LFDNoise2_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD_(0,"seed",m_seed); + FLEXT_ADDMETHOD_(0,"set",m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_freq = sc_getfloatarg(Args,0); + + rgen.init(timeseed()); + + RGET; + + m_phase=0.f; + m_levela = frand2(s1, s2, s3) * 0.8f;// limits max interpol. overshoot to 1. + m_levelb = frand2(s1, s2, s3) * 0.8f; + m_levelc = frand2(s1, s2, s3) * 0.8f; + m_leveld = frand2(s1, s2, s3) * 0.8f; + + RPUT; + + m_ar = sc_ar(Args); + + if (m_ar) + AddInSignal("freqency"); + else + AddInSignal("\"set\" frequency"); + AddOutSignal(); +} + +void LFDNoise2_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + m_smpdur = sc_sampledur(); +} + + +void LFDNoise2_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nout = *out; + + float a = m_levela; + float b = m_levelb; + float c = m_levelc; + float d = m_leveld; + + float phase = m_phase; + + RGET; + + if (m_ar) + { + t_sample *nin = *in; + float smpdur = m_smpdur; + for (int i = 0; i!= n; ++i) + { + phase -= ZXP(nin) * smpdur; + if (phase <= 0) + { + phase = sc_wrap(phase, 0.f, 1.f); + a = b; + b = c; + c = d; + d = frand2(s1,s2,s3) * 0.8f; // limits max interpol. overshoot to 1. + + } + ZXP(nout) = cubicinterp(1.f - phase, a, b, c, d); + } + } + else + { + float dphase = m_smpdur * m_freq; + for (int i = 0; i!= n; ++i) + { + phase -= dphase; + if (phase <= 0) + { + phase = sc_wrap(phase, 0.f, 1.f); + a = b; + b = c; + c = d; + d = frand2(s1,s2,s3) * 0.8f; // limits max interpol. overshoot to 1. + } + ZXP(nout) = cubicinterp(1.f - phase, a, b, c, d); + } + } + + + m_phase = phase; + + m_levela = a; + m_levelb = b; + m_levelc = c; + m_leveld = d; + + RPUT; +} + + diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 8216421..13fbc90 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -66,8 +66,9 @@ void sc4pd_library_setup() "TwoPole~, \n" " TwoZero~, FOS(~), SOS~, RLPF~, RHPF~, LPF~, HPF~, BPF~, " "BRF~,\n" - " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~)" - "\n" + " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~), " + "LFDNoise0~,\n" + " LFDNoise1~, LFDNoise2~, sc+~, sc-~, sc*~, sc/~\n" ); //initialize objects @@ -281,6 +282,20 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(BPZ2_ar); FLEXT_SETUP(BPZ2_kr); + + FLEXT_DSP_SETUP(LFDNoise0_ar); + + FLEXT_DSP_SETUP(LFDNoise1_ar); + + FLEXT_DSP_SETUP(LFDNoise2_ar); + + FLEXT_DSP_SETUP(scadd_ar); + + FLEXT_DSP_SETUP(scsub_ar); + + FLEXT_DSP_SETUP(scmul_ar); + + FLEXT_DSP_SETUP(scdiv_ar); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/sc*.cpp b/sc4pd/source/sc*.cpp new file mode 100644 index 0000000..55ac074 --- /dev/null +++ b/sc4pd/source/sc*.cpp @@ -0,0 +1,113 @@ +/* sc4pd + sc*~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ sc*~ -------------------------------*/ + +class scmul_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(scmul_ar,sc4pd_dsp); + +public: + scmul_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_nextfactor = f; + changed = true; + } + + float m_nextfactor, m_factor; + bool changed; + +private: + FLEXT_CALLBACK_1(m_set,float); +}; + +FLEXT_LIB_DSP_V("sc*~",scmul_ar); + +scmul_ar::scmul_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(1,m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_factor = sc_getfloatarg(Args,0); + + AddInSignal("signal"); + AddInFloat("scalar"); + AddOutSignal(); + + changed = false; +} + +void scmul_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + if (changed) + { + float xb = m_nextfactor; + float slope = CALCSLOPE(xb, m_factor); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) * xb; + xb += slope; + } + m_factor = xb; + changed = false; + } + else + { + float xb = m_factor; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) * xb; + } + } +} + + diff --git a/sc4pd/source/sc+.cpp b/sc4pd/source/sc+.cpp new file mode 100644 index 0000000..e1a7e26 --- /dev/null +++ b/sc4pd/source/sc+.cpp @@ -0,0 +1,113 @@ +/* sc4pd + sc+~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways Past + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ sc+~ -------------------------------*/ + +class scadd_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(scadd_ar,sc4pd_dsp); + +public: + scadd_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_nextsummand = f; + changed = true; + } + + float m_nextsummand, m_summand; + bool changed; + +private: + FLEXT_CALLBACK_1(m_set,float); +}; + +FLEXT_LIB_DSP_V("sc+~",scadd_ar); + +scadd_ar::scadd_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(1,m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_summand = sc_getfloatarg(Args,0); + + AddInSignal("signal"); + AddInFloat("scalar"); + AddOutSignal(); + + changed = false; +} + +void scadd_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + if (changed) + { + float xb = m_nextsummand; + float slope = CALCSLOPE(xb, m_summand); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) + xb; + xb += slope; + } + m_summand = xb; + changed = false; + } + else + { + float xb = m_summand; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) + xb; + } + } +} + + diff --git a/sc4pd/source/sc-.cpp b/sc4pd/source/sc-.cpp new file mode 100644 index 0000000..0dfd2ce --- /dev/null +++ b/sc4pd/source/sc-.cpp @@ -0,0 +1,142 @@ +/* sc4pd + sc-~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ sc-~ -------------------------------*/ + +class scsub_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(scsub_ar,sc4pd_dsp); + +public: + scsub_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_nextsubtrahend = f; + changed = true; + } + + float m_nextsubtrahend, m_subtrahend; + bool changed; + bool invert; + +private: + FLEXT_CALLBACK_1(m_set,float); +}; + +FLEXT_LIB_DSP_V("sc-~",scsub_ar); + +scsub_ar::scsub_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(1,m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_subtrahend = sc_getfloatarg(Args,0); + + invert = sc_inv(Args); + + AddInSignal("signal"); + AddInFloat("scalar"); + AddOutSignal(); + + changed = false; +} + +void scsub_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + if (invert) + { + if (changed) + { + float xb = m_nextsubtrahend; + float slope = CALCSLOPE(xb, m_subtrahend); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = xb - ZXP(nin); + xb += slope; + } + m_subtrahend = xb; + changed = false; + } + else + { + float xb = m_subtrahend; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = xb - ZXP(nin); + } + } + } + else + { + if (changed) + { + float xb = m_nextsubtrahend; + float slope = CALCSLOPE(xb, m_subtrahend); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) - xb; + xb += slope; + } + m_subtrahend = xb; + changed = false; + } + else + { + float xb = m_subtrahend; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) - xb; + } + } + } +} + diff --git a/sc4pd/source/sc4pd.hpp b/sc4pd/source/sc4pd.hpp index f80b177..13d82c0 100644 --- a/sc4pd/source/sc4pd.hpp +++ b/sc4pd/source/sc4pd.hpp @@ -124,5 +124,5 @@ class sc4pd_dsp }; -#define _SC$PD_HPP +#define _SC4PD_HPP #endif diff --git a/sc4pd/source/scdiv.cpp b/sc4pd/source/scdiv.cpp new file mode 100644 index 0000000..045d1b4 --- /dev/null +++ b/sc4pd/source/scdiv.cpp @@ -0,0 +1,142 @@ +/* sc4pd + sc/~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ sc/~ -------------------------------*/ + +class scdiv_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(scdiv_ar,sc4pd_dsp); + +public: + scdiv_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_nextdivisor = f; + changed = true; + } + + float m_nextdivisor, m_divisor; + bool changed; + bool invert; + +private: + FLEXT_CALLBACK_1(m_set,float); +}; + +FLEXT_LIB_DSP_V("sc/~",scdiv_ar); + +scdiv_ar::scdiv_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(1,m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_divisor = sc_getfloatarg(Args,0); + + invert = sc_inv(Args); + + AddInSignal("signal"); + AddInFloat("scalar"); + AddOutSignal(); + + changed = false; +} + +void scdiv_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + if (invert) + { + if (changed) + { + float xb = m_nextdivisor; + float slope = CALCSLOPE(xb, m_divisor); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = xb / ZXP(nin); + xb += slope; + } + m_divisor = xb; + changed = false; + } + else + { + float xb = m_divisor; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = xb / ZXP(nin); + } + } + } + else + { + if (changed) + { + float xb = m_nextdivisor; + float slope = CALCSLOPE(xb, m_divisor); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) / xb; + xb += slope; + } + m_divisor = xb; + changed = false; + } + else + { + float xb = m_divisor; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) / xb; + } + } + } +} + diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp index fd87c86..077ea45 100644 --- a/sc4pd/source/support.cpp +++ b/sc4pd/source/support.cpp @@ -77,16 +77,20 @@ bool sc_ar(flext::AtomList a) return false; } -// macros to put rgen state in registers -#define RGET \ - uint32 s1 = rgen.s1; \ - uint32 s2 = rgen.s2; \ - uint32 s3 = rgen.s3; - -#define RPUT \ - rgen.s1 = s1; \ - rgen.s2 = s2; \ - rgen.s3 = s3; +bool sc_inv(flext::AtomList a) +{ + for (int i = 0; i!=a.Count();++i) + { + if ( flext::IsSymbol(a[i]) ) + { + const char * teststring; + teststring = flext::GetString(a[i]); + if((strcmp(teststring,"inv"))==0) + return true; + } + } + return false; +} int32 timeseed() { diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index 3972c83..a9258e8 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -50,6 +50,7 @@ bool sc_add (flext::AtomList a); float sc_getfloatarg (flext::AtomList a,int i); bool sc_ar(flext::AtomList a); +bool sc_inv(flext::AtomList a); /* for rngs */ @@ -94,7 +95,7 @@ inline float CalcFeedback(float delaytime, float decaytime) } -/* this is copied from thomas grill's xsample: +/* this is adapted from thomas grill's xsample: xsample - extended sample objects for Max/MSP and pd (pure data) Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net) @@ -102,34 +103,17 @@ For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "license.txt," in this distribution. */ -#define F float -#define D double -#define I int -#define L long -#define C char -#define V void -#define BL bool -#define S t_sample - #define SETSIGFUN(VAR,FUN) v_##VAR = FUN -#define DEFSIGFUN(NAME) V NAME(I n,S *const *in,S *const *out) +#define DEFSIGFUN(NAME) void NAME(int n,t_sample *const *in,t_sample *const *out) #define DEFSIGCALL(NAME) \ - inline V NAME(I n,S *const *in,S *const *out) \ + inline void NAME(int n,t_sample *const *in,t_sample *const *out) \ { (this->*v_##NAME)(n,in,out); } \ - V (thisType::*v_##NAME)(I n,S *const *invecs,S *const *outvecs) + void (thisType::*v_##NAME)(int n,t_sample *const *invecs,t_sample *const *outvecs) #define SIGFUN(FUN) &thisType::FUN -#undef F -#undef D -#undef I -#undef L -#undef C -#undef V -#undef BL -#undef S #endif -- cgit v1.2.1 From ba1866d2b465633b6d4b3ebbba2c6dc6c0e25d6b Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 11 Sep 2004 08:10:45 +0000 Subject: ... svn path=/trunk/externals/tb/; revision=2024 --- sc4pd/make-files.txt | 2 +- sc4pd/source/Convolution.cpp | 222 +++ sc4pd/source/fftlib.c | 3306 ++++++++++++++++++++++++++++++++++++++++++ sc4pd/source/fftlib.h | 62 + sc4pd/source/main.cpp | 9 +- sc4pd/source/sc*.cpp | 113 -- sc4pd/source/scmul.cpp | 113 ++ sc4pd/source/support.cpp | 74 + sc4pd/source/support.hpp | 5 + 9 files changed, 3791 insertions(+), 115 deletions(-) create mode 100644 sc4pd/source/Convolution.cpp create mode 100644 sc4pd/source/fftlib.c create mode 100644 sc4pd/source/fftlib.h delete mode 100644 sc4pd/source/sc*.cpp create mode 100644 sc4pd/source/scmul.cpp diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt index ea7e551..486674f 100755 --- a/sc4pd/make-files.txt +++ b/sc4pd/make-files.txt @@ -16,4 +16,4 @@ SRCS= \ TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp RLPF.cpp RHPF.cpp LPF.cpp \ HPF.cpp BPF.cpp BRF.cpp LPZ1.cpp HPZ1.cpp LPZ2.cpp HPZ2.cpp \ BPZ2.cpp BRZ2.cpp LFDNoise0.cpp LFDNoise1.cpp LFDNoise2.cpp \ - sc+.cpp sc-.cpp + sc+.cpp sc-.cpp scmul.cpp scdiv.cpp Convolution.cpp diff --git a/sc4pd/source/Convolution.cpp b/sc4pd/source/Convolution.cpp new file mode 100644 index 0000000..0026b01 --- /dev/null +++ b/sc4pd/source/Convolution.cpp @@ -0,0 +1,222 @@ +/* sc4pd + Convolution~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Ambarchi/Muller/Voice Crack: Oystered + +*/ + +#include "sc4pd.hpp" +#include "fftlib.h" + +/* ------------------------ Convolution~ -------------------------------*/ + +class Convolution_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(Convolution_ar,sc4pd_dsp); + +public: + Convolution_ar(int argc, t_atom *argv); + ~Convolution_ar(); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + virtual void m_dsp(int n, t_sample *const *in, t_sample *const *out); + +private: + int m_pos, m_insize, m_fftsize,m_mask; + int m_log2n; + + float *m_inbuf1,*m_inbuf2, *m_fftbuf1, *m_fftbuf2, *m_outbuf,*m_overlapbuf; + +}; + +FLEXT_LIB_DSP_V("Convolution~",Convolution_ar); + +Convolution_ar::Convolution_ar(int argc, t_atom *argv) +{ + + //parse arguments + AtomList Args(argc,argv); + + m_insize = sc_getfloatarg(Args,0); + + AddInSignal("signal"); + AddInSignal("kernel"); + AddOutSignal(); + + + //require size N+M-1 to be a power of two + + m_fftsize=2*(m_insize); + + //just use memory for the input buffers and fft buffers + int insize = m_insize * sizeof(float); + int fftsize = m_fftsize * sizeof(float); + + m_inbuf1 = new float[m_insize]; + m_inbuf2 = new float[m_insize]; + + m_fftbuf1 = new float[m_fftsize]; + m_fftbuf2 = new float[m_fftsize]; + + m_outbuf = new float[m_fftsize]; + m_overlapbuf = new float[m_insize]; + + memset(m_outbuf, 0, fftsize); + memset(m_overlapbuf, 0, insize); + + m_log2n = LOG2CEIL(m_fftsize); + + //test for full input buffer + m_mask = m_insize; + m_pos = 0; +} + +Convolution_ar::~Convolution_ar() +{ + delete m_inbuf1; + delete m_inbuf2; + + delete m_fftbuf1; + delete m_fftbuf2; + + delete m_outbuf; + delete m_overlapbuf; +} + +void Convolution_ar::m_dsp(int n, t_sample *const *in, + t_sample *const *out) +{ + +} + +extern float* cosTable[32]; + +void Convolution_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + float *in1 = in[0]; + float *in2 = in[1]; + + float *out1 = m_inbuf1 + m_pos; + float *out2 = m_inbuf2 + m_pos; + + int numSamples = 2*n; //??? mWorld->mFullRate.mBufLength; + + // copy input + CopySamples(out1, in1, numSamples); + CopySamples(out2, in2, numSamples); + + m_pos += numSamples; + + if (m_pos & m_insize) + { + + //have collected enough samples to transform next frame + m_pos = 0; //reset collection counter + + // copy to fftbuf + + uint32 insize=m_insize * sizeof(float); + memcpy(m_fftbuf1, m_inbuf1, insize); + memcpy(m_fftbuf2, m_inbuf2, insize); + + //zero pad second part of buffer to allow for convolution + memset(m_fftbuf1+m_insize, 0, insize); + memset(m_fftbuf2+m_insize, 0, insize); + + int log2n = m_log2n; + + + // do windowing + DoWindowing(log2n, m_fftbuf1, m_fftsize); + DoWindowing(log2n, m_fftbuf2, m_fftsize); + + // do fft +/* #if __VEC__ + ctoz(m_fftbuf1, 2, outbuf1, 1, 1L<> 1; //m_fftsize - 2 >> 1; + + float * p1= m_fftbuf1; + float * p2= m_fftbuf2; + + p1[0] *= p2[0]; + p1[1] *= p2[1]; + + //complex multiply + for (int i=1; ibin[i]; + p1[imagind]= imag; + } + + //copy second part from before to overlap + memcpy(m_overlapbuf, m_outbuf+m_insize, m_insize * sizeof(float)); + + //inverse fft into outbuf + memcpy(m_outbuf, m_fftbuf1, m_fftsize * sizeof(float)); + + //in place + riffts(m_outbuf, log2n, 1, cosTable[log2n]); + + DoWindowing(log2n, m_outbuf, m_fftsize); + } + + //write out samples copied from outbuf, with overlap added in + + float *output = out[0]; + float *nout= m_outbuf+m_pos; + float *overlap= m_overlapbuf+m_pos; + + for (int i=0; i +#include "fftlib.h" + +#define MAXMROOT 9 /* 2^(MAXMROOT-1) = # of elements in BRcnt */ + +/* Bit reversed counter */ +static const unsigned char BRcnt[256] = { + 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, + 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, + 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, + 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, + 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, + 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, + 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202, + 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, + 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, + 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, + 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, + 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, + 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, + 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, + 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, + 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, + 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, + 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, + 27, 155, 91, 219, 59, 187, 123, 251, 7, 135, 71, 199, + 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, + 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, + 63, 191, 127, 255 }; + +/* Table of powers of 2 */ +static const long Ntbl[21] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, + 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576}; + +long FFTInit(long *fftMptr, long fftN, float *Utbl){ +/* Compute cosine table and check size for complex ffts */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ +long i1, ErrVal; +ErrVal = 0; +*fftMptr = (long)(log(fftN)/log(2.0) + 0.5); +if ((*fftMptr >= 3) & (*fftMptr <= 19) & (int)(pow(2,*fftMptr)+.5) == fftN) + for (i1 = 0; i1 <= fftN/4; i1++) + Utbl[i1] = cos( ( 3.1415926535897932384626433832795 * 2.0 * i1 ) / fftN ); +else + ErrVal = 1; +return ErrVal; +} + +long rFFTInit(long *fftMptr, long fftN, float *Utbl){ +/* Compute cosine table and check size for a real input fft */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ +long i1, ErrVal; +ErrVal = 0; +*fftMptr = (long)(log(fftN)/log(2.0) + 0.5); +if ((*fftMptr >= 4) & (*fftMptr <= 20) & (int)(pow(2,*fftMptr)+.5) == fftN) + + for (i1 = 0; i1 <= fftN/4; i1++) + Utbl[i1] = cos( ( 3.1415926535897932384626433832795 * 2.0 * i1 ) / fftN ); +else + ErrVal = 1; +return ErrVal; +} + +void ffts(float *ioptr, long M, long Rows, float *Utbl){ +/* Compute in-place complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +long Flyinc; +long FlyOffsetA; +long FlyOffsetAIm; +long FlyOffsetB; +long FlyOffsetBIm; +long NsameU1; +long NsameU2; +long NsameU4; +long diffUcnt; +long LoopCnt; + +float scale; +float fly0r; +float fly0i; +float fly1r; +float fly1i; +float fly2r; +float fly2i; +float fly3r; +float fly3i; +float fly4r; +float fly4i; +float fly5r; +float fly5i; +float fly6r; +float fly6i; +float fly7r; +float fly7i; +float U0r; +float U0i; +float U1r; +float U1i; +float U2r; +float U2i; +float U3r; +float U3i; +float t0r; +float t0i; +float t1r; +float t1i; + +float *fly0P; +float *fly1P; +float *fly2P; +float *fly3P; + +float *U0rP; +float *U0iP; +float *U1rP; +float *U1iP; +float *U2rP; +float *U2iP; +float *IOP; +long U3offset; + +long stage; +long NdiffU; +long LoopN; + +const long BRshift = MAXMROOT - (M>>1); +const long Nrems2 = Ntbl[M-(M>>1)+1]; +const long Nroot_1_ColInc = (Ntbl[M-1]-Ntbl[M-(M>>1)])*2; + +scale = 2.0; +for (;Rows>0;Rows--){ + +FlyOffsetA = Ntbl[M] * (2/2); +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetB = FlyOffsetA + 2; +FlyOffsetBIm = FlyOffsetB + 1; + +/* BitrevR2 ** bit reverse and first radix 2 stage ******/ + +for (stage = 0; stage < Ntbl[M-(M>>1)]*2; stage += Ntbl[M>>1]*2){ + for (LoopN = (Ntbl[(M>>1)-1]-1); LoopN >= 0; LoopN--){ + LoopCnt = (Ntbl[(M>>1)-1]-1); + fly0P = ioptr+ Nroot_1_ColInc + ((int)BRcnt[LoopN] >> BRshift)*(2*2) + stage; + IOP = ioptr + (LoopN<<(M+1)/2) * 2 + stage; + fly1P = IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2); + fly0r = *(fly0P); + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + for (; LoopCnt > LoopN;){ + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + fly4r = *(fly1P); + fly4i = *(fly1P+1); + fly5r = *(fly1P+FlyOffsetA); + fly5i = *(fly1P+FlyOffsetAIm); + fly6r = *(fly1P+2); + fly6i = *(fly1P+(2+1)); + fly7r = *(fly1P+FlyOffsetB); + fly7i = *(fly1P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + fly0r = fly4r + fly5r; + fly0i = fly4i + fly5i; + fly5r = fly4r - fly5r; + fly5i = fly4i - fly5i; + fly2r = fly6r + fly7r; + fly2i = fly6i + fly7i; + fly7r = fly6r - fly7r; + fly7i = fly6i - fly7i; + + *(fly1P) = t0r; + *(fly1P+1) = t0i; + *(fly1P+2) = fly1r; + *(fly1P+(2+1)) = fly1i; + *(fly1P+FlyOffsetA) = t1r; + *(fly1P+FlyOffsetAIm) = t1i; + *(fly1P+FlyOffsetB) = fly3r; + *(fly1P+FlyOffsetBIm) = fly3i; + *(fly0P) = fly0r; + *(fly0P+1) = fly0i; + *(fly0P+2) = fly5r; + *(fly0P+(2+1)) = fly5i; + *(fly0P+FlyOffsetA) = fly2r; + *(fly0P+FlyOffsetAIm) = fly2i; + *(fly0P+FlyOffsetB) = fly7r; + *(fly0P+FlyOffsetBIm) = fly7i; + + fly0P -= Nrems2; + fly0r = *(fly0P); + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + LoopCnt -= 1; + fly1P = (IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2)); + }; + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + + *(fly0P) = t0r; + *(fly0P+1) = t0i; + *(fly0P+2) = fly1r; + *(fly0P+(2+1)) = fly1i; + *(fly0P+FlyOffsetA) = t1r; + *(fly0P+FlyOffsetAIm) = t1i; + *(fly0P+FlyOffsetB) = fly3r; + *(fly0P+FlyOffsetBIm) = fly3i; + + }; +}; + + + +/**** FFTC **************/ + +NdiffU = 2; +Flyinc = (NdiffU); + +NsameU4 = Ntbl[M]/4; +LoopN = Ntbl[M-3]; + +stage = ((M-1)/3); +if ( (M-1-(stage * 3)) != 0 ){ + FlyOffsetA = Flyinc << 2; + FlyOffsetB = FlyOffsetA << 1; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + if ( (M-1-(stage * 3)) == 1 ){ + /* 1 radix 2 stage */ + + IOP = ioptr; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 + t1 - - t1 + f2 - 1- f5 + f1 - -i- f7 + f4 - - f4 + f0 - - f0 + f6 - 1- f2 + f3 - -i- f1 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r - fly1i; + fly7i = t1i + fly1r; + t1r = t1r + fly1i; + t1i = t1i - fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r - fly3i; + fly1i = fly0i + fly3r; + fly0r = fly0r + fly3i; + fly0i = fly0i - fly3r; + + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly0P + FlyOffsetA) = fly4r; + *(fly0P + FlyOffsetAIm) = fly4i; + *(fly3P + FlyOffsetA) = fly1r; + *(fly3P + FlyOffsetAIm) = fly1i; + *(fly1P + FlyOffsetA) = fly0r; + *(fly1P + FlyOffsetAIm) = fly0i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + }; + + NsameU4 >>= 1; + LoopN >>= 1; + NdiffU <<= 1; + Flyinc = Flyinc << 1; + } + else{ + /* 1 radix 4 stage */ + IOP = ioptr; + + U3r = 0.7071067811865475244008443621; /* sqrt(0.5); */ + U3i = U3r; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 - - t0 + t1 - - t1 - - t1 + f2 - 1- f5 - - f5 + f1 - -i- f7 - - f7 + f4 - - f4 - 1- f6 + f0 - - f0 -U3 - f3 + f6 - 1- f2 - -i- f4 + f3 - -i- f1 -U3a- f2 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r - fly1i; + fly7i = t1i + fly1r; + t1r = t1r + fly1i; + t1i = t1i - fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r - fly3i; + fly1i = fly0i + fly3r; + fly0r = fly0r + fly3i; + fly0i = fly0i - fly3r; + + + fly6r = t0r - fly4r; + fly6i = t0i - fly4i; + t0r = t0r + fly4r; + t0i = t0i + fly4i; + + fly3r = fly5r - fly2i; + fly3i = fly5i + fly2r; + fly5r = fly5r + fly2i; + fly5i = fly5i - fly2r; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r - U3i * fly0i; + fly4i = t1i + U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly2r = fly7r + U3i * fly1r; + fly2r = fly2r - U3r * fly1i; + fly2i = fly7i + U3r * fly1r; + fly2i = fly2i + U3i * fly1i; + fly7r = scale * fly7r - fly2r; + fly7i = scale * fly7i - fly2i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P + FlyOffsetA) = fly3r; + *(fly2P + FlyOffsetAIm) = fly3i; + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly3P + FlyOffsetA) = fly2r; + *(fly3P + FlyOffsetAIm) = fly2i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + + }; + + NsameU4 >>= 2; + LoopN >>= 2; + NdiffU <<= 2; + Flyinc = Flyinc << 2; + }; +}; + +NsameU2 = NsameU4 >> 1; +NsameU1 = NsameU2 >> 1; +Flyinc <<= 1; +FlyOffsetA = Flyinc << 2; +FlyOffsetB = FlyOffsetA << 1; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetBIm = FlyOffsetB + 1; +LoopN >>= 1; +/* ****** RADIX 8 Stages */ +for (stage = stage<<1; stage > 0 ; stage--){ + + /* an fft stage is done in two parts to ease use of the single quadrant cos table */ + +/* fftcalc1(iobuf, Utbl, N, NdiffU, LoopN); */ + if(!(stage&1)){ + U0rP = &Utbl[0]; + U0iP = &Utbl[Ntbl[M-2]]; + U1rP = U0rP; + U1iP = U0iP; + U2rP = U0rP; + U2iP = U0iP; + U3offset = (Ntbl[M]) / 8; + + IOP = ioptr; + + U0r = *U0rP, + U0i = *U0iP; + U1r = *U1rP, + U1i = *U1iP; + U2r = *U2rP, + U2i = *U2iP; + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + } + + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + for (diffUcnt = (NdiffU)>>1; diffUcnt != 0; diffUcnt--){ + + /* Butterflys */ + /* + f0 - - t0 - - t0 - - t0 + f1 -U0 - t1 - - t1 - - t1 + f2 - - f2 -U1 - f5 - - f3 + f3 -U0 - f1 -U1a- f7 - - f7 + f4 - - f4 - - f4 -U2 - f6 + f5 -U0 - f0 - - f0 -U3 - f4 + f6 - - f6 -U1 - f2 -U2a- f2 + f7 -U0 - f3 -U1a- f1 -U3a- f5 + */ + + fly0r = *(IOP); + fly0i = *(IOP+1); + fly1r = *(fly1P); + fly1i = *(fly1P+1); + + for (LoopCnt = LoopN-1; LoopCnt > 0 ; LoopCnt--){ + + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r - U0i * fly1i; + t1i = fly0i + U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r - U0i * fly3i; + fly1i = fly2i + U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r - U0i * fly5i; + fly0i = fly4i + U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r - U0i * fly7i; + fly3i = fly6i + U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r - U1i * fly2i; + fly5i = t0i + U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r - U1r * fly1i; + fly7i = t1i + U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r - U1i * fly6i; + fly2i = fly4i + U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r - U1r * fly3i; + fly1i = fly0i + U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r - U2i * fly4i; + fly6i = t0i + U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r + U2r * fly2i; + fly3i = fly5i - U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r - U3i * fly0i; + fly4i = t1i + U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r - U3r * fly1i; + fly5i = fly7i + U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + + fly0r = *(fly0P + FlyOffsetB); + fly0i = *(fly0P + FlyOffsetBIm); + + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + fly1r = *(fly1P + FlyOffsetB); + fly1i = *(fly1P + FlyOffsetBIm); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + }; + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r - U0i * fly1i; + t1i = fly0i + U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r - U0i * fly3i; + fly1i = fly2i + U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r - U0i * fly5i; + fly0i = fly4i + U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r - U0i * fly7i; + fly3i = fly6i + U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r - U1i * fly2i; + fly5i = t0i + U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r - U1r * fly1i; + fly7i = t1i + U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r - U1i * fly6i; + fly2i = fly4i + U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r - U1r * fly3i; + fly1i = fly0i + U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + U0i = *(U0iP = (U0iP - NsameU4)); + U0r = *(U0rP = (U0rP + NsameU4)); + U1r = *(U1rP = (U1rP + NsameU2)); + U1i = *(U1iP = (U1iP - NsameU2)); + if(stage&1) + U0r = -U0r; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r - U2i * fly4i; + fly6i = t0i + U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r + U2r * fly2i; + fly3i = fly5i - U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r - U3i * fly0i; + fly4i = t1i + U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r - U3r * fly1i; + fly5i = fly7i + U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + + U2r = *(U2rP = (U2rP + NsameU1)); + U2i = *(U2iP = (U2iP - NsameU1)); + + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + IOP = IOP + 2; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + }; + NsameU4 = -NsameU4; + + if(stage&1){ + LoopN >>= 3; + NsameU1 >>= 3; + NsameU2 >>= 3; + NsameU4 >>= 3; + NdiffU <<= 3; + Flyinc <<= 3; + FlyOffsetA <<= 3; + FlyOffsetB <<= 3; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + } +} +ioptr += 2*Ntbl[M]; +} +} + +void iffts(float *ioptr, long M, long Rows, float *Utbl){ +/* Compute in-place inverse complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +long Flyinc; +long FlyOffsetA; +long FlyOffsetAIm; +long FlyOffsetB; +long FlyOffsetBIm; +long NsameU1; +long NsameU2; +long NsameU4; +long diffUcnt; +long LoopCnt; + +float scale; +float fly0r; +float fly0i; +float fly1r; +float fly1i; +float fly2r; +float fly2i; +float fly3r; +float fly3i; +float fly4r; +float fly4i; +float fly5r; +float fly5i; +float fly6r; +float fly6i; +float fly7r; +float fly7i; +float U0r; +float U0i; +float U1r; +float U1i; +float U2r; +float U2i; +float U3r; +float U3i; +float t0r; +float t0i; +float t1r; +float t1i; + +float *fly0P; +float *fly1P; +float *fly2P; +float *fly3P; +float *U0rP; +float *U0iP; +float *U1rP; +float *U1iP; +float *U2rP; +float *U2iP; +float *IOP; +long U3offset; + +long stage; +long NdiffU; +long LoopN; + +const long BRshift = MAXMROOT - (M>>1); +const long Nrems2 = Ntbl[M-(M>>1)+1]; +const long Nroot_1_ColInc = (Ntbl[M-1]-Ntbl[M-(M>>1)])*2; + +for (;Rows>0;Rows--){ + +FlyOffsetA = Ntbl[M] * 2/2; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetB = FlyOffsetA + 2; +FlyOffsetBIm = FlyOffsetB + 1; + +/* BitrevR2 ** bit reverse and first radix 2 stage ******/ + +scale = 1./Ntbl[M]; +for (stage = 0; stage < Ntbl[M-(M>>1)]*2; stage += Ntbl[M>>1]*2){ + for (LoopN = (Ntbl[(M>>1)-1]-1); LoopN >= 0; LoopN--){ + LoopCnt = (Ntbl[(M>>1)-1]-1); + fly0P = ioptr + Nroot_1_ColInc + ((int)BRcnt[LoopN] >> BRshift)*(2*2) + stage; + IOP = ioptr + (LoopN<<(M+1)/2) * 2 + stage; + fly1P = IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2); + fly0r = *(fly0P); + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + for (; LoopCnt > LoopN;){ + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + fly4r = *(fly1P); + fly4i = *(fly1P+1); + fly5r = *(fly1P+FlyOffsetA); + fly5i = *(fly1P+FlyOffsetAIm); + fly6r = *(fly1P+2); + fly6i = *(fly1P+(2+1)); + fly7r = *(fly1P+FlyOffsetB); + fly7i = *(fly1P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + fly0r = fly4r + fly5r; + fly0i = fly4i + fly5i; + fly5r = fly4r - fly5r; + fly5i = fly4i - fly5i; + fly2r = fly6r + fly7r; + fly2i = fly6i + fly7i; + fly7r = fly6r - fly7r; + fly7i = fly6i - fly7i; + + *(fly1P) = scale*t0r; + *(fly1P+1) = scale*t0i; + *(fly1P+2) = scale*fly1r; + *(fly1P+(2+1)) = scale*fly1i; + *(fly1P+FlyOffsetA) = scale*t1r; + *(fly1P+FlyOffsetAIm) = scale*t1i; + *(fly1P+FlyOffsetB) = scale*fly3r; + *(fly1P+FlyOffsetBIm) = scale*fly3i; + *(fly0P) = scale*fly0r; + *(fly0P+1) = scale*fly0i; + *(fly0P+2) = scale*fly5r; + *(fly0P+(2+1)) = scale*fly5i; + *(fly0P+FlyOffsetA) = scale*fly2r; + *(fly0P+FlyOffsetAIm) = scale*fly2i; + *(fly0P+FlyOffsetB) = scale*fly7r; + *(fly0P+FlyOffsetBIm) = scale*fly7i; + + fly0P -= Nrems2; + fly0r = *(fly0P); + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + LoopCnt -= 1; + fly1P = (IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2)); + }; + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + + *(fly0P) = scale*t0r; + *(fly0P+1) = scale*t0i; + *(fly0P+2) = scale*fly1r; + *(fly0P+(2+1)) = scale*fly1i; + *(fly0P+FlyOffsetA) = scale*t1r; + *(fly0P+FlyOffsetAIm) = scale*t1i; + *(fly0P+FlyOffsetB) = scale*fly3r; + *(fly0P+FlyOffsetBIm) = scale*fly3i; + + }; +}; + +/**** FFTC **************/ + +scale = 2.0; + +NdiffU = 2; +Flyinc = (NdiffU); + +NsameU4 = Ntbl[M]/4; +LoopN = Ntbl[M-3]; + +stage = ((M-1)/3); +if ( (M-1-(stage * 3)) != 0 ){ + FlyOffsetA = Flyinc << 2; + FlyOffsetB = FlyOffsetA << 1; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + if ( (M-1-(stage * 3)) == 1 ){ + /* 1 radix 2 stage */ + + IOP = ioptr; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 + t1 - - t1 + f2 - 1- f5 + f1 - -i- f7 + f4 - - f4 + f0 - - f0 + f6 - 1- f2 + f3 - -i- f1 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r + fly1i; + fly7i = t1i - fly1r; + t1r = t1r - fly1i; + t1i = t1i + fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r + fly3i; + fly1i = fly0i - fly3r; + fly0r = fly0r - fly3i; + fly0i = fly0i + fly3r; + + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly0P + FlyOffsetA) = fly4r; + *(fly0P + FlyOffsetAIm) = fly4i; + *(fly3P + FlyOffsetA) = fly1r; + *(fly3P + FlyOffsetAIm) = fly1i; + *(fly1P + FlyOffsetA) = fly0r; + *(fly1P + FlyOffsetAIm) = fly0i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + }; + + NsameU4 >>= 1; + LoopN >>= 1; + NdiffU <<= 1; + Flyinc = Flyinc << 1; + } + else{ + /* 1 radix 4 stage */ + IOP = ioptr; + + U3r = 0.7071067811865475244008443621; /* sqrt(0.5); */ + U3i = U3r; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 - - t0 + t1 - - t1 - - t1 + f2 - 1- f5 - - f5 + f1 - -i- f7 - - f7 + f4 - - f4 - 1- f6 + f0 - - f0 -U3 - f3 + f6 - 1- f2 - -i- f4 + f3 - -i- f1 -U3a- f2 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r + fly1i; + fly7i = t1i - fly1r; + t1r = t1r - fly1i; + t1i = t1i + fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r + fly3i; + fly1i = fly0i - fly3r; + fly0r = fly0r - fly3i; + fly0i = fly0i + fly3r; + + fly6r = t0r - fly4r; + fly6i = t0i - fly4i; + t0r = t0r + fly4r; + t0i = t0i + fly4i; + + fly3r = fly5r + fly2i; + fly3i = fly5i - fly2r; + fly5r = fly5r - fly2i; + fly5i = fly5i + fly2r; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r + U3i * fly0i; + fly4i = t1i - U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly2r = fly7r + U3i * fly1r; + fly2r = fly2r + U3r * fly1i; + fly2i = fly7i - U3r * fly1r; + fly2i = fly2i + U3i * fly1i; + fly7r = scale * fly7r - fly2r; + fly7i = scale * fly7i - fly2i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P + FlyOffsetA) = fly3r; + *(fly2P + FlyOffsetAIm) = fly3i; + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly3P + FlyOffsetA) = fly2r; + *(fly3P + FlyOffsetAIm) = fly2i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + + }; + + NsameU4 >>= 2; + LoopN >>= 2; + NdiffU <<= 2; + Flyinc = Flyinc << 2; + }; +}; + +NsameU2 = NsameU4 >> 1; +NsameU1 = NsameU2 >> 1; +Flyinc <<= 1; +FlyOffsetA = Flyinc << 2; +FlyOffsetB = FlyOffsetA << 1; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetBIm = FlyOffsetB + 1; +LoopN >>= 1; + +/* ****** RADIX 8 Stages */ +for (stage = stage<<1; stage > 0 ; stage--){ + + /* an fft stage is done in two parts to ease use of the single quadrant cos table */ + +/* fftcalc1(iobuf, Utbl, N, NdiffU, LoopN); */ + if(!(stage&1)){ + U0rP = &Utbl[0]; + U0iP = &Utbl[Ntbl[M-2]]; + U1rP = U0rP; + U1iP = U0iP; + U2rP = U0rP; + U2iP = U0iP; + U3offset = (Ntbl[M]) / 8; + + IOP = ioptr; + + U0r = *U0rP, + U0i = *U0iP; + U1r = *U1rP, + U1i = *U1iP; + U2r = *U2rP, + U2i = *U2iP; + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + } + + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + for (diffUcnt = (NdiffU)>>1; diffUcnt > 0; diffUcnt--){ + + /* Butterflys */ + /* + f0 - - t0 - - t0 - - t0 + f1 -U0 - t1 - - t1 - - t1 + f2 - - f2 -U1 - f5 - - f3 + f3 -U0 - f1 -U1a- f7 - - f7 + f4 - - f4 - - f4 -U2 - f6 + f5 -U0 - f0 - - f0 -U3 - f4 + f6 - - f6 -U1 - f2 -U2a- f2 + f7 -U0 - f3 -U1a- f1 -U3a- f5 + */ + + fly0r = *(IOP); + fly0i = *(IOP+1); + fly1r = *(fly1P); + fly1i = *(fly1P+1); + + for (LoopCnt = LoopN-1; LoopCnt > 0 ; LoopCnt--){ + + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r + U0i * fly1i; + t1i = fly0i - U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r + U0i * fly3i; + fly1i = fly2i - U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r + U0i * fly5i; + fly0i = fly4i - U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r + U0i * fly7i; + fly3i = fly6i - U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r + U1i * fly2i; + fly5i = t0i - U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r + U1r * fly1i; + fly7i = t1i - U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r + U1i * fly6i; + fly2i = fly4i - U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r + U1r * fly3i; + fly1i = fly0i - U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r + U2i * fly4i; + fly6i = t0i - U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r - U2r * fly2i; + fly3i = fly5i + U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r + U3i * fly0i; + fly4i = t1i - U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r + U3r * fly1i; + fly5i = fly7i - U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + + fly0r = *(fly0P + FlyOffsetB); + fly0i = *(fly0P + FlyOffsetBIm); + + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + fly1r = *(fly1P + FlyOffsetB); + fly1i = *(fly1P + FlyOffsetBIm); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + + }; + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r + U0i * fly1i; + t1i = fly0i - U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r + U0i * fly3i; + fly1i = fly2i - U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r + U0i * fly5i; + fly0i = fly4i - U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r + U0i * fly7i; + fly3i = fly6i - U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r + U1i * fly2i; + fly5i = t0i - U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r + U1r * fly1i; + fly7i = t1i - U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r + U1i * fly6i; + fly2i = fly4i - U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r + U1r * fly3i; + fly1i = fly0i - U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + U0i = *(U0iP = (U0iP - NsameU4)); + U0r = *(U0rP = (U0rP + NsameU4)); + U1r = *(U1rP = (U1rP + NsameU2)); + U1i = *(U1iP = (U1iP - NsameU2)); + if(stage&1) + U0r = - U0r; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r + U2i * fly4i; + fly6i = t0i - U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r - U2r * fly2i; + fly3i = fly5i + U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r + U3i * fly0i; + fly4i = t1i - U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r + U3r * fly1i; + fly5i = fly7i - U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + + U2r = *(U2rP = (U2rP + NsameU1)); + U2i = *(U2iP = (U2iP - NsameU1)); + + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + IOP = IOP + 2; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + }; + NsameU4 = -NsameU4; + + if(stage&1){ + LoopN >>= 3; + NsameU1 >>= 3; + NsameU2 >>= 3; + NsameU4 >>= 3; + NdiffU <<= 3; + Flyinc = Flyinc << 3; + FlyOffsetA <<= 3; + FlyOffsetB <<= 3; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + } +} +ioptr += 2*Ntbl[M]; +} +} + +/* rffts */ +/* compute multiple real input FFTs on 'Rows' consecutively stored arrays */ +/* ioptr = pointer to the data in and out */ +/* M = log2 of fft size */ +/* Rows = number of FFTs to compute */ +/* Utbl = Pointer to cosine table */ + +void rffts(float *ioptr, long M, long Rows, float *Utbl){ +/* Compute in-place real fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = real input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ + +long Flyinc; +long FlyOffsetA; +long FlyOffsetAIm; +long FlyOffsetB; +long FlyOffsetBIm; +long NsameU1; +long NsameU2; +long NsameU4; +long diffUcnt; +long LoopCnt; +float scale; +float fly0r; +float fly0i; +float fly1r; +float fly1i; +float fly2r; +float fly2i; +float fly3r; +float fly3i; +float fly4r; +float fly4i; +float fly5r; +float fly5i; +float fly6r; +float fly6i; +float fly7r; +float fly7i; +float U0r; +float U0i; +float U1r; +float U1i; +float U2r; +float U2i; +float U3r; +float U3i; +float t0r; +float t0i; +float t1r; +float t1i; + +float *fly0P; +float *fly1P; +float *fly2P; +float *fly3P; + +float *U0rP; +float *U0iP; +float *U1rP; +float *U1iP; +float *U2rP; +float *U2iP; +float *IOP; +long U3offset; + +long stage; +long NdiffU; +long LoopN; + +const long BRshift = MAXMROOT - ((M-1)>>1); /* for RFFT */ +const long Nrems2 = Ntbl[(M-1)-((M-1)>>1)+1]; /* for RFFT */ +const long Nroot_1_ColInc = (Ntbl[(M-1)-1]-Ntbl[(M-1)-((M-1)>>1)])*2; /* for RFFT */ + +for (;Rows>0;Rows--){ + +M=M-1; /* for RFFT */ + +FlyOffsetA = Ntbl[M] * 2/2; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetB = FlyOffsetA + 2; +FlyOffsetBIm = FlyOffsetB + 1; + +/* BitrevR2 ** bit reverse shuffle and first radix 2 stage ******/ + +scale = 0.5; +for (stage = 0; stage < Ntbl[M-(M>>1)]*2; stage += Ntbl[M>>1]*2){ + for (LoopN = (Ntbl[(M>>1)-1]-1); LoopN >= 0; LoopN--){ + LoopCnt = (Ntbl[(M>>1)-1]-1); + fly0P = ioptr + Nroot_1_ColInc + ((int)BRcnt[LoopN] >> BRshift)*(2*2) + stage; + IOP = ioptr + (LoopN<<(M+1)/2) * 2 + stage; + fly1P = IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2); + fly0r = *fly0P; + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + for (; LoopCnt > LoopN;){ + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + fly4r = *fly1P; + fly4i = *(fly1P+1); + fly5r = *(fly1P+FlyOffsetA); + fly5i = *(fly1P+FlyOffsetAIm); + fly6r = *(fly1P+2); + fly6i = *(fly1P+(2+1)); + fly7r = *(fly1P+FlyOffsetB); + fly7i = *(fly1P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + fly0r = fly4r + fly5r; + fly0i = fly4i + fly5i; + fly5r = fly4r - fly5r; + fly5i = fly4i - fly5i; + fly2r = fly6r + fly7r; + fly2i = fly6i + fly7i; + fly7r = fly6r - fly7r; + fly7i = fly6i - fly7i; + + *fly1P = scale*t0r; + *(fly1P+1) = scale*t0i; + *(fly1P+2) = scale*fly1r; + *(fly1P+(2+1)) = scale*fly1i; + *(fly1P+FlyOffsetA) = scale*t1r; + *(fly1P+FlyOffsetAIm) = scale*t1i; + *(fly1P+FlyOffsetB) = scale*fly3r; + *(fly1P+FlyOffsetBIm) = scale*fly3i; + *fly0P = scale*fly0r; + *(fly0P+1) = scale*fly0i; + *(fly0P+2) = scale*fly5r; + *(fly0P+(2+1)) = scale*fly5i; + *(fly0P+FlyOffsetA) = scale*fly2r; + *(fly0P+FlyOffsetAIm) = scale*fly2i; + *(fly0P+FlyOffsetB) = scale*fly7r; + *(fly0P+FlyOffsetBIm) = scale*fly7i; + + fly0P -= Nrems2; + fly0r = *fly0P; + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + LoopCnt -= 1; + fly1P = (IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2)); + }; + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + + *fly0P = scale*t0r; + *(fly0P+1) = scale*t0i; + *(fly0P+2) = scale*fly1r; + *(fly0P+(2+1)) = scale*fly1i; + *(fly0P+FlyOffsetA) = scale*t1r; + *(fly0P+FlyOffsetAIm) = scale*t1i; + *(fly0P+FlyOffsetB) = scale*fly3r; + *(fly0P+FlyOffsetBIm) = scale*fly3i; + + }; +}; + + + +/**** FFTC **************/ + +scale = 2.0; + +NdiffU = 2; +Flyinc = (NdiffU); + +NsameU4 = Ntbl[M+1]/4; /* for RFFT */ +LoopN = Ntbl[M-3]; + +stage = ((M-1)/3); +if ( (M-1-(stage * 3)) != 0 ){ + FlyOffsetA = Flyinc << 2; + FlyOffsetB = FlyOffsetA << 1; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + if ( (M-1-(stage * 3)) == 1 ){ + /* 1 radix 2 stage */ + + IOP = ioptr; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 + t1 - - t1 + f2 - 1- f5 + f1 - -i- f7 + f4 - - f4 + f0 - - f0 + f6 - 1- f2 + f3 - -i- f1 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r - fly1i; + fly7i = t1i + fly1r; + t1r = t1r + fly1i; + t1i = t1i - fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r - fly3i; + fly1i = fly0i + fly3r; + fly0r = fly0r + fly3i; + fly0i = fly0i - fly3r; + + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly0P + FlyOffsetA) = fly4r; + *(fly0P + FlyOffsetAIm) = fly4i; + *(fly3P + FlyOffsetA) = fly1r; + *(fly3P + FlyOffsetAIm) = fly1i; + *(fly1P + FlyOffsetA) = fly0r; + *(fly1P + FlyOffsetAIm) = fly0i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + }; + + NsameU4 >>= 1; + LoopN >>= 1; + NdiffU <<= 1; + Flyinc = Flyinc << 1; + } + else{ + /* 1 radix 4 stage */ + IOP = ioptr; + + U3r = 0.7071067811865475244008443621; /* sqrt(0.5); */ + U3i = U3r; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 - - t0 + t1 - - t1 - - t1 + f2 - 1- f5 - - f5 + f1 - -i- f7 - - f7 + f4 - - f4 - 1- f6 + f0 - - f0 -U3 - f3 + f6 - 1- f2 - -i- f4 + f3 - -i- f1 -U3a- f2 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r - fly1i; + fly7i = t1i + fly1r; + t1r = t1r + fly1i; + t1i = t1i - fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r - fly3i; + fly1i = fly0i + fly3r; + fly0r = fly0r + fly3i; + fly0i = fly0i - fly3r; + + fly6r = t0r - fly4r; + fly6i = t0i - fly4i; + t0r = t0r + fly4r; + t0i = t0i + fly4i; + + fly3r = fly5r - fly2i; + fly3i = fly5i + fly2r; + fly5r = fly5r + fly2i; + fly5i = fly5i - fly2r; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r - U3i * fly0i; + fly4i = t1i + U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly2r = fly7r + U3i * fly1r; + fly2r = fly2r - U3r * fly1i; + fly2i = fly7i + U3r * fly1r; + fly2i = fly2i + U3i * fly1i; + fly7r = scale * fly7r - fly2r; + fly7i = scale * fly7i - fly2i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P + FlyOffsetA) = fly3r; + *(fly2P + FlyOffsetAIm) = fly3i; + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly3P + FlyOffsetA) = fly2r; + *(fly3P + FlyOffsetAIm) = fly2i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + + }; + + NsameU4 >>= 2; + LoopN >>= 2; + NdiffU <<= 2; + Flyinc = Flyinc << 2; + }; +}; + +NsameU2 = NsameU4 >> 1; +NsameU1 = NsameU2 >> 1; +Flyinc <<= 1; +FlyOffsetA = Flyinc << 2; +FlyOffsetB = FlyOffsetA << 1; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetBIm = FlyOffsetB + 1; +LoopN >>= 1; + +/* ****** RADIX 8 Stages */ +for (stage = stage<<1; stage > 0 ; stage--){ + + /* an fft stage is done in two parts to ease use of the single quadrant cos table */ + +/* fftcalc1(iobuf, Utbl, N, NdiffU, LoopN); */ + if(!(stage&1)){ + U0rP = &Utbl[0]; + U0iP = &Utbl[Ntbl[M-1]]; /* for RFFT */ + U1rP = U0rP; + U1iP = U0iP; + U2rP = U0rP; + U2iP = U0iP; + U3offset = (Ntbl[M+1]) / 8; /* for RFFT */ + + IOP = ioptr; + + U0r = *U0rP, + U0i = *U0iP; + U1r = *U1rP, + U1i = *U1iP; + U2r = *U2rP, + U2i = *U2iP; + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + } + + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + for (diffUcnt = (NdiffU)>>1; diffUcnt > 0; diffUcnt--){ + + /* Butterflys */ + /* + f0 - - t0 - - t0 - - t0 + f1 -U0 - t1 - - t1 - - t1 + f2 - - f2 -U1 - f5 - - f3 + f3 -U0 - f1 -U1a- f7 - - f7 + f4 - - f4 - - f4 -U2 - f6 + f5 -U0 - f0 - - f0 -U3 - f4 + f6 - - f6 -U1 - f2 -U2a- f2 + f7 -U0 - f3 -U1a- f1 -U3a- f5 + */ + + fly0r = *(IOP); + fly0i = *(IOP+1); + fly1r = *(fly1P); + fly1i = *(fly1P+1); + + for (LoopCnt = LoopN-1; LoopCnt > 0 ; LoopCnt--){ + + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r - U0i * fly1i; + t1i = fly0i + U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r - U0i * fly3i; + fly1i = fly2i + U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r - U0i * fly5i; + fly0i = fly4i + U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r - U0i * fly7i; + fly3i = fly6i + U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r - U1i * fly2i; + fly5i = t0i + U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r - U1r * fly1i; + fly7i = t1i + U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r - U1i * fly6i; + fly2i = fly4i + U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r - U1r * fly3i; + fly1i = fly0i + U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r - U2i * fly4i; + fly6i = t0i + U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r + U2r * fly2i; + fly3i = fly5i - U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r - U3i * fly0i; + fly4i = t1i + U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r - U3r * fly1i; + fly5i = fly7i + U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + + fly0r = *(fly0P + FlyOffsetB); + fly0i = *(fly0P + FlyOffsetBIm); + + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + fly1r = *(fly1P + FlyOffsetB); + fly1i = *(fly1P + FlyOffsetBIm); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + }; + + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r - U0i * fly1i; + t1i = fly0i + U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r - U0i * fly3i; + fly1i = fly2i + U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r - U0i * fly5i; + fly0i = fly4i + U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r - U0i * fly7i; + fly3i = fly6i + U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r - U1i * fly2i; + fly5i = t0i + U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r - U1r * fly1i; + fly7i = t1i + U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r - U1i * fly6i; + fly2i = fly4i + U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r - U1r * fly3i; + fly1i = fly0i + U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + U0i = *(U0iP = (U0iP - NsameU4)); + U0r = *(U0rP = (U0rP + NsameU4)); + U1r = *(U1rP = (U1rP + NsameU2)); + U1i = *(U1iP = (U1iP - NsameU2)); + if(stage&1) + U0r = -U0r; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r - U2i * fly4i; + fly6i = t0i + U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r + U2r * fly2i; + fly3i = fly5i - U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r - U3i * fly0i; + fly4i = t1i + U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r - U3r * fly1i; + fly5i = fly7i + U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + + U2r = *(U2rP = (U2rP + NsameU1)); + U2i = *(U2iP = (U2iP - NsameU1)); + + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + IOP = IOP + 2; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + }; + NsameU4 = -NsameU4; + + if(stage&1){ + LoopN >>= 3; + NsameU1 >>= 3; + NsameU2 >>= 3; + NsameU4 >>= 3; + NdiffU <<= 3; + Flyinc = Flyinc << 3; + FlyOffsetA <<= 3; + FlyOffsetB <<= 3; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + } +} + +/* Finish RFFT */ +M=M+1; + +FlyOffsetA = Ntbl[M] * 2/4; +FlyOffsetAIm = Ntbl[M] * 2/4 + 1; + +IOP = ioptr; + +fly0P = (IOP + Ntbl[M]*2/4); +fly1P = (IOP + Ntbl[M]*2/8); + +U0rP = &Utbl[Ntbl[M-3]]; + +U0r = *U0rP, + +fly0r = *(IOP); +fly0i = *(IOP + 1); +fly1r = *(fly0P); +fly1i = *(fly0P + 1); +fly2r = *(fly1P); +fly2i = *(fly1P + 1); +fly3r = *(fly1P + FlyOffsetA); +fly3i = *(fly1P + FlyOffsetAIm); + + t0r = scale * fly0r + scale * fly0i; /* compute Re(x[0]) */ + t0i = scale * fly0r - scale * fly0i; /* compute Re(x[N/2]) */ + t1r = scale * fly1r; + t1i = -scale * fly1i; + + fly0r = fly2r + fly3r; + fly0i = fly2i - fly3i; + fly1r = fly2i + fly3i; + fly1i = fly3r - fly2r; + + fly2r = fly0r + U0r * fly1r; + fly2r = fly2r + U0r * fly1i; + fly2i = fly0i - U0r * fly1r; + fly2i = fly2i + U0r * fly1i; + fly3r = scale * fly0r - fly2r; + fly3i = fly2i - scale * fly0i; + +*(IOP) = t0r; +*(IOP + 1) = t0i; +*(fly0P) = t1r; +*(fly0P + 1) = t1i; +*(fly1P) = fly2r; +*(fly1P + 1) = fly2i; +*(fly1P + FlyOffsetA) = fly3r; +*(fly1P + FlyOffsetAIm) = fly3i; + +U0rP = &Utbl[1]; +U0iP = &Utbl[Ntbl[M-2]-1]; + +U0r = *U0rP, +U0i = *U0iP; + +fly0P = (IOP + 2); +fly1P = (IOP + (Ntbl[M-2]-1)*2); + + /* Butterflys */ + /* + f0 - t0 - - f2 + f1 - t1 -U0 - f3 + f2 - f0 - - t0 + f3 - f1 -U0a- t1 + */ + +for (diffUcnt = Ntbl[M-3]-1; diffUcnt > 0 ; diffUcnt--){ + + fly0r = *(fly0P); + fly0i = *(fly0P + 1); + fly1r = *(fly1P + FlyOffsetA); + fly1i = *(fly1P + FlyOffsetAIm); + fly2r = *(fly1P); + fly2i = *(fly1P + 1); + fly3r = *(fly0P + FlyOffsetA); + fly3i = *(fly0P + FlyOffsetAIm); + + t0r = fly0r + fly1r; + t0i = fly0i - fly1i; + t1r = fly0i + fly1i; + t1i = fly1r - fly0r; + + fly0r = fly2r + fly3r; + fly0i = fly2i - fly3i; + fly1r = fly2i + fly3i; + fly1i = fly3r - fly2r; + + fly2r = t0r + U0r * t1r; + fly2r = fly2r + U0i * t1i; + fly2i = t0i - U0i * t1r; + fly2i = fly2i + U0r * t1i; + fly3r = scale * t0r - fly2r; + fly3i = fly2i - scale * t0i; + + t0r = fly0r + U0i * fly1r; + t0r = t0r + U0r * fly1i; + t0i = fly0i - U0r * fly1r; + t0i = t0i + U0i * fly1i; + t1r = scale * fly0r - t0r; + t1i = t0i - scale * fly0i; + + *(fly0P) = fly2r; + *(fly0P + 1) = fly2i; + *(fly1P + FlyOffsetA) = fly3r; + *(fly1P + FlyOffsetAIm) = fly3i; + + U0r = *(U0rP = (U0rP + 1)); + U0i = *(U0iP = (U0iP - 1)); + + *(fly1P) = t0r; + *(fly1P + 1) = t0i; + *(fly0P + FlyOffsetA) = t1r; + *(fly0P + FlyOffsetAIm) = t1i; + + fly0P += 2; + fly1P -= 2; +}; + +ioptr += Ntbl[M]; +} +} + +void riffts(float *ioptr, long M, long Rows, float *Utbl){ +/* Compute in-place real ifft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = real output data array */ + +long Flyinc; +long FlyOffsetA; +long FlyOffsetAIm; +long FlyOffsetB; +long FlyOffsetBIm; +long NsameU1; +long NsameU2; +long NsameU4; +long diffUcnt; +long LoopCnt; +float scale; +float fly0r; +float fly0i; +float fly1r; +float fly1i; +float fly2r; +float fly2i; +float fly3r; +float fly3i; +float fly4r; +float fly4i; +float fly5r; +float fly5i; +float fly6r; +float fly6i; +float fly7r; +float fly7i; +float U0r; +float U0i; +float U1r; +float U1i; +float U2r; +float U2i; +float U3r; +float U3i; +float t0r; +float t0i; +float t1r; +float t1i; + +float *fly0P; +float *fly1P; +float *fly2P; +float *fly3P; + +float *U0rP; +float *U0iP; +float *U1rP; +float *U1iP; +float *U2rP; +float *U2iP; +float *IOP; +long U3offset; + +long stage; +long NdiffU; +long LoopN; + +const long BRshift = MAXMROOT - ((M-1)>>1); /* for RIFFT */ +const long Nrems2 = Ntbl[(M-1)-((M-1)>>1)+1]; /* for RIFFT */ +const long Nroot_1_ColInc = (Ntbl[(M-1)-1]-Ntbl[(M-1)-((M-1)>>1)])*2; /* for RIFFT */ + +for (;Rows>0;Rows--){ + +/* Start RIFFT */ + +FlyOffsetA = Ntbl[M] * 2/4; +FlyOffsetAIm = Ntbl[M] * 2/4 + 1; + +IOP = ioptr; + +fly0P = (IOP + Ntbl[M]*2/4); +fly1P = (IOP + Ntbl[M]*2/8); + +U0rP = &Utbl[Ntbl[M-3]]; + +U0r = *U0rP, + +fly0r = *(IOP); +fly0i = *(IOP + 1); +fly1r = *(fly0P); +fly1i = *(fly0P + 1); +fly2r = *(fly1P); +fly2i = *(fly1P + 1); +fly3r = *(fly1P + FlyOffsetA); +fly3i = *(fly1P + FlyOffsetAIm); + + t0r = fly0r + fly0i; + t0i = fly0r - fly0i; + t1r = fly1r + fly1r; + t1i = -fly1i - fly1i; + + fly0r = fly2r + fly3r; + fly0i = fly2i - fly3i; + fly1r = fly2r - fly3r; + fly1i = fly2i + fly3i; + + fly3r = fly1r * U0r; + fly3r = fly3r - U0r * fly1i; + fly3i = fly1r * U0r; + fly3i = fly3i + U0r * fly1i; + + fly2r = fly0r - fly3i; + fly2i = fly0i + fly3r; + fly1r = fly0r + fly3i; + fly1i = -fly0i + fly3r; + +*(IOP) = t0r; +*(IOP + 1) = t0i; +*(fly0P) = t1r; +*(fly0P + 1) = t1i; +*(fly1P) = fly2r; +*(fly1P + 1) = fly2i; +*(fly1P + FlyOffsetA) = fly1r; +*(fly1P + FlyOffsetAIm) = fly1i; + +U0rP = &Utbl[1]; +U0iP = &Utbl[Ntbl[M-2]-1]; + +U0r = *U0rP, +U0i = *U0iP; + +fly0P = (IOP + 2); +fly1P = (IOP + (Ntbl[M-2]-1)*2); + + /* Butterflys */ + /* + f0 - t0 - f2 + f1 -t1 -U0- f3 - f1 + f2 - f0 - t0 + f3 -f1 -U0a t1 - f3 + */ + +for (diffUcnt = Ntbl[M-3]-1; diffUcnt > 0 ; diffUcnt--){ + + fly0r = *(fly0P); + fly0i = *(fly0P + 1); + fly1r = *(fly1P + FlyOffsetA); + fly1i = *(fly1P + FlyOffsetAIm); + fly2r = *(fly1P); + fly2i = *(fly1P + 1); + fly3r = *(fly0P + FlyOffsetA); + fly3i = *(fly0P + FlyOffsetAIm); + + t0r = fly0r + fly1r; + t0i = fly0i - fly1i; + t1r = fly0r - fly1r; + t1i = fly0i + fly1i; + + fly0r = fly2r + fly3r; + fly0i = fly2i - fly3i; + fly1r = fly2r - fly3r; + fly1i = fly2i + fly3i; + + + fly3r = t1r * U0r; + fly3r = fly3r - U0i * t1i; + fly3i = t1r * U0i; + fly3i = fly3i + U0r * t1i; + + t1r = fly1r * U0i; + t1r = t1r - U0r * fly1i; + t1i = fly1r * U0r; + t1i = t1i + U0i * fly1i; + + + fly2r = t0r - fly3i; + fly2i = t0i + fly3r; + fly1r = t0r + fly3i; + fly1i = -t0i + fly3r; + + t0r = fly0r - t1i; + t0i = fly0i + t1r; + fly3r = fly0r + t1i; + fly3i = -fly0i + t1r; + + + *(fly0P) = fly2r; + *(fly0P + 1) = fly2i; + *(fly1P + FlyOffsetA) = fly1r; + *(fly1P + FlyOffsetAIm) = fly1i; + + U0r = *(U0rP = (U0rP + 1)); + U0i = *(U0iP = (U0iP - 1)); + + *(fly1P) = t0r; + *(fly1P + 1) = t0i; + *(fly0P + FlyOffsetA) = fly3r; + *(fly0P + FlyOffsetAIm) = fly3i; + + fly0P += 2; + fly1P -= 2; +}; + +M=M-1; /* for RIFFT */ + +FlyOffsetA = Ntbl[M] * 2/2; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetB = FlyOffsetA + 2; +FlyOffsetBIm = FlyOffsetB + 1; + +/* BitrevR2 ** bit reverse shuffle and first radix 2 stage ******/ + +scale = 1./Ntbl[M+1]; +for (stage = 0; stage < Ntbl[M-(M>>1)]*2; stage += Ntbl[M>>1]*2){ + for (LoopN = (Ntbl[(M>>1)-1]-1); LoopN >= 0; LoopN--){ + LoopCnt = (Ntbl[(M>>1)-1]-1); + fly0P = ioptr + Nroot_1_ColInc + ((int)BRcnt[LoopN] >> BRshift)*(2*2) + stage; + IOP = ioptr + (LoopN<<(M+1)/2) * 2 + stage; + fly1P = IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2); + fly0r = *(fly0P); + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + for (; LoopCnt > LoopN;){ + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + fly4r = *(fly1P); + fly4i = *(fly1P+1); + fly5r = *(fly1P+FlyOffsetA); + fly5i = *(fly1P+FlyOffsetAIm); + fly6r = *(fly1P+2); + fly6i = *(fly1P+(2+1)); + fly7r = *(fly1P+FlyOffsetB); + fly7i = *(fly1P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + fly0r = fly4r + fly5r; + fly0i = fly4i + fly5i; + fly5r = fly4r - fly5r; + fly5i = fly4i - fly5i; + fly2r = fly6r + fly7r; + fly2i = fly6i + fly7i; + fly7r = fly6r - fly7r; + fly7i = fly6i - fly7i; + + *(fly1P) = scale*t0r; + *(fly1P+1) = scale*t0i; + *(fly1P+2) = scale*fly1r; + *(fly1P+(2+1)) = scale*fly1i; + *(fly1P+FlyOffsetA) = scale*t1r; + *(fly1P+FlyOffsetAIm) = scale*t1i; + *(fly1P+FlyOffsetB) = scale*fly3r; + *(fly1P+FlyOffsetBIm) = scale*fly3i; + *(fly0P) = scale*fly0r; + *(fly0P+1) = scale*fly0i; + *(fly0P+2) = scale*fly5r; + *(fly0P+(2+1)) = scale*fly5i; + *(fly0P+FlyOffsetA) = scale*fly2r; + *(fly0P+FlyOffsetAIm) = scale*fly2i; + *(fly0P+FlyOffsetB) = scale*fly7r; + *(fly0P+FlyOffsetBIm) = scale*fly7i; + + fly0P -= Nrems2; + fly0r = *(fly0P); + fly0i = *(fly0P+1); + fly1r = *(fly0P+FlyOffsetA); + fly1i = *(fly0P+FlyOffsetAIm); + LoopCnt -= 1; + fly1P = (IOP + ((int)BRcnt[LoopCnt] >> BRshift)*(2*2)); + }; + fly2r = *(fly0P+2); + fly2i = *(fly0P+(2+1)); + fly3r = *(fly0P+FlyOffsetB); + fly3i = *(fly0P+FlyOffsetBIm); + + t0r = fly0r + fly1r; + t0i = fly0i + fly1i; + fly1r = fly0r - fly1r; + fly1i = fly0i - fly1i; + t1r = fly2r + fly3r; + t1i = fly2i + fly3i; + fly3r = fly2r - fly3r; + fly3i = fly2i - fly3i; + + *(fly0P) = scale*t0r; + *(fly0P+1) = scale*t0i; + *(fly0P+2) = scale*fly1r; + *(fly0P+(2+1)) = scale*fly1i; + *(fly0P+FlyOffsetA) = scale*t1r; + *(fly0P+FlyOffsetAIm) = scale*t1i; + *(fly0P+FlyOffsetB) = scale*fly3r; + *(fly0P+FlyOffsetBIm) = scale*fly3i; + + }; +}; + +/**** FFTC **************/ + +scale = 2.0; + +NdiffU = 2; +Flyinc = (NdiffU); + +NsameU4 = Ntbl[M+1]/4; /* for RIFFT */ +LoopN = Ntbl[M-3]; + +stage = ((M-1)/3); +if ( (M-1-(stage * 3)) != 0 ){ + FlyOffsetA = Flyinc << 2; + FlyOffsetB = FlyOffsetA << 1; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + if ( (M-1-(stage * 3)) == 1 ){ + /* 1 radix 2 stage */ + + IOP = ioptr; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 + t1 - - t1 + f2 - 1- f5 + f1 - -i- f7 + f4 - - f4 + f0 - - f0 + f6 - 1- f2 + f3 - -i- f1 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r + fly1i; + fly7i = t1i - fly1r; + t1r = t1r - fly1i; + t1i = t1i + fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r + fly3i; + fly1i = fly0i - fly3r; + fly0r = fly0r - fly3i; + fly0i = fly0i + fly3r; + + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly0P + FlyOffsetA) = fly4r; + *(fly0P + FlyOffsetAIm) = fly4i; + *(fly3P + FlyOffsetA) = fly1r; + *(fly3P + FlyOffsetAIm) = fly1i; + *(fly1P + FlyOffsetA) = fly0r; + *(fly1P + FlyOffsetAIm) = fly0i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + }; + + NsameU4 >>= 1; + LoopN >>= 1; + NdiffU <<= 1; + Flyinc = Flyinc << 1; + } + else{ + /* 1 radix 4 stage */ + IOP = ioptr; + + U3r = 0.7071067811865475244008443621; /* sqrt(0.5); */ + U3i = U3r; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + /* Butterflys */ + /* + t0 - - t0 - - t0 + t1 - - t1 - - t1 + f2 - 1- f5 - - f5 + f1 - -i- f7 - - f7 + f4 - - f4 - 1- f6 + f0 - - f0 -U3 - f3 + f6 - 1- f2 - -i- f4 + f3 - -i- f1 -U3a- f2 + */ + + for (LoopCnt = LoopN; LoopCnt > 0 ; LoopCnt--){ + t0r = *(fly0P); + t0i = *(fly0P + 1); + t1r = *(fly1P); + t1i = *(fly1P + 1); + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly1r = *(fly3P); + fly1i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly0r = *(fly1P + FlyOffsetA); + fly0i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly3r = *(fly3P + FlyOffsetA); + fly3i = *(fly3P + FlyOffsetAIm); + + fly5r = t0r - fly2r; + fly5i = t0i - fly2i; + t0r = t0r + fly2r; + t0i = t0i + fly2i; + + fly7r = t1r + fly1i; + fly7i = t1i - fly1r; + t1r = t1r - fly1i; + t1i = t1i + fly1r; + + fly2r = fly4r - fly6r; + fly2i = fly4i - fly6i; + fly4r = fly4r + fly6r; + fly4i = fly4i + fly6i; + + fly1r = fly0r + fly3i; + fly1i = fly0i - fly3r; + fly0r = fly0r - fly3i; + fly0i = fly0i + fly3r; + + fly6r = t0r - fly4r; + fly6i = t0i - fly4i; + t0r = t0r + fly4r; + t0i = t0i + fly4i; + + fly3r = fly5r + fly2i; + fly3i = fly5i - fly2r; + fly5r = fly5r - fly2i; + fly5i = fly5i + fly2r; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r + U3i * fly0i; + fly4i = t1i - U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly2r = fly7r + U3i * fly1r; + fly2r = fly2r + U3r * fly1i; + fly2i = fly7i - U3r * fly1r; + fly2i = fly2i + U3i * fly1i; + fly7r = scale * fly7r - fly2r; + fly7i = scale * fly7i - fly2i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P + FlyOffsetA) = fly3r; + *(fly2P + FlyOffsetAIm) = fly3i; + *(fly2P) = fly5r; + *(fly2P + 1) = fly5i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + *(fly3P + FlyOffsetA) = fly2r; + *(fly3P + FlyOffsetAIm) = fly2i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + + }; + + NsameU4 >>= 2; + LoopN >>= 2; + NdiffU <<= 2; + Flyinc = Flyinc << 2; + }; +}; + +NsameU2 = NsameU4 >> 1; +NsameU1 = NsameU2 >> 1; +Flyinc <<= 1; +FlyOffsetA = Flyinc << 2; +FlyOffsetB = FlyOffsetA << 1; +FlyOffsetAIm = FlyOffsetA + 1; +FlyOffsetBIm = FlyOffsetB + 1; +LoopN >>= 1; + +/* ****** RADIX 8 Stages */ +for (stage = stage<<1; stage > 0 ; stage--){ + + /* an fft stage is done in two parts to ease use of the single quadrant cos table */ + +/* fftcalc1(iobuf, Utbl, N, NdiffU, LoopN); */ + if(!(stage&1)){ + U0rP = &Utbl[0]; + U0iP = &Utbl[Ntbl[M-1]]; /* for RIFFT */ + U1rP = U0rP; + U1iP = U0iP; + U2rP = U0rP; + U2iP = U0iP; + U3offset = (Ntbl[M+1]) / 8; /* for RIFFT */ + + IOP = ioptr; + + U0r = *U0rP, + U0i = *U0iP; + U1r = *U1rP, + U1i = *U1iP; + U2r = *U2rP, + U2i = *U2iP; + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + } + + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + + for (diffUcnt = (NdiffU)>>1; diffUcnt > 0; diffUcnt--){ + + /* Butterflys */ + /* + f0 - - t0 - - t0 - - t0 + f1 -U0 - t1 - - t1 - - t1 + f2 - - f2 -U1 - f5 - - f3 + f3 -U0 - f1 -U1a- f7 - - f7 + f4 - - f4 - - f4 -U2 - f6 + f5 -U0 - f0 - - f0 -U3 - f4 + f6 - - f6 -U1 - f2 -U2a- f2 + f7 -U0 - f3 -U1a- f1 -U3a- f5 + */ + + fly0r = *(IOP); + fly0i = *(IOP+1); + fly1r = *(fly1P); + fly1i = *(fly1P+1); + + for (LoopCnt = LoopN-1; LoopCnt > 0 ; LoopCnt--){ + + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r + U0i * fly1i; + t1i = fly0i - U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r + U0i * fly3i; + fly1i = fly2i - U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r + U0i * fly5i; + fly0i = fly4i - U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r + U0i * fly7i; + fly3i = fly6i - U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r + U1i * fly2i; + fly5i = t0i - U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r + U1r * fly1i; + fly7i = t1i - U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r + U1i * fly6i; + fly2i = fly4i - U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r + U1r * fly3i; + fly1i = fly0i - U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r + U2i * fly4i; + fly6i = t0i - U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r - U2r * fly2i; + fly3i = fly5i + U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r + U3i * fly0i; + fly4i = t1i - U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r + U3r * fly1i; + fly5i = fly7i - U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + + fly0r = *(fly0P + FlyOffsetB); + fly0i = *(fly0P + FlyOffsetBIm); + + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + fly1r = *(fly1P + FlyOffsetB); + fly1i = *(fly1P + FlyOffsetBIm); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + fly0P = (fly0P + FlyOffsetB); + fly1P = (fly1P + FlyOffsetB); + fly2P = (fly2P + FlyOffsetB); + fly3P = (fly3P + FlyOffsetB); + + }; + fly2r = *(fly2P); + fly2i = *(fly2P + 1); + fly3r = *(fly3P); + fly3i = *(fly3P + 1); + fly4r = *(fly0P + FlyOffsetA); + fly4i = *(fly0P + FlyOffsetAIm); + fly5r = *(fly1P + FlyOffsetA); + fly5i = *(fly1P + FlyOffsetAIm); + fly6r = *(fly2P + FlyOffsetA); + fly6i = *(fly2P + FlyOffsetAIm); + fly7r = *(fly3P + FlyOffsetA); + fly7i = *(fly3P + FlyOffsetAIm); + + t1r = fly0r - U0r * fly1r; + t1r = t1r + U0i * fly1i; + t1i = fly0i - U0i * fly1r; + t1i = t1i - U0r * fly1i; + t0r = scale * fly0r - t1r; + t0i = scale * fly0i - t1i; + + fly1r = fly2r - U0r * fly3r; + fly1r = fly1r + U0i * fly3i; + fly1i = fly2i - U0i * fly3r; + fly1i = fly1i - U0r * fly3i; + fly2r = scale * fly2r - fly1r; + fly2i = scale * fly2i - fly1i; + + fly0r = fly4r - U0r * fly5r; + fly0r = fly0r + U0i * fly5i; + fly0i = fly4i - U0i * fly5r; + fly0i = fly0i - U0r * fly5i; + fly4r = scale * fly4r - fly0r; + fly4i = scale * fly4i - fly0i; + + fly3r = fly6r - U0r * fly7r; + fly3r = fly3r + U0i * fly7i; + fly3i = fly6i - U0i * fly7r; + fly3i = fly3i - U0r * fly7i; + fly6r = scale * fly6r - fly3r; + fly6i = scale * fly6i - fly3i; + + fly5r = t0r - U1r * fly2r; + fly5r = fly5r + U1i * fly2i; + fly5i = t0i - U1i * fly2r; + fly5i = fly5i - U1r * fly2i; + t0r = scale * t0r - fly5r; + t0i = scale * t0i - fly5i; + + fly7r = t1r + U1i * fly1r; + fly7r = fly7r + U1r * fly1i; + fly7i = t1i - U1r * fly1r; + fly7i = fly7i + U1i * fly1i; + t1r = scale * t1r - fly7r; + t1i = scale * t1i - fly7i; + + fly2r = fly4r - U1r * fly6r; + fly2r = fly2r + U1i * fly6i; + fly2i = fly4i - U1i * fly6r; + fly2i = fly2i - U1r * fly6i; + fly4r = scale * fly4r - fly2r; + fly4i = scale * fly4i - fly2i; + + fly1r = fly0r + U1i * fly3r; + fly1r = fly1r + U1r * fly3i; + fly1i = fly0i - U1r * fly3r; + fly1i = fly1i + U1i * fly3i; + fly0r = scale * fly0r - fly1r; + fly0i = scale * fly0i - fly1i; + + U0i = *(U0iP = (U0iP - NsameU4)); + U0r = *(U0rP = (U0rP + NsameU4)); + U1r = *(U1rP = (U1rP + NsameU2)); + U1i = *(U1iP = (U1iP - NsameU2)); + if(stage&1) + U0r = - U0r; + + fly6r = t0r - U2r * fly4r; + fly6r = fly6r + U2i * fly4i; + fly6i = t0i - U2i * fly4r; + fly6i = fly6i - U2r * fly4i; + t0r = scale * t0r - fly6r; + t0i = scale * t0i - fly6i; + + fly3r = fly5r - U2i * fly2r; + fly3r = fly3r - U2r * fly2i; + fly3i = fly5i + U2r * fly2r; + fly3i = fly3i - U2i * fly2i; + fly2r = scale * fly5r - fly3r; + fly2i = scale * fly5i - fly3i; + + fly4r = t1r - U3r * fly0r; + fly4r = fly4r + U3i * fly0i; + fly4i = t1i - U3i * fly0r; + fly4i = fly4i - U3r * fly0i; + t1r = scale * t1r - fly4r; + t1i = scale * t1i - fly4i; + + fly5r = fly7r + U3i * fly1r; + fly5r = fly5r + U3r * fly1i; + fly5i = fly7i - U3r * fly1r; + fly5i = fly5i + U3i * fly1i; + fly7r = scale * fly7r - fly5r; + fly7i = scale * fly7i - fly5i; + + *(fly0P + FlyOffsetA) = fly6r; + *(fly0P + FlyOffsetAIm) = fly6i; + *(fly0P) = t0r; + *(fly0P + 1) = t0i; + + U2r = *(U2rP = (U2rP + NsameU1)); + U2i = *(U2iP = (U2iP - NsameU1)); + + *(fly2P) = fly3r; + *(fly2P + 1) = fly3i; + *(fly2P + FlyOffsetA) = fly2r; + *(fly2P + FlyOffsetAIm) = fly2i; + *(fly1P + FlyOffsetA) = fly4r; + *(fly1P + FlyOffsetAIm) = fly4i; + *(fly1P) = t1r; + *(fly1P + 1) = t1i; + + U3r = *( U2rP + U3offset); + U3i = *( U2iP - U3offset); + + *(fly3P + FlyOffsetA) = fly5r; + *(fly3P + FlyOffsetAIm) = fly5i; + *(fly3P) = fly7r; + *(fly3P + 1) = fly7i; + + IOP = IOP + 2; + fly0P = IOP; + fly1P = (IOP+Flyinc); + fly2P = (fly1P+Flyinc); + fly3P = (fly2P+Flyinc); + }; + NsameU4 = -NsameU4; + + if(stage&1){ + LoopN >>= 3; + NsameU1 >>= 3; + NsameU2 >>= 3; + NsameU4 >>= 3; + NdiffU <<= 3; + Flyinc = Flyinc << 3; + FlyOffsetA <<= 3; + FlyOffsetB <<= 3; + FlyOffsetAIm = FlyOffsetA + 1; + FlyOffsetBIm = FlyOffsetB + 1; + } +} +M=M+1; /* for RIFFT */ + +ioptr += Ntbl[M]; +} +} diff --git a/sc4pd/source/fftlib.h b/sc4pd/source/fftlib.h new file mode 100644 index 0000000..b03317d --- /dev/null +++ b/sc4pd/source/fftlib.h @@ -0,0 +1,62 @@ +long FFTInit(long *fftMptr, long fftN, float *Utbl); +/* Compute cosine table and check size for complex ffts */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +long rFFTInit(long *fftMptr, long fftN, float *Utbl); +/* Compute cosine table and check size for a real input fft */ +/* INPUTS */ +/* fftN = size of fft */ +/* OUTPUTS */ +/* *fftMptr = log2 of fft size */ +/* *Utbl = cosine table with fftN/4 + 1 entries (angles = 0 to pi/2 inclusive) */ +/* RETURNS */ +/* 1 if fftN is invalid, 0 otherwise */ + +void ffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void iffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place inverse complex fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array */ + +void rffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place real fft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = real input data array */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = output data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ + + +void riffts(float *ioptr, long M, long Rows, float *Utbl); +/* Compute in-place real ifft on the rows of the input array */ +/* INPUTS */ +/* M = log2 of fft size */ +/* *ioptr = input data array in the following order */ +/* Re(x[0]), Re(x[N/2]), Re(x[1]), Im(x[1]), Re(x[2]), Im(x[2]), ... Re(x[N/2-1]), Im(x[N/2-1]). */ +/* *Utbl = cosine table */ +/* Rows = number of rows in ioptr array (use Rows of 1 if ioptr is a 1 dimensional array) */ +/* OUTPUTS */ +/* *ioptr = real output data array */ diff --git a/sc4pd/source/main.cpp b/sc4pd/source/main.cpp index 13fbc90..fa81e2e 100644 --- a/sc4pd/source/main.cpp +++ b/sc4pd/source/main.cpp @@ -1,3 +1,4 @@ + /* sc4pd library initialization @@ -68,7 +69,8 @@ void sc4pd_library_setup() "BRF~,\n" " LPZ1(~), HPZ1(~), LPZ2(~), HPZ2(~), BPZ2(~), BRZ2(~), " "LFDNoise0~,\n" - " LFDNoise1~, LFDNoise2~, sc+~, sc-~, sc*~, sc/~\n" + " LFDNoise1~, LFDNoise2~, sc+~, sc-~, sc*~, sc/~, " + "Convolution~\n" ); //initialize objects @@ -296,6 +298,11 @@ void sc4pd_library_setup() FLEXT_DSP_SETUP(scmul_ar); FLEXT_DSP_SETUP(scdiv_ar); + + FLEXT_DSP_SETUP(Convolution_ar); + + //init ffts + init_ffts(); } FLEXT_LIB_SETUP(sc4pd,sc4pd_library_setup); diff --git a/sc4pd/source/sc*.cpp b/sc4pd/source/sc*.cpp deleted file mode 100644 index 55ac074..0000000 --- a/sc4pd/source/sc*.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* sc4pd - sc*~ - - Copyright (c) 2004 Tim Blechmann. - - This code is derived from: - SuperCollider real time audio synthesis system - Copyright (c) 2002 James McCartney. All rights reserved. - http://www.audiosynth.com - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - Based on: - PureData by Miller Puckette and others. - http://www.crca.ucsd.edu/~msp/software.html - FLEXT by Thomas Grill - http://www.parasitaere-kapazitaeten.net/ext - SuperCollider by James McCartney - http://www.audiosynth.com - - Coded while listening to: Phil Minton & Veryan Weston: Ways - -*/ - -#include "sc4pd.hpp" - - -/* ------------------------ sc*~ -------------------------------*/ - -class scmul_ar: - public sc4pd_dsp -{ - FLEXT_HEADER(scmul_ar,sc4pd_dsp); - -public: - scmul_ar(int argc, t_atom *argv); - -protected: - virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); - - void m_set(float f) - { - m_nextfactor = f; - changed = true; - } - - float m_nextfactor, m_factor; - bool changed; - -private: - FLEXT_CALLBACK_1(m_set,float); -}; - -FLEXT_LIB_DSP_V("sc*~",scmul_ar); - -scmul_ar::scmul_ar(int argc, t_atom *argv) -{ - FLEXT_ADDMETHOD(1,m_set); - - //parse arguments - AtomList Args(argc,argv); - - m_factor = sc_getfloatarg(Args,0); - - AddInSignal("signal"); - AddInFloat("scalar"); - AddOutSignal(); - - changed = false; -} - -void scmul_ar::m_signal(int n, t_sample *const *in, - t_sample *const *out) -{ - t_sample *nin = *in; - t_sample *nout = *out; - - if (changed) - { - float xb = m_nextfactor; - float slope = CALCSLOPE(xb, m_factor); - for (int i = 0; i!=n; ++i) - { - ZXP(nout) = ZXP(nin) * xb; - xb += slope; - } - m_factor = xb; - changed = false; - } - else - { - float xb = m_factor; - - for (int i = 0; i!=n; ++i) - { - ZXP(nout) = ZXP(nin) * xb; - } - } -} - - diff --git a/sc4pd/source/scmul.cpp b/sc4pd/source/scmul.cpp new file mode 100644 index 0000000..55ac074 --- /dev/null +++ b/sc4pd/source/scmul.cpp @@ -0,0 +1,113 @@ +/* sc4pd + sc*~ + + Copyright (c) 2004 Tim Blechmann. + + This code is derived from: + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Based on: + PureData by Miller Puckette and others. + http://www.crca.ucsd.edu/~msp/software.html + FLEXT by Thomas Grill + http://www.parasitaere-kapazitaeten.net/ext + SuperCollider by James McCartney + http://www.audiosynth.com + + Coded while listening to: Phil Minton & Veryan Weston: Ways + +*/ + +#include "sc4pd.hpp" + + +/* ------------------------ sc*~ -------------------------------*/ + +class scmul_ar: + public sc4pd_dsp +{ + FLEXT_HEADER(scmul_ar,sc4pd_dsp); + +public: + scmul_ar(int argc, t_atom *argv); + +protected: + virtual void m_signal(int n, t_sample *const *in, t_sample *const *out); + + void m_set(float f) + { + m_nextfactor = f; + changed = true; + } + + float m_nextfactor, m_factor; + bool changed; + +private: + FLEXT_CALLBACK_1(m_set,float); +}; + +FLEXT_LIB_DSP_V("sc*~",scmul_ar); + +scmul_ar::scmul_ar(int argc, t_atom *argv) +{ + FLEXT_ADDMETHOD(1,m_set); + + //parse arguments + AtomList Args(argc,argv); + + m_factor = sc_getfloatarg(Args,0); + + AddInSignal("signal"); + AddInFloat("scalar"); + AddOutSignal(); + + changed = false; +} + +void scmul_ar::m_signal(int n, t_sample *const *in, + t_sample *const *out) +{ + t_sample *nin = *in; + t_sample *nout = *out; + + if (changed) + { + float xb = m_nextfactor; + float slope = CALCSLOPE(xb, m_factor); + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) * xb; + xb += slope; + } + m_factor = xb; + changed = false; + } + else + { + float xb = m_factor; + + for (int i = 0; i!=n; ++i) + { + ZXP(nout) = ZXP(nin) * xb; + } + } +} + + diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp index 077ea45..69aaf2b 100644 --- a/sc4pd/source/support.cpp +++ b/sc4pd/source/support.cpp @@ -108,3 +108,77 @@ int32 timeseed() return (int32)tsec ^ (int32)tusec ^ count--; } + +/* from Convolution.cpp */ +extern "C" +{ + float *cosTable[32]; + float *fftWindow[32]; +} + + +float* create_cosTable(int log2n) +{ + int size = 1 << log2n; + int size2 = size / 4 + 1; + float *win = (float*)malloc(size2 * sizeof(float)); + double winc = twopi / size; + for (int i=0; i Date: Tue, 21 Sep 2004 08:51:30 +0000 Subject: removed, since it's obsolete and causing licence problems ... svn path=/trunk/externals/tb/; revision=2053 --- sc4pd/headers/common/dlfcn.h | 44 -------------------------------------------- 1 file changed, 44 deletions(-) delete mode 100755 sc4pd/headers/common/dlfcn.h diff --git a/sc4pd/headers/common/dlfcn.h b/sc4pd/headers/common/dlfcn.h deleted file mode 100755 index 62966d0..0000000 --- a/sc4pd/headers/common/dlfcn.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.1 (the "License"). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#ifdef __cplusplus -extern "C" -{ -#endif - void * dlopen(const char *path, int mode); - void * dlsym(void * handle, const char *symbol); - const char * dlerror(void); - int dlclose(void * handle); -#ifdef __cplusplus -} -#endif - -#define RTLD_LAZY 0x1 -#define RTLD_NOW 0x2 -#define RTLD_LOCAL 0x4 -#define RTLD_GLOBAL 0x8 -#define RTLD_NOLOAD 0x10 -#define RTLD_SHARED 0x20 /* not used, the default */ -#define RTLD_UNSHARED 0x40 -#define RTLD_NODELETE 0x80 -#define RTLD_LAZY_UNDEF 0x100 -- cgit v1.2.1 From 5233c01a26329306c9f1d08c1a39733aee2cc518 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 21 Dec 2004 09:22:10 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2423, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=2424 --- chaos/AUTHORS | 3 + chaos/ChangeLog | 0 chaos/Makefile.am | 2 + chaos/NEWS | 0 chaos/README | 0 chaos/bootstrap.sh | 5 ++ chaos/configure.ac | 142 +++++++++++++++++++++++++++++ chaos/src/Makefile.am | 44 +++++++++ chaos/src/bernoulli_map.hpp | 75 ++++++++++++++++ chaos/src/bungalow_tent_map.hpp | 121 +++++++++++++++++++++++++ chaos/src/chaos.hpp | 35 ++++++++ chaos/src/chaos_base.cpp | 21 +++++ chaos/src/chaos_base.hpp | 55 ++++++++++++ chaos/src/chaos_dsp.cpp | 193 ++++++++++++++++++++++++++++++++++++++++ chaos/src/chaos_dsp.hpp | 61 +++++++++++++ chaos/src/circle_map.hpp | 106 ++++++++++++++++++++++ chaos/src/gauss_map.hpp | 77 ++++++++++++++++ chaos/src/henon_map.hpp | 121 +++++++++++++++++++++++++ chaos/src/ikeda_laser_map.hpp | 153 +++++++++++++++++++++++++++++++ chaos/src/logistic_map.hpp | 91 +++++++++++++++++++ chaos/src/lorenz.hpp | 150 +++++++++++++++++++++++++++++++ chaos/src/lozi_map.hpp | 126 ++++++++++++++++++++++++++ chaos/src/main.cpp | 29 ++++++ chaos/src/map_base.hpp | 40 +++++++++ chaos/src/ode_base.cpp | 90 +++++++++++++++++++ chaos/src/ode_base.hpp | 83 +++++++++++++++++ chaos/src/sine_map.hpp | 72 +++++++++++++++ chaos/src/standard_map.hpp | 130 +++++++++++++++++++++++++++ chaos/src/tent_map.hpp | 63 +++++++++++++ 29 files changed, 2088 insertions(+) create mode 100644 chaos/AUTHORS create mode 100644 chaos/ChangeLog create mode 100644 chaos/Makefile.am create mode 100644 chaos/NEWS create mode 100644 chaos/README create mode 100755 chaos/bootstrap.sh create mode 100644 chaos/configure.ac create mode 100644 chaos/src/Makefile.am create mode 100644 chaos/src/bernoulli_map.hpp create mode 100644 chaos/src/bungalow_tent_map.hpp create mode 100644 chaos/src/chaos.hpp create mode 100644 chaos/src/chaos_base.cpp create mode 100644 chaos/src/chaos_base.hpp create mode 100644 chaos/src/chaos_dsp.cpp create mode 100644 chaos/src/chaos_dsp.hpp create mode 100644 chaos/src/circle_map.hpp create mode 100644 chaos/src/gauss_map.hpp create mode 100644 chaos/src/henon_map.hpp create mode 100644 chaos/src/ikeda_laser_map.hpp create mode 100644 chaos/src/logistic_map.hpp create mode 100644 chaos/src/lorenz.hpp create mode 100644 chaos/src/lozi_map.hpp create mode 100644 chaos/src/main.cpp create mode 100644 chaos/src/map_base.hpp create mode 100644 chaos/src/ode_base.cpp create mode 100644 chaos/src/ode_base.hpp create mode 100644 chaos/src/sine_map.hpp create mode 100644 chaos/src/standard_map.hpp create mode 100644 chaos/src/tent_map.hpp diff --git a/chaos/AUTHORS b/chaos/AUTHORS new file mode 100644 index 0000000..022e6c0 --- /dev/null +++ b/chaos/AUTHORS @@ -0,0 +1,3 @@ +Tim Blechmann +Mike McGonagle +B. Bogart \ No newline at end of file diff --git a/chaos/ChangeLog b/chaos/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/chaos/Makefile.am b/chaos/Makefile.am new file mode 100644 index 0000000..5db2166 --- /dev/null +++ b/chaos/Makefile.am @@ -0,0 +1,2 @@ +SUBDIRS = src +EXTRA_DIST = src \ No newline at end of file diff --git a/chaos/NEWS b/chaos/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/chaos/README b/chaos/README new file mode 100644 index 0000000..e69de29 diff --git a/chaos/bootstrap.sh b/chaos/bootstrap.sh new file mode 100755 index 0000000..695f2bd --- /dev/null +++ b/chaos/bootstrap.sh @@ -0,0 +1,5 @@ +#! /bin/sh + +aclocal \ +&& automake-1.8 --gnu --add-missing \ +&& autoconf \ No newline at end of file diff --git a/chaos/configure.ac b/chaos/configure.ac new file mode 100644 index 0000000..c228f01 --- /dev/null +++ b/chaos/configure.ac @@ -0,0 +1,142 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(chaos~, 0.01, TimBlechmann@gmx.de, chaos~) +AM_INIT_AUTOMAKE + +dnl Checks for programs. +AC_PROG_MAKE_SET +AC_PROG_CC +AC_PROG_CXX + +dnl Checks for libraries. +AC_CHECK_LIB(m, sin) + +dnl Checks for header files. +AC_HEADER_STDC + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_C_INLINE +AC_TYPE_SIZE_T +AC_HEADER_TIME + + +dnl Checks for command line arguments +AC_ARG_WITH(flextdir, + [ --with-flextdir path to flext headers], + [ + flextdir=$withval + INCLUDEDIR="-I$withval $INCLUDEDIR" + ], + [echo "path to flext headers required" && exit 1]) + +AC_CHECK_FILE("$flextdir/flext.h",, + [echo "$flextdir/flext.h not found" && exit 1]) + + +AC_ARG_ENABLE(system, + [ --enable-system system (default: pd)], + [ + if test "enableval" == "max"; then + AC_DEFINE(FLEXT_SYS,1) + else + AC_DEFINE(FLEXT_SYS,2) + fi + system = $enabeval + ], + AC_DEFINE(FLEXT_SYS,2) + ) + + +AC_ARG_WITH(sysdir, + [ --with-sysdir path pd / max installation], + SYSDIR=$withval, + [echo "path to pd / max installation required" && exit 1]) + + +AC_ARG_ENABLE(static, + [ --enable-static static linking with libflext], + LDFLAGS="-Bstatic $LDFLAGS" + , + [ + AC_DEFINE(FLEXT_SHARED) + AC_DEFINE(FLEXT_THREADS) + LDFLAGS="-Bdynamic $LDFLAGS" + ] + ) + +AC_ARG_ENABLE(debug, + [ --enable-debug link with libflext_d library for debugging], + [ + LDFLAGS="-lflext_d $LDFLAGS" + CXXFLAGS="-g" + ], + [ + LDFLAGS="-lflext $LDFLAGS" + CXXFLAGS="-O3" + ]) + +dnl mtune will break gcc 3.3.x +AC_ARG_ENABLE(optimize, [ --enable-optimize enables optimized builds for: pentium4, pentium3, G4, G5], + [ + case $enableval in + pentium3 | pentium3m) + OPT_FLAGS = "-mtune=$enableval -march=$enableval -mmmx -msse -mfpmath=sse";; + pentium2 | athlon | pentium-mmx) + OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx";; + pentium) + OPT_FLAGS="-mtune=$enableval -march=$enableval";; + pentium4 | pentium4m | pentium-m | prescott | nocona | athlon-xp | athlon-mp | athlon64 | opteron) + OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx -msse -msse2 -mfpmath=sse";; + G5 | G4) + OPT_FLAGS="-mtune=$enableval -march=$enableval -maltivec -faltivec -malign-natural";; + G3) + OPT_FLAGS="-mtune=$enableval -march=$enableval -malign-natural";; + *) + ;; + esac + ]) + +dnl select build +if test `uname -s` == "Linux"; then + dnl no max/msp for linux + OBJEXT=o + EXTENSION=pd_linux +fi + +if test `uname -s` == "Darwin"; then + dnl just a guess + if test "$system" = "max"; then + echo "build system doesn't support max, yet" && exit 1; + else + LDFLAGS="-bundle -bundle_loader $LDFLAGS" + FRAMEWORKS= + EXTENSION=pd_darwin + LIBS="gcc $LIBS" + fi + OBJEXT=o +fi + +if test `uname -s` == "Cygwin"; then + dnl just a guess + if test "$system" = "max"; then + echo "build system doesn't support max, yet" && exit 1; + else + EXTENSION=dll + LIBS="gcc $LIBS bin/pd bin/pthreadVC.dll" + LDFLAGS="-L$SYSDIR" + fi +fi + + +AC_SUBST(EXTENSION) +AC_SUBST(INCLUDEDIR) +AC_SUBST(CXXFLAGS) +AC_SUBST(OPT_FLAGS) +AC_SUBST(LDFLAGS) +AC_SUBST(DEFS) +AC_SUBST(LIBS) +AC_SUBST(OBJEXT) +AC_SUBST(FRAMEWORKS) +AC_SUBST(SYSDIR) +AC_OUTPUT([Makefile + src/Makefile]) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am new file mode 100644 index 0000000..9f99c3f --- /dev/null +++ b/chaos/src/Makefile.am @@ -0,0 +1,44 @@ +NAME = chaos~ + +BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp + + +CXXFLAGS = @CXXFLAGS@ \ + @OPT_FLAGS@ \ + @INCLUDEDIR@ \ + $(DEFS) + +LDFLAGS = @LDFLAGS@ \ + $(patsubst %,-framework %,$(FRAMEWORKS)) + +LIBS = @LIBS@ + +FRAMEWORKS = @FRAMEWORKS@ + +TARGET =$(NAME).@EXTENSION@ + +OBJECTS = $(patsubst %.cpp,./%.@OBJEXT@,$(BUILT_SOURCES)) + +SYSDIR = @SYSDIR@ + + +# ----------------------------- targets -------------------------------- + + +all-local: $(OBJECTS) + $(CXX) $(LDFLAGS) -shared ./*.@OBJEXT@ $(LIBS) -o ../$(TARGET) + strip --strip-unneeded ../$(TARGET) + +./%.@OBJEXT@ : %.cpp + $(CXX) -c $(CXXFLAGS) $< -o $@ + +dist-hook: + rm -f ./*~ + rm -f ./*.@OBJEXT@ + +clean-local: + rm -f ../$(TARGET) + rm -f ../obj/* + +install-exec-local: + install ../$(TARGET) $(SYSDIR)extra \ No newline at end of file diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp new file mode 100644 index 0000000..b006c92 --- /dev/null +++ b/chaos/src/bernoulli_map.hpp @@ -0,0 +1,75 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// bernoulli map: x[n+1] = 2 * x[n] mod 1 +// 0 <= x[n] < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class bernoulli: + protected map_base +{ +public: + bernoulli() + { + m_num_eq = 1: + m_data = new data_t[1]; + set_x(0.5f); + } + + ~bernoulli() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + + if (x < 0.5f) + m_data[0] = 2.f * x; + else + m_data[0] = 2.f * x - 1.f; + } + + void set_x(t_float f) + { + if ( (f >= 0) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } +}; + + +#define BERNOULLI_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define BERNOULLI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp new file mode 100644 index 0000000..6708eae --- /dev/null +++ b/chaos/src/bungalow_tent_map.hpp @@ -0,0 +1,121 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// bungalow_tent map: x[n+1] = 1 + 2 * r + 2 * (r + 1) * x[n] +// (for -1 <= x[n] < -0.5f) +// 1 + 2 * (1 - r) * (x[n]) +// (for -0.5 <= x[n] < 0) +// 1 + 2 * (r - 1) * (x[n]) +// (for 0 <= x[n] < 0.5) +// 1 + 2 * r - 2 * (r + 1) * (x[n]) +// (for 0.5 <= x[n] < 1) +// -1 <= x[n] < 1 +// -0.5 <= r < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class bungalow_tent: + protected map_base +{ +public: + bungalow_tent() + : m_r(0.5) + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5f); + } + + ~bungalow_tent() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t r = m_r; + + if ( x < - 0.5) + { + m_data[0] = 1 + 2 * r + 2 * (r + 1) * x; + return; + } + if ( x < 0) + { + m_data[0] = 1 + 2 * (1 - r) * x; + return; + } + if ( x < 0.5) + { + m_data[0] = 1 + 2 * (r - 1) * x; + return; + } + else + { + m_data[0] = 1 + 2 * r - 2 * (r + 1) * x; + return; + } + + } + + void set_x(t_float f) + { + if ( (f > -1) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + void set_r(t_float f) + { + if ( (f > -.5) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for r %f out of range", f); + } + + t_float get_r() + { + return (t_float)m_data[0]; + } + +private: + data_t m_r; + +}; + + +#define BUNGALOW_TENT_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ + + +#define BUNGALOW_TENT_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp new file mode 100644 index 0000000..d65ba5c --- /dev/null +++ b/chaos/src/chaos.hpp @@ -0,0 +1,35 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef __chaos_hpp + +#define FLEXT_ATTRIBUTES 1 + +#include "flext.h" + +/* internal we can work with a higher precision than pd */ +#ifdef DOUBLE_PRECISION +typedef double data_t; +#else +typedef t_float data_t; +#endif + +#define __chaos_hpp +#endif /* __chaos_hpp */ diff --git a/chaos/src/chaos_base.cpp b/chaos/src/chaos_base.cpp new file mode 100644 index 0000000..9f8cad3 --- /dev/null +++ b/chaos/src/chaos_base.cpp @@ -0,0 +1,21 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp new file mode 100644 index 0000000..231580b --- /dev/null +++ b/chaos/src/chaos_base.hpp @@ -0,0 +1,55 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef __chaos_base_hpp + +#include "chaos.hpp" + +class chaos_base +{ + +public: + t_sample get_data(unsigned int i) + { + return (t_sample)m_data[i]; /* this is not save, but fast */ + } + + int get_num_eq() + { + return m_num_eq; + } + + /* prototype for system function */ + virtual void m_step(); + + data_t * m_data; // state of the system + +protected: + int m_num_eq; // number of equations of the system +}; + +#define CHAOS_CALLBACKS \ +FLEXT_CALLGET_F(m_system->get_num_eq); + +#define CHAOS_ATTRIBUTES \ +FLEXT_ADDATTR_GET("dimension",m_system->get_num_eq); + +#define __chaos_base_hpp +#endif /* __chaos_base_hpp */ diff --git a/chaos/src/chaos_dsp.cpp b/chaos/src/chaos_dsp.cpp new file mode 100644 index 0000000..790be06 --- /dev/null +++ b/chaos/src/chaos_dsp.cpp @@ -0,0 +1,193 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#include "chaos_dsp.hpp" + +void chaos_dsp::m_signal(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + if (m_freq >= m_sr * 0.5) + { + m_signal_(n, insigs, outsigs); + return; + } + + switch (m_method) + { + case 0: + m_signal_n(n, insigs, outsigs); + return; + case 1: + m_signal_l(n, insigs, outsigs); + return; + case 2: + m_signal_c(n, insigs, outsigs); + return; + } +} + +void chaos_dsp::m_signal_(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + for (int i = 0; i!=n; ++i) + { + m_system->m_step(); + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_system->get_data(j); + } + } + +} + +void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_system->get_data(j); + } + ++i; + } + } + m_phase = phase; +} + + +/* linear and cubic interpolation adapted from supercollider by James McCartney */ + +void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + + for (int j = 0; j != outlets; ++j) + m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; +} + + +void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + phase = (phase > 2) ? phase : 2; + + for (int j = 0; j != outlets; ++j) + { + t_sample value = m_nextvalues[j]; + m_nextvalues[j]= m_system->get_data(j); + + m_values[j] = m_nextmidpts[j]; + m_nextmidpts[j] = (m_values[j] + value) * 0.5f; + + float fseglen = (float)phase; + m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - fseglen * m_slopes[j]) + / (fseglen * fseglen + fseglen); + + m_values[j] = value; + } + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_slopes[j]+=m_curves[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; +} + + +void chaos_dsp::m_dsp(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + m_sr = Samplerate(); +} diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp new file mode 100644 index 0000000..12efaa8 --- /dev/null +++ b/chaos/src/chaos_dsp.hpp @@ -0,0 +1,61 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos_base.hpp" + +class chaos_dsp + : public flext_dsp +{ + FLEXT_HEADER(chaos_dsp, flext_dsp); + +protected: + + /* signal functions: */ + /* for frequency = sr/2 */ + void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* sample & hold */ + void m_signal_n(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* linear interpolation */ + void m_signal_l(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* cubic interpolatio */ + void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); + + virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs); + virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs); + + + /* local data for system, output and interpolation */ + chaos_base * m_system; /* the system */ + + t_sample * m_values; /* actual value */ + t_sample * m_slopes; /* actual slope for cubic interpolation */ + + t_sample * m_nextvalues; + t_sample * m_nextmidpts; + t_sample * m_curves; + + /* local data for signal functions */ + float m_freq; /* frequency of oscillations */ + int m_phase; /* phase counter */ + float m_sr; /* sample rate */ + + char m_method; /* interpolation method */ + +}; diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp new file mode 100644 index 0000000..f1ef406 --- /dev/null +++ b/chaos/src/circle_map.hpp @@ -0,0 +1,106 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// circle_map map: x[n+1] = x[n] * omega - r / (2*pi) * sin (2 * pi * x [n]) +// +// taken from Willi-Hans Steeb: Chaos and Fractals + +class circle_map: + protected map_base +{ +public: + circle_map() + : m_omega(0.4), m_r(1) + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~circle_map() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t omega = m_omega; + data_t r = m_r; + + m_data[0] = x + omega - r / (2.f * M_PI) * sin (2.f * M_PI * x); + } + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + void set_r(t_float f) + { + m_r = (data_t) f; + } + + + t_float get_r() + { + return (t_float)m_r; + } + + + void set_omega (t_float f) + { + m_omega = (data_t) f; + } + + t_float get_omega() + { + return (t_float)m_omega; + } + + +private: + data_t m_omega; + data_t m_r; +}; + +#define CIRCLE_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_ATTRVAR_F(m_system->m_omega); \ +FLEXT_ATTRVAR_F(m_system->m_r); \ +FLEXT_CALLVAR_F(m_system->get_omega, m_system->set_omega); \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define CIRCLE_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR1("omega",m_system->m_omega); \ +FLEXT_ADDATTR_VAR1("r",m_system->m_r); \ +FLEXT_ADDATTR_VAR("omega",m_system->get_omega, m_system->set_omega); \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp new file mode 100644 index 0000000..e2316ec --- /dev/null +++ b/chaos/src/gauss_map.hpp @@ -0,0 +1,77 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// gauss map: x[n+1] = 0 (for x[n] = 0) +// fmod(1 / x[n]) (else) +// 0 <= x[n] < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class gauss: + protected map_base +{ +public: + gauss() + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~gauss() + { + delete m_data; + } + + virtual void m_step() + { + data_t data = m_data[0]; + + if (data == 0) + m_data[0] = 0; + else + m_data[0] = fmod(1.f / data); + } + + void set_x(t_float f) + { + if ( (f >= 0) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + +}; + +#define GAUSS_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define GAUSS_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + + diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp new file mode 100644 index 0000000..d29e8a7 --- /dev/null +++ b/chaos/src/henon_map.hpp @@ -0,0 +1,121 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// henon map: x[n+1] = y[n] + 1 - a * x[n] * x[n] +// y[n+1] = b * x[n] +// b != 0 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class henon: + protected map_base +{ +public: + henon() + : m_a(1.4), m_b(0.3) + { + m_num_eq = 2; + m_data = new data_t[1]; + set_x(0.f); + set_y(0.f); + } + + ~henon() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + + m_data[0] = 1 + y - m_a * x * x; + m_data[1] = m_b * x; + + } + + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + + void set_y(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_y() + { + return (t_float)m_data[1]; + } + + + void set_a(t_float f) + { + m_a = (data_t) f; + } + + t_float get_a() + { + return (t_float)m_a; + } + + + void set_b(t_float f) + { + if (f != 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + +private: + data_t m_a; + data_t m_b; +}; + + +#define HENON_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ +FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); + +#define HENON_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ +FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ +FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp new file mode 100644 index 0000000..39d75c4 --- /dev/null +++ b/chaos/src/ikeda_laser_map.hpp @@ -0,0 +1,153 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// ikeda laser map: z[n+1] = roh + c2 * z[n] * +// exp (j * (c1 - c3 / (1 + abs(z) * abs(z)))) +// z is complex +// +// equal: x[n+1] = roh + c2 * (x[n] * cos(tau) - y[n] * sin (tau)) +// y[n+1] = c2 * (x[n] * sin(tau) + y[n] * cos(tau)) +// tau = c1 - (c2 / (1 + x*x + y*y)) +// +// taken from Willi-Hans Steeb: Chaos and Fractals + +class ikeda: + protected map_base +{ +public: + ikeda() + : m_c1(0.4), m_c2(0.9), m_c3(9), m_roh(0.85) + { + m_num_eq = 2; + m_data = new data_t[2]; + set_x(0.5); + set_y(0.5); + } + + ~ikeda() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + + data_t tau = m_c1 - m_c3 / (1 + x*x + y*y); + data_t cos_tau = cos(tau); + data_t sin_tau = sin(tau); + + m_data[0] = m_roh + m_c2 * (x * cos_tau - y * sin_tau); + m_data[1] = m_c2 * (x * sin_tau + y * cos_tau); + } + + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + void set_y(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_y() + { + return (t_float)m_data[1]; + } + + + void set_c1(t_float f) + { + m_c1 = (data_t) f; + } + + t_float get_c1() + { + return (t_float)m_c1; + } + + + void set_c2(t_float f) + { + m_c2[1] = (data_t) f; + } + + t_float get_c2() + { + return (t_float)m_c2; + } + + + void set_c3(t_float f) + { + m_c3 = (data_t) f; + } + + t_float get_c3() + { + return (t_float)m_c3; + } + + + void set_roh(t_float f) + { + m_roh = (data_t) f; + } + + t_float get_roh() + { + return (t_float)m_roh; + } + + +private: + data_t m_c1, m_c2, m_c3, m_roh; +}; + + +#define IKEDA_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_c1, m_system->set_c1); \ +FLEXT_CALLVAR_F(m_system->get_c2, m_system->set_c2); \ +FLEXT_CALLVAR_F(m_system->get_c3, m_system->set_c3); \ +FLEXT_CALLVAR_F(m_system->get_roh, m_system->set_roh); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ +FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); \ + + +#define IKEDA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("c1",m_system->get_c1, m_system->set_c1); \ +FLEXT_ADDATTR_VAR("c2",m_system->get_c2, m_system->set_c2); \ +FLEXT_ADDATTR_VAR("c3",m_system->get_c3, m_system->set_c3); \ +FLEXT_ADDATTR_VAR("roh",m_system->get_roh, m_system->set_roh); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ +FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp new file mode 100644 index 0000000..c443f45 --- /dev/null +++ b/chaos/src/logistic_map.hpp @@ -0,0 +1,91 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// logistic map: x[n+1] = alpha * x[n] * (1 - x[n]) +// 0 <= x[n] < 1 +// 0 <= alpha <= 4 + +class logistic: + protected map_base +{ +public: + logistic() + : m_alpha(3.8) + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5f); + } + + ~logistic() + { + delete m_data; + } + + virtual void m_step() + { + data_t data = m_data[0]; + data_t alpha = m_alpha; + m_data[0] = alpha * data * (1.f - data); + } + + void set_alpha(t_float f) + { + if ( (f > 0) && (f < 4)) + m_alpha = (data_t) f; + else + post("value for alpha %f out of range", f); + } + + t_float get_alpha() + { + return (t_float)m_alpha; + } + + void set_x(t_float f) + { + if ( (f > 0) && (f < 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + +private: + data_t m_alpha; +}; + +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_alpha, m_system->set_alpha); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("alpha",m_system->get_alpha, m_system->set_alpha); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + + diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp new file mode 100644 index 0000000..70dad4d --- /dev/null +++ b/chaos/src/lorenz.hpp @@ -0,0 +1,150 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// lorenz model: dx1/dt = sigma * (x2 - x1) +// dx2/dt = - x1 * x3 + r * x1 - x2 +// dx3/dt = x1 * x2 - b * x3 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class lorenz + : protected ode_base +{ +public: + logistic() + : m_sigma(16), m_b(4), m_r(40) + { + m_num_eq = 3; + m_data = new data_t[3]; + set_x1(0.8f); + set_x2(0.8f); + set_x3(0.8f); + set_method(0); + } + + ~logistic() + { + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0], x2 = data[1], x3 = data[2]; + + deriv[0] = m_sigma * (x2 - x1); + deriv[1] = - x1 * x3 + m_r * x1 - x2; + deriv[3] = x1 * x2 - m_b * x3; + } + + void set_x1(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x1() + { + return (t_float)m_data[0]; + } + + void set_x2(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_x2() + { + return (t_float)m_data[1]; + } + + void set_x3(t_float f) + { + m_data[2] = (data_t) f; + } + + t_float get_x3() + { + return (t_float)m_data[2]; + } + + + void set_sigma(t_float f) + { + if (f > 0) + m_sigma = (data_t) f; + else + post("value for sigma %f out of range", f); + } + + t_float get_sigma() + { + return (t_float)m_sigma; + } + + + void set_r(t_float f) + { + if (f > 0) + m_r = (data_t) f; + else + post("value for r %f out of range", f); + } + + t_float get_r() + { + return (t_float)m_r; + } + + void set_b(t_float f) + { + if (f > 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + + +private: + data_t m_sigma, m_r, m_b; +}; + + +#define LORENZ_CALLBACKS \ +ODE_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_sigma, m_system->set_sigma); \ +FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x1, m_system->set_x1); \ +FLEXT_CALLVAR_F(m_system->get_x2, m_system->set_x2); \ +FLEXT_CALLVAR_F(m_system->get_x3, m_system->set_x3); + +#define LORENZ_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("sigma",m_system->get_sigma, m_system->set_sigma); \ +FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ +FLEXT_ADDATTR_VAR("b",m_system->get_g, m_system->set_g); \ +FLEXT_ADDATTR_VAR("x1",m_system->get_x1, m_system->set_x1); \ +FLEXT_ADDATTR_VAR("x2",m_system->get_x2, m_system->set_x2); \ +FLEXT_ADDATTR_VAR("x3",m_system->get_x3, m_system->set_x3); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp new file mode 100644 index 0000000..50192c4 --- /dev/null +++ b/chaos/src/lozi_map.hpp @@ -0,0 +1,126 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// lozi map: x[n+1] = y[n] + 1 - a * abs(x[n]) +// y[n+1] = b * x[n] +// b != 0 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class lozi: + protected map_base +{ +public: + lozi() + : m_a(1.4), m_b(0.3) + { + m_num_eq = 2; + m_data = new data_t[1]; + set_x(0.5); + set_y(0.5); + } + + ~lozi() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + + if (x > 0) + m_data[0] = 1 + y - m_a * x; + else + m_data[0] = 1 + y + m_a * x; + + m_data[1] = m_b * x; + + } + + + void set_x(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + + + void set_y(t_float f) + { + m_data[1] = (data_t) f; + } + + t_float get_y() + { + return (t_float)m_data[1]; + } + + + void set_a(t_float f) + { + m_a = (data_t) f; + } + + t_float get_a() + { + return (t_float)m_a; + } + + + void set_b(t_float f) + { + if (f != 0) + m_b = (data_t) f; + else + post("value for b %f out of range", f); + } + + t_float get_b() + { + return (t_float)m_b; + } + + +private: + data_t m_a; + data_t m_b; +}; + + +#define LOZI_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ +FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ +FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); + +#define LOZI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ +FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ +FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp new file mode 100644 index 0000000..df25010 --- /dev/null +++ b/chaos/src/main.cpp @@ -0,0 +1,29 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos.hpp" +#include "logistic_map.hpp" + +void chaos_library_setup() +{ + post("chaos~ version"PACKAGE_VERSION"\n"); +} + +FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp new file mode 100644 index 0000000..35c8460 --- /dev/null +++ b/chaos/src/map_base.hpp @@ -0,0 +1,40 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#ifndef __map_base_hpp + +#include "chaos_base.hpp" + +class map_base + : protected chaos_base +{ + +}; + +#define MAP_CALLBACKS \ +CHAOS_CALLBACKS + + +#define MAP_ATTRIBUTES \ +CHAOS_ATTRIBUTES; + +#define __map_base_hpp +#endif /* __map_base_hpp */ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp new file mode 100644 index 0000000..cfedeee --- /dev/null +++ b/chaos/src/ode_base.cpp @@ -0,0 +1,90 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +void ode_base::rk1() +{ + m_system (m_k[0], m_data); + for (int i = 0; i != m_num_eq; ++i) + m_data[i] += m_dt * m_k[0][i]; +} + + +void ode_base::rk2() +{ + m_system (m_k[0], m_data); + for (int i = 0; i != m_num_eq; ++i) + m_k[0][i] = m_k[0][i] * 0.5 * m_dt + m_data[i]; + + m_system (m_k[1], m_k[0]); + for (int i = 0; i != m_num_eq; ++i) + m_data[i] += m_dt * m_k[1][i]; +} + + +void ode_base::rk4() +{ + m_system (m_k[0], m_data); + for (int i = 0; i != m_num_eq; ++i) + { + m_k[0][i] *= m_dt; + m_tmp[i] = m_data[i] + 0.5 * m_k[0][i]; + } + + m_system (m_k[1], m_tmp); + for (int i = 0; i != m_num_eq; ++i) + { + m_k[1][i] *= m_dt; + m_tmp[i] = m_data[i] + 0.5 * m_k[1][i]; + } + + m_system (m_k[2], m_tmp); + for (int i = 0; i != m_num_eq; ++i) + { + m_k[2][i] *= m_dt; + m_tmp[i] = m_data[i] + m_k[2][i]; + } + + m_system (m_k[3], m_tmp); + for (int i = 0; i != m_num_eq; ++i) + m_k[3][i] *= m_dt; + + for (int i = 0; i != m_num_eq; ++i) + m_data[i] += (m_k[0][i] + 2. * (m_k[1][i] + m_k[2][i]) + m_k[3][i]) + / 6.; +} + +void ode_base::m_step() +{ + switch (m_method) + { + case 0: + rk1(); + break; + case 1: + rk2(); + break; + case 2: + rk3(); + break; + } + +} diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp new file mode 100644 index 0000000..5fdd6d1 --- /dev/null +++ b/chaos/src/ode_base.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#ifndef __ode_base_hpp + +#include "chaos_base.hpp" + +class ode_base + : protected chaos_base +{ +public: + void set_method(int i) + { + if (i >=0 && i <4) + m_method = (unsigned char) i; + post("no such method"); + } + + t_int get_method() + { + return (int) m_method; + } + + void set_dt(t_float f) + { + if (f >= 0) + m_dt = (data_t)f; + else + post("invalid value for dt: %f", f); + } + + t_float get_dt() + { + return (t_float) m_dt; + } + + void m_step(); + +protected: + unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ + data_t m_dt; /* step width */ + + data_t* m_k[3]; /* temporary arrays for runge kutta */ + data_t* m_tmp; + + virtual void m_system (data_t* deriv, data_t* data); + + void rk1 (); + void rk2 (); + void rk4 (); +}; + +#define ODE_CALLBACKS \ +CHAOS_CALLBACKS; \ +FLEXT_CALLVAR_I(m_system->get_method, m_system->set_method); \ +FLEXT_CALLVAR_F(m_system->get_dt, m_system->set_dt); + +#define ODE_ATTRIBUTES \ +CHAOS_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("method", m_system->get_method, m_system->set_method); \ +FLEXT_ADDATTR_VAR("dt",m_system->get_dt, m_system->set_dt); + + +#define __ode_base_hpp +#endif /* __ode_base_hpp */ diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp new file mode 100644 index 0000000..dd62458 --- /dev/null +++ b/chaos/src/sine_map.hpp @@ -0,0 +1,72 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// sine map: x[n+1] = sin(pi * x) +// 0 <= x[n] <= 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class sine: + protected map_base +{ + +public: + sine() + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~sine() + { + delete m_data; + } + + virtual void m_step() + { + m_data[0] = sin (M_PI * m_data[0]); + } + + void set_x(t_float f) + { + if ( (f >= 0) && (f <= 1)) + m_data[0] = (data_t) f; + else + post("value for x %f out of range", f); + } + + t_float get_x() + { + return (t_float)m_data[0]; + } + +}; + +#define SINE_CALLBACKS \ +MAP_CALLBACKS \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define SINE_ATTRIBUTES \ +MAP_ATTRIBUTES \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp new file mode 100644 index 0000000..5f77af9 --- /dev/null +++ b/chaos/src/standard_map.hpp @@ -0,0 +1,130 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// standard map: I[n+1] = I[n] + k * sin(theta[n]) +// theta[n+1] = theta[n] + I[n] + k * sin(theta[n]) +// 0 <= theta <= 2*pi +// taken from Willi-Hans Steeb: Chaos and Fractals + +class standard: + protected map_base +{ +public: + standard() + : m_k(0.8) + { + m_num_eq = 2; + m_data = new data_t[2]; + set_I(0.1); + set_theta(0.2); + } + + ~standard() + { + delete m_data; + } + + virtual void m_step() + { + data_t I = m_data[0]; + data_t theta = m_data[1]; + + m_data[0] = I + m_k * sin(theta); + theta = theta + I + k * sin(theta); + + if (y > 2 * M_PI) + { + do + { + y -= 2*M_PI; + } + while (y > 2 * M_PI); + goto put_data; + } + + if (y < 0) + { + do + { + y += 2*M_PI; + } + while (y < 0); + } + + put_data: + m_data[1] = theta; + } + + + void set_I(t_float f) + { + m_data[0] = (data_t) f; + } + + t_float get_I() + { + return (t_float)m_data[0]; + } + + + void set_theta(t_float f) + { + if ( (f >= 0) && (f < 2*M_PI)) + m_data[1] = (data_t) f; + else + post("value for theta %f out of range", f); + } + + t_float get_theta() + { + return (t_float)m_data[1]; + } + + + void set_k(t_float f) + { + m_k = (data_t) f; + } + + t_float get_k() + { + return (t_float)m_k; + } + +private: + data_t m_k; +}; + + +#define STANDARD_CALLBACKS \ +MAP_CALLBACKS; \ +FLEXT_CALLVAR_F(m_system->get_I, m_system->set_I); \ +FLEXT_CALLVAR_F(m_system->get_theta, m_system->set_theta); \ +FLEXT_CALLVAR_F(m_system->get_k, m_system->set_k); + + +#define STANDARD_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +FLEXT_ADDATTR_VAR("I",m_system->get_I, m_system->set_I); \ +FLEXT_ADDATTR_VAR("theta",m_system->get_theta, m_system->set_theta); \ +FLEXT_ADDATTR_VAR("k",m_system->get_k, m_system->set_k); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp new file mode 100644 index 0000000..16de333 --- /dev/null +++ b/chaos/src/tent_map.hpp @@ -0,0 +1,63 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// tent map: x[n+1] = 2 * x[n] (for 0 < x <= 0.5) +// 2 * (1 - x[n]) (else) +// 0 <= x[n] < 1 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class tent: + protected map_base +{ +public: + tent() + { + m_num_eq = 1; + m_data = new data_t[1]; + set_x(0.5); + } + + ~tent() + { + delete m_data; + } + + virtual void m_step() + { + data_t data = m_data[0]; + + if (data < 0.5f) + m_data[0] = 2.f * data; + else + m_data[0] = 2.f * (1.f - data); + } +}; + + +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS \ +FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); + +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES \ +FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); + -- cgit v1.2.1 From 404bfef9e23dfc3166cb2005367e7e8a41863914 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 23 Dec 2004 10:07:17 +0000 Subject: base class macros svn path=/trunk/externals/tb/; revision=2426 --- chaos/src/bernoulli_map.hpp | 29 ++++----- chaos/src/bungalow_tent_map.hpp | 54 ++++++----------- chaos/src/chaos.hpp | 2 +- chaos/src/chaos_base.hpp | 92 +++++++++++++++++++++++++++- chaos/src/circle_map.hpp | 73 ++++++----------------- chaos/src/gauss_map.hpp | 29 ++++----- chaos/src/henon_map.hpp | 90 ++++++++-------------------- chaos/src/ikeda_laser_map.hpp | 126 +++++++++++---------------------------- chaos/src/logistic_map.hpp | 53 ++++++----------- chaos/src/lorenz.hpp | 129 +++++++++++----------------------------- chaos/src/lozi_map.hpp | 90 ++++++++-------------------- chaos/src/sine_map.hpp | 28 ++++----- chaos/src/standard_map.hpp | 68 +++++++-------------- chaos/src/tent_map.hpp | 21 ++++--- 14 files changed, 335 insertions(+), 549 deletions(-) diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index b006c92..50bca13 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -32,10 +32,10 @@ public: { m_num_eq = 1: m_data = new data_t[1]; - set_x(0.5f); + CHAOS_SYS_INIT(x,0.5) } - ~bernoulli() + ~Bernoulli() { delete m_data; } @@ -50,26 +50,19 @@ public: m_data[0] = 2.f * x - 1.f; } - void set_x(t_float f) + CHAOS_SYSVAR_FUNCS_PRED(x,0,m_pred_x); + bool m_pred_x(t_float f) { - if ( (f >= 0) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; + return (f >= 0) && (f < 1); } }; -#define BERNOULLI_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define BERNOULLI_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); -#define BERNOULLI_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define BERNOULLI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 6708eae..dfb6e25 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -37,11 +37,11 @@ class bungalow_tent: { public: bungalow_tent() - : m_r(0.5) { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5f); + CHAOS_SYS_INIT(x, 0.5); + CHAOS_SYS_INIT(r, 0.5); } ~bungalow_tent() @@ -52,7 +52,7 @@ public: virtual void m_step() { data_t x = m_data[0]; - data_t r = m_r; + data_t r = CHAOS_PARAMETER(r); if ( x < - 0.5) { @@ -77,45 +77,25 @@ public: } - void set_x(t_float f) + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) { - if ( (f > -1) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - void set_r(t_float f) - { - if ( (f > -.5) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for r %f out of range", f); + return (f >= -1) && (f < 1); } - t_float get_r() + CHAOS_SYSVAR_FUNCS_PRED(r, 0, m_pred_r); + bool m_pred_r(t_float f) { - return (t_float)m_data[0]; + return (f >= -0.5) && (f < 1); } - -private: - data_t m_r; - }; +#define BUNGALOW_TENT_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(r); -#define BUNGALOW_TENT_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ - - -#define BUNGALOW_TENT_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define BUNGALOW_TENT_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x) \ +CHAOS_SYS_ATTRIBUTE(r) diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index d65ba5c..4f51902 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -22,7 +22,7 @@ #define FLEXT_ATTRIBUTES 1 -#include "flext.h" +//#include "flext.h" /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 231580b..a42e275 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,4 +1,4 @@ -// +a// // // chaos~ // Copyright (C) 2004 Tim Blechmann @@ -36,7 +36,6 @@ public: return m_num_eq; } - /* prototype for system function */ virtual void m_step(); data_t * m_data; // state of the system @@ -51,5 +50,94 @@ FLEXT_CALLGET_F(m_system->get_num_eq); #define CHAOS_ATTRIBUTES \ FLEXT_ADDATTR_GET("dimension",m_system->get_num_eq); + + +// macros for simplified system state functions +#define CHAOS_SYS_SETFUNC(NAME, NR) \ + void set_##NAME(t_float f) \ + { \ + m_data[NR] = (data_t) f; \ + } + +#define CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ + void set_##NAME(t_float f) \ + { \ + if ( PRED(f) ) \ + m_data[NR] = (data_t) f; \ + else \ + post("value for dimension " #NAME " %f out of range", f); \ + } + +#define CHAOS_SYS_GETFUNC(NAME, NR) \ + t_float get_##NAME() \ + { \ + return (t_float)m_data[NR]; \ + } + +/* to be called in the public part */ +#define CHAOS_SYSVAR_FUNCS_PRED(NAME, NR, PRED) \ +public: \ +CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ +CHAOS_SYS_GETFUNC(NAME, NR) + +#define CHAOS_SYSVAR_FUNCS(NAME, NR) \ +public: \ +CHAOS_SYS_SETFUNC(NAME, NR) \ +CHAOS_SYS_GETFUNC(NAME, NR) + + + +// macros for simplified system parameter functions +#define CHAOS_PAR_SETFUNC(NAME) \ + void set_##NAME(t_float f) \ + { \ + m_##NAME = (data_t) f; \ + } + +#define CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ + void set_##NAME(t_float f) \ + { \ + if ( PRED(f) ) \ + m_##NAME = (data_t) f; \ + else \ + post("value for parameter " #NAME " %f out of range", f); \ + } + +#define CHAOS_PAR_GETFUNC(NAME) \ + t_float get_##NAME() \ + { \ + return (t_float)m_##NAME; \ + } + + +#define CHAOS_SYSPAR_FUNCS_PRED(NAME, PRED) \ +public: \ +CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ +CHAOS_PAR_GETFUNC(NAME) \ +private: \ +data_t m_##NAME; \ +public: + +#define CHAOS_SYSPAR_FUNCS(NAME) \ +public: \ +CHAOS_PAR_SETFUNC(NAME) \ +CHAOS_PAR_GETFUNC(NAME) \ +private: \ +data_t m_##NAME; \ +public: + + +#define CHAOS_SYS_CALLBACKS(NAME) \ +FLEXT_CALLVAR_F(m_system->get_##NAME, m_system->set_##NAME); + +#define CHAOS_SYS_ATTRIBUTE(NAME) \ +FLEXT_ADDATTR_VAR(#NAME,m_system->get_##NAME, m_system->set_##NAME); + +#define CHAOS_SYS_INIT(NAME, VALUE) \ +set_##NAME(VALUE); + +#define CHAOS_PARAMETER(NAME) m_##NAME + + #define __chaos_base_hpp #endif /* __chaos_base_hpp */ diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index f1ef406..02817de 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -29,11 +29,12 @@ class circle_map: { public: circle_map() - : m_omega(0.4), m_r(1) { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(omega, 0.4); + CHAOS_SYS_INIT(r, 1); + CHAOS_SYS_INIT(x, 0.5); } ~circle_map() @@ -44,63 +45,27 @@ public: virtual void m_step() { data_t x = m_data[0]; - data_t omega = m_omega; - data_t r = m_r; + data_t omega = CHAOS_PARAMETER(omega); + data_t r = CHAOS_PARAMETER(r); m_data[0] = x + omega - r / (2.f * M_PI) * sin (2.f * M_PI * x); } - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - void set_r(t_float f) - { - m_r = (data_t) f; - } - - - t_float get_r() - { - return (t_float)m_r; - } - - - void set_omega (t_float f) - { - m_omega = (data_t) f; - } - - t_float get_omega() - { - return (t_float)m_omega; - } - - -private: - data_t m_omega; - data_t m_r; + CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSPAR_FUNCS(r); + CHAOS_SYSPAR_FUNCS(omega); }; -#define CIRCLE_MAP_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_ATTRVAR_F(m_system->m_omega); \ -FLEXT_ATTRVAR_F(m_system->m_r); \ -FLEXT_CALLVAR_F(m_system->get_omega, m_system->set_omega); \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define CIRCLE_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(omega); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(x); + -#define CIRCLE_MAP_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR1("omega",m_system->m_omega); \ -FLEXT_ADDATTR_VAR1("r",m_system->m_r); \ -FLEXT_ADDATTR_VAR("omega",m_system->get_omega, m_system->set_omega); \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define CIRCLE_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(omega); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index e2316ec..537dcfb 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -33,7 +33,7 @@ public: { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(x,0.5); } ~gauss() @@ -51,27 +51,20 @@ public: m_data[0] = fmod(1.f / data); } - void set_x(t_float f) + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) { - if ( (f >= 0) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; + return (f >= 0) && (f < 1); } - }; -#define GAUSS_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define GAUSS_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); + +#define GAUSS_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); -#define GAUSS_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index d29e8a7..0aecbee 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -30,12 +30,14 @@ class henon: { public: henon() - : m_a(1.4), m_b(0.3) { m_num_eq = 2; m_data = new data_t[1]; - set_x(0.f); - set_y(0.f); + + CHAOS_SYS_INIT(x,0); + CHAOS_SYS_INIT(y,0); + CHAOS_SYS_INIT(a,1.4); + CHAOS_SYS_INIT(b,0.3); } ~henon() @@ -48,74 +50,34 @@ public: data_t x = m_data[0]; data_t y = m_data[1]; - m_data[0] = 1 + y - m_a * x * x; - m_data[1] = m_b * x; - + m_data[0] = 1 + y - CHAOS_PARAMETER(a) * x * x; + m_data[1] = CHAOS_PARAMETER(b) * x; } + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 1); - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - - void set_y(t_float f) - { - m_data[1] = (data_t) f; - } + CHAOS_SYSPAR_FUNCS(a); - t_float get_y() + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); + bool m_pred_b(t_float f) { - return (t_float)m_data[1]; + return (f != 0); } - - - void set_a(t_float f) - { - m_a = (data_t) f; - } - - t_float get_a() - { - return (t_float)m_a; - } - - - void set_b(t_float f) - { - if (f != 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - -private: - data_t m_a; - data_t m_b; }; -#define HENON_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ -FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); +#define HENON_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); + +#define HENON_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); -#define HENON_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ -FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ -FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 39d75c4..ccc14cc 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -36,12 +36,15 @@ class ikeda: { public: ikeda() - : m_c1(0.4), m_c2(0.9), m_c3(9), m_roh(0.85) { m_num_eq = 2; m_data = new data_t[2]; - set_x(0.5); - set_y(0.5); + CHAOS_SYS_INIT(c1,0.4); + CHAOS_SYS_INIT(c2,0.9); + CHAOS_SYS_INIT(c3,9); + CHAOS_SYS_INIT(roh,0.85); + CHAOS_SYS_INIT(x,0.5); + CHAOS_SYS_INIT(y,0.5); } ~ikeda() @@ -54,100 +57,41 @@ public: data_t x = m_data[0]; data_t y = m_data[1]; - data_t tau = m_c1 - m_c3 / (1 + x*x + y*y); + data_t tau = CHAOS_PARAMETER(c1) - + CHAOS_PARAMETER(c3) / (1 + x*x + y*y); data_t cos_tau = cos(tau); data_t sin_tau = sin(tau); - m_data[0] = m_roh + m_c2 * (x * cos_tau - y * sin_tau); - m_data[1] = m_c2 * (x * sin_tau + y * cos_tau); + m_data[0] = CHAOS_PARAMETER(roh) + CHAOS_PARAMETER(c2) + * (x * cos_tau - y * sin_tau); + m_data[1] = CHAOS_PARAMETER(c2) * (x * sin_tau + y * cos_tau); } - - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - void set_y(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_y() - { - return (t_float)m_data[1]; - } - - - void set_c1(t_float f) - { - m_c1 = (data_t) f; - } - - t_float get_c1() - { - return (t_float)m_c1; - } - - - void set_c2(t_float f) - { - m_c2[1] = (data_t) f; - } - - t_float get_c2() - { - return (t_float)m_c2; - } - - - void set_c3(t_float f) - { - m_c3 = (data_t) f; - } - - t_float get_c3() - { - return (t_float)m_c3; - } - - - void set_roh(t_float f) - { - m_roh = (data_t) f; - } - - t_float get_roh() - { - return (t_float)m_roh; - } - + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 1); -private: - data_t m_c1, m_c2, m_c3, m_roh; -}; + CHAOS_PAR_FUNCS(c1); + CHAOS_PAR_FUNCS(c2); + CHAOS_PAR_FUNCS(c3); + CHAOS_PAR_FUNCS(roh); - -#define IKEDA_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_c1, m_system->set_c1); \ -FLEXT_CALLVAR_F(m_system->get_c2, m_system->set_c2); \ -FLEXT_CALLVAR_F(m_system->get_c3, m_system->set_c3); \ -FLEXT_CALLVAR_F(m_system->get_roh, m_system->set_roh); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ -FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); \ +}; -#define IKEDA_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("c1",m_system->get_c1, m_system->set_c1); \ -FLEXT_ADDATTR_VAR("c2",m_system->get_c2, m_system->set_c2); \ -FLEXT_ADDATTR_VAR("c3",m_system->get_c3, m_system->set_c3); \ -FLEXT_ADDATTR_VAR("roh",m_system->get_roh, m_system->set_roh); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ -FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); +#define IKEDA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(c1); \ +CHAOS_SYS_CALLBACKS(c2); \ +CHAOS_SYS_CALLBACKS(c3); \ +CHAOS_SYS_CALLBACKS(roh); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); + +#define IKEDA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(c1); \ +CHAOS_SYS_ATTRIBUTE(c2); \ +CHAOS_SYS_ATTRIBUTE(c3); \ +CHAOS_SYS_ATTRIBUTE(roh); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index c443f45..e0111f7 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -29,11 +29,11 @@ class logistic: { public: logistic() - : m_alpha(3.8) { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5f); + CHAOS_SYS_INIT(alpha, 3.8); + CHAOS_SYS_INIT(x, 0.5); } ~logistic() @@ -44,48 +44,31 @@ public: virtual void m_step() { data_t data = m_data[0]; - data_t alpha = m_alpha; + data_t alpha = CHAOS_PARAMETER(alpha); m_data[0] = alpha * data * (1.f - data); } - void set_alpha(t_float f) + CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); + bool m_pred_alpha(t_float f) { - if ( (f > 0) && (f < 4)) - m_alpha = (data_t) f; - else - post("value for alpha %f out of range", f); + return (f > 0) && (f < 4); } - t_float get_alpha() + CHAOS_SYSVAR_FUNCS_PRED(x, m_pred_x); + + bool m_pred_x(t_float f) { - return (t_float)m_alpha; + return (f > 0) && (f < 1); } - - void set_x(t_float f) - { - if ( (f > 0) && (f < 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - -private: - data_t m_alpha; }; -#define LOGISTIC_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_alpha, m_system->set_alpha); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); - -#define LOGISTIC_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("alpha",m_system->get_alpha, m_system->set_alpha); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(x); +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index 70dad4d..e3e5ccd 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -30,13 +30,17 @@ class lorenz { public: logistic() - : m_sigma(16), m_b(4), m_r(40) { m_num_eq = 3; m_data = new data_t[3]; - set_x1(0.8f); - set_x2(0.8f); - set_x3(0.8f); + + CHAOS_SYS_INIT(x1,0.8); + CHAOS_SYS_INIT(x2,0.8); + CHAOS_SYS_INIT(x3,0.8); + CHAOS_SYS_INIT(sigma,16); + CHAOS_SYS_INIT(b,4); + CHAOS_SYS_INIT(r,40); + set_method(0); } @@ -49,102 +53,41 @@ public: { data_t x1 = data[0], x2 = data[1], x3 = data[2]; - deriv[0] = m_sigma * (x2 - x1); - deriv[1] = - x1 * x3 + m_r * x1 - x2; - deriv[3] = x1 * x2 - m_b * x3; - } - - void set_x1(t_float f) - { - m_data[0] = (data_t) f; + deriv[0] = CHAOS_PARAMETER(sigma) * (x2 - x1); + deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; + deriv[3] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } - t_float get_x1() - { - return (t_float)m_data[0]; - } - - void set_x2(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_x2() - { - return (t_float)m_data[1]; - } - - void set_x3(t_float f) - { - m_data[2] = (data_t) f; - } - - t_float get_x3() - { - return (t_float)m_data[2]; - } + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + CHAOS_SYSPAR_FUNCS_PRED(sigma, m_pred); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred); - void set_sigma(t_float f) + bool m_pred (t_float f) { - if (f > 0) - m_sigma = (data_t) f; - else - post("value for sigma %f out of range", f); + return (f > 0); } - t_float get_sigma() - { - return (t_float)m_sigma; - } - - - void set_r(t_float f) - { - if (f > 0) - m_r = (data_t) f; - else - post("value for r %f out of range", f); - } - - t_float get_r() - { - return (t_float)m_r; - } - - void set_b(t_float f) - { - if (f > 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - - -private: - data_t m_sigma, m_r, m_b; }; -#define LORENZ_CALLBACKS \ -ODE_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_sigma, m_system->set_sigma); \ -FLEXT_CALLVAR_F(m_system->get_r, m_system->set_r); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x1, m_system->set_x1); \ -FLEXT_CALLVAR_F(m_system->get_x2, m_system->set_x2); \ -FLEXT_CALLVAR_F(m_system->get_x3, m_system->set_x3); - -#define LORENZ_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("sigma",m_system->get_sigma, m_system->set_sigma); \ -FLEXT_ADDATTR_VAR("r",m_system->get_r, m_system->set_r); \ -FLEXT_ADDATTR_VAR("b",m_system->get_g, m_system->set_g); \ -FLEXT_ADDATTR_VAR("x1",m_system->get_x1, m_system->set_x1); \ -FLEXT_ADDATTR_VAR("x2",m_system->get_x2, m_system->set_x2); \ -FLEXT_ADDATTR_VAR("x3",m_system->get_x3, m_system->set_x3); +#define LORENZ_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); \ +CHAOS_SYS_CALLBACKS(sigma); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(b); + +#define LORENZ_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); \ +CHAOS_SYS_ATTRIBUTE(sigma); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(b); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 50192c4..8bee655 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -30,12 +30,13 @@ class lozi: { public: lozi() - : m_a(1.4), m_b(0.3) { m_num_eq = 2; m_data = new data_t[1]; - set_x(0.5); - set_y(0.5); + CHAOS_SYS_INIT(x,0); + CHAOS_SYS_INIT(y,0); + CHAOS_SYS_INIT(a,1.4); + CHAOS_SYS_INIT(b,0.3); } ~lozi() @@ -49,78 +50,37 @@ public: data_t y = m_data[1]; if (x > 0) - m_data[0] = 1 + y - m_a * x; + m_data[0] = 1 + y - CHAOS_PARAMETER(a) * x; else - m_data[0] = 1 + y + m_a * x; + m_data[0] = 1 + y + CHAOS_PARAMETER(a) * x; - m_data[1] = m_b * x; + m_data[1] = CHAOS_PARAMETER(b) * x; } + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 1); - void set_x(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_x() - { - return (t_float)m_data[0]; - } - - - void set_y(t_float f) - { - m_data[1] = (data_t) f; - } - - t_float get_y() - { - return (t_float)m_data[1]; - } - + CHAOS_SYSPAR_FUNCS(a); - void set_a(t_float f) + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); + bool m_pred_b(t_float f) { - m_a = (data_t) f; + return (f != 0); } - - t_float get_a() - { - return (t_float)m_a; - } - - - void set_b(t_float f) - { - if (f != 0) - m_b = (data_t) f; - else - post("value for b %f out of range", f); - } - - t_float get_b() - { - return (t_float)m_b; - } - - -private: - data_t m_a; - data_t m_b; }; -#define LOZI_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_a, m_system->set_a); \ -FLEXT_CALLVAR_F(m_system->get_b, m_system->set_b); \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); \ -FLEXT_CALLVAR_F(m_system->get_y, m_system->set_y); +#define LOZI_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); -#define LOZI_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("a",m_system->get_a, m_system->set_a); \ -FLEXT_ADDATTR_VAR("b",m_system->get_b, m_system->set_b); \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); \ -FLEXT_ADDATTR_VAR("y",m_system->get_y, m_system->set_y); +#define LOZI_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index dd62458..d083270 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -34,7 +34,7 @@ public: { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(x,0); } ~sine() @@ -47,26 +47,20 @@ public: m_data[0] = sin (M_PI * m_data[0]); } - void set_x(t_float f) - { - if ( (f >= 0) && (f <= 1)) - m_data[0] = (data_t) f; - else - post("value for x %f out of range", f); - } + CHAOS_SYSVAR_FUNCS_PRED(x, m_pred); - t_float get_x() + bool m_pred(t_float f) { - return (t_float)m_data[0]; + return (f >= 0) && (f <= 1); } - }; -#define SINE_CALLBACKS \ -MAP_CALLBACKS \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define SINE_CALLBACKS \ +MAP_CALLBACKS \ +CHAOS_SYS_CALLBACKS(x); + +#define SINE_ATTRIBUTES \ +MAP_ATTRIBUTES \ +CHAOS_SYS_ATTRIBUTE(x); -#define SINE_ATTRIBUTES \ -MAP_ATTRIBUTES \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 5f77af9..9515efe 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -31,12 +31,13 @@ class standard: { public: standard() - : m_k(0.8) { m_num_eq = 2; m_data = new data_t[2]; - set_I(0.1); - set_theta(0.2); + + CHAOS_SYS_INIT(I,0.1); + CHAOS_SYS_INIT(theta,0.2); + CHAOS_SYS_INIT(k, 0.8); } ~standard() @@ -48,8 +49,9 @@ public: { data_t I = m_data[0]; data_t theta = m_data[1]; + data_t k = CHAOS_PARAMETER(k); - m_data[0] = I + m_k * sin(theta); + m_data[0] = I + k * sin(theta); theta = theta + I + k * sin(theta); if (y > 2 * M_PI) @@ -76,55 +78,27 @@ public: } - void set_I(t_float f) - { - m_data[0] = (data_t) f; - } - - t_float get_I() - { - return (t_float)m_data[0]; - } - - - void set_theta(t_float f) - { - if ( (f >= 0) && (f < 2*M_PI)) - m_data[1] = (data_t) f; - else - post("value for theta %f out of range", f); - } - - t_float get_theta() - { - return (t_float)m_data[1]; - } - - - void set_k(t_float f) - { - m_k = (data_t) f; - } + CHAOS_SYSVAR_FUNCS(I, 0); - t_float get_k() + CHAOS_SYSVAR_FUNCS_PRED(theta, 1, m_pred_theta); + bool m_pred_theta(t_float f) { - return (t_float)m_k; + return (f >= 0) && (f < 2*M_PI); } -private: - data_t m_k; + CHAOS_SYSPAR_FUNCS(I, 1); }; -#define STANDARD_CALLBACKS \ -MAP_CALLBACKS; \ -FLEXT_CALLVAR_F(m_system->get_I, m_system->set_I); \ -FLEXT_CALLVAR_F(m_system->get_theta, m_system->set_theta); \ -FLEXT_CALLVAR_F(m_system->get_k, m_system->set_k); +#define STANDARD_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(I); \ +CHAOS_SYS_CALLBACKS(theta); \ +CHAOS_SYS_CALLBACKS(k); -#define STANDARD_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("I",m_system->get_I, m_system->set_I); \ -FLEXT_ADDATTR_VAR("theta",m_system->get_theta, m_system->set_theta); \ -FLEXT_ADDATTR_VAR("k",m_system->get_k, m_system->set_k); +#define STANDARD_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(I); \ +CHAOS_SYS_ATTRIBUTE(theta); \ +CHAOS_SYS_ATTRIBUTE(k); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 16de333..137599a 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -33,7 +33,7 @@ public: { m_num_eq = 1; m_data = new data_t[1]; - set_x(0.5); + CHAOS_SYS_INIT(x, 0.5); } ~tent() @@ -50,14 +50,21 @@ public: else m_data[0] = 2.f * (1.f - data); } + + CHAOS_SYSPAR_FUNCS_PRED(x, m_pred_x); + bool m_pred_x(t_float f) + { + return (f >= 0) && (f < 1); + } }; -#define LOGISTIC_CALLBACKS \ -MAP_CALLBACKS \ -FLEXT_CALLVAR_F(m_system->get_x, m_system->set_x); +#define LOGISTIC_CALLBACKS \ +MAP_CALLBACKS \ +CHAOS_SYS_CALLBACKS(x); + +#define LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES \ +CHAOS_SYS_ATTRIBUTE(x); -#define LOGISTIC_ATTRIBUTES \ -MAP_ATTRIBUTES \ -FLEXT_ADDATTR_VAR("x",m_system->get_x, m_system->set_x); -- cgit v1.2.1 From 45932d6b4b33ecd4f4dc2e7eab9f210dfa46cc34 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Dec 2004 15:31:14 +0000 Subject: xmas's changes svn path=/trunk/externals/tb/; revision=2427 --- chaos/src/Makefile.am | 13 +-- chaos/src/chaos.hpp | 3 +- chaos/src/chaos_base.hpp | 103 +++------------------ chaos/src/chaos_dsp.cpp | 171 ---------------------------------- chaos/src/chaos_dsp.hpp | 223 ++++++++++++++++++++++++++++++++++++++++++++- chaos/src/logistic_map.hpp | 2 +- chaos/src/lorenz.hpp | 8 +- chaos/src/main.cpp | 6 +- chaos/src/ode_base.cpp | 2 +- chaos/src/ode_base.hpp | 42 ++++----- 10 files changed, 269 insertions(+), 304 deletions(-) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 9f99c3f..43ad73b 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,6 +1,7 @@ -NAME = chaos~ +NAME = chaos -BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp +BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ + lorenz_dsp.cpp CXXFLAGS = @CXXFLAGS@ \ @@ -17,7 +18,7 @@ FRAMEWORKS = @FRAMEWORKS@ TARGET =$(NAME).@EXTENSION@ -OBJECTS = $(patsubst %.cpp,./%.@OBJEXT@,$(BUILT_SOURCES)) +OBJECTS = $(patsubst %.cpp,%.@OBJEXT@,$(BUILT_SOURCES)) SYSDIR = @SYSDIR@ @@ -26,10 +27,10 @@ SYSDIR = @SYSDIR@ all-local: $(OBJECTS) - $(CXX) $(LDFLAGS) -shared ./*.@OBJEXT@ $(LIBS) -o ../$(TARGET) + $(CXX) $(LDFLAGS) -shared $^ $(LIBS) -o ../$(TARGET) strip --strip-unneeded ../$(TARGET) -./%.@OBJEXT@ : %.cpp +%.@OBJEXT@ : %.cpp $(CXX) -c $(CXXFLAGS) $< -o $@ dist-hook: @@ -38,7 +39,7 @@ dist-hook: clean-local: rm -f ../$(TARGET) - rm -f ../obj/* + rm -f ./*.@OBJEXT@ install-exec-local: install ../$(TARGET) $(SYSDIR)extra \ No newline at end of file diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 4f51902..65a9c46 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -22,7 +22,7 @@ #define FLEXT_ATTRIBUTES 1 -//#include "flext.h" +#include "flext.h" /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION @@ -31,5 +31,6 @@ typedef double data_t; typedef t_float data_t; #endif + #define __chaos_hpp #endif /* __chaos_hpp */ diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index a42e275..795383e 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,4 +1,4 @@ -a// +// // // chaos~ // Copyright (C) 2004 Tim Blechmann @@ -21,6 +21,7 @@ a// #ifndef __chaos_base_hpp #include "chaos.hpp" +#include "chaos_defs.hpp" class chaos_base { @@ -36,7 +37,9 @@ public: return m_num_eq; } - virtual void m_step(); + virtual void m_step() + { + } data_t * m_data; // state of the system @@ -45,98 +48,16 @@ protected: }; #define CHAOS_CALLBACKS \ -FLEXT_CALLGET_F(m_system->get_num_eq); - -#define CHAOS_ATTRIBUTES \ -FLEXT_ADDATTR_GET("dimension",m_system->get_num_eq); - - - -// macros for simplified system state functions -#define CHAOS_SYS_SETFUNC(NAME, NR) \ - void set_##NAME(t_float f) \ - { \ - m_data[NR] = (data_t) f; \ - } - -#define CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ - void set_##NAME(t_float f) \ - { \ - if ( PRED(f) ) \ - m_data[NR] = (data_t) f; \ - else \ - post("value for dimension " #NAME " %f out of range", f); \ - } - -#define CHAOS_SYS_GETFUNC(NAME, NR) \ - t_float get_##NAME() \ - { \ - return (t_float)m_data[NR]; \ - } - -/* to be called in the public part */ -#define CHAOS_SYSVAR_FUNCS_PRED(NAME, NR, PRED) \ -public: \ -CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ -CHAOS_SYS_GETFUNC(NAME, NR) - -#define CHAOS_SYSVAR_FUNCS(NAME, NR) \ -public: \ -CHAOS_SYS_SETFUNC(NAME, NR) \ -CHAOS_SYS_GETFUNC(NAME, NR) - - - -// macros for simplified system parameter functions -#define CHAOS_PAR_SETFUNC(NAME) \ - void set_##NAME(t_float f) \ - { \ - m_##NAME = (data_t) f; \ - } - -#define CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ - void set_##NAME(t_float f) \ - { \ - if ( PRED(f) ) \ - m_##NAME = (data_t) f; \ - else \ - post("value for parameter " #NAME " %f out of range", f); \ - } - -#define CHAOS_PAR_GETFUNC(NAME) \ - t_float get_##NAME() \ - { \ - return (t_float)m_##NAME; \ - } - - -#define CHAOS_SYSPAR_FUNCS_PRED(NAME, PRED) \ -public: \ -CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ -CHAOS_PAR_GETFUNC(NAME) \ -private: \ -data_t m_##NAME; \ -public: - -#define CHAOS_SYSPAR_FUNCS(NAME) \ public: \ -CHAOS_PAR_SETFUNC(NAME) \ -CHAOS_PAR_GETFUNC(NAME) \ -private: \ -data_t m_##NAME; \ -public: - - -#define CHAOS_SYS_CALLBACKS(NAME) \ -FLEXT_CALLVAR_F(m_system->get_##NAME, m_system->set_##NAME); - -#define CHAOS_SYS_ATTRIBUTE(NAME) \ -FLEXT_ADDATTR_VAR(#NAME,m_system->get_##NAME, m_system->set_##NAME); +void get_dimension(int &i) \ +{ \ + i = m_system->get_num_eq(); \ +} \ +FLEXT_CALLGET_I(get_dimension); -#define CHAOS_SYS_INIT(NAME, VALUE) \ -set_##NAME(VALUE); +#define CHAOS_ATTRIBUTES \ +FLEXT_ADDATTR_GET("dimension",get_dimension); -#define CHAOS_PARAMETER(NAME) m_##NAME #define __chaos_base_hpp diff --git a/chaos/src/chaos_dsp.cpp b/chaos/src/chaos_dsp.cpp index 790be06..2040312 100644 --- a/chaos/src/chaos_dsp.cpp +++ b/chaos/src/chaos_dsp.cpp @@ -20,174 +20,3 @@ #include "chaos_dsp.hpp" - -void chaos_dsp::m_signal(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - if (m_freq >= m_sr * 0.5) - { - m_signal_(n, insigs, outsigs); - return; - } - - switch (m_method) - { - case 0: - m_signal_n(n, insigs, outsigs); - return; - case 1: - m_signal_l(n, insigs, outsigs); - return; - case 2: - m_signal_c(n, insigs, outsigs); - return; - } -} - -void chaos_dsp::m_signal_(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - int outlets = m_system->get_num_eq(); - - for (int i = 0; i!=n; ++i) - { - m_system->m_step(); - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_system->get_data(j); - } - } - -} - -void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - int outlets = m_system->get_num_eq(); - - int phase = m_phase; - - int i = 0; - - while (n) - { - if (m_phase == 0) - { - m_system->m_step(); - phase = int (m_sr / m_freq); - } - - int next = (phase < n) ? phase : n; - n -= next; - phase -=next; - - while (next--) - { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_system->get_data(j); - } - ++i; - } - } - m_phase = phase; -} - - -/* linear and cubic interpolation adapted from supercollider by James McCartney */ - -void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - int outlets = m_system->get_num_eq(); - - int phase = m_phase; - - int i = 0; - - while (n) - { - if (m_phase == 0) - { - m_system->m_step(); - phase = int (m_sr / m_freq); - - for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; - } - - int next = (phase < n) ? phase : n; - n -= next; - phase -=next; - - while (next--) - { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_values[j]; - m_values[j]+=m_slopes[j]; - } - ++i; - } - } - m_phase = phase; -} - - -void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - int outlets = m_system->get_num_eq(); - - int phase = m_phase; - - int i = 0; - - while (n) - { - if (m_phase == 0) - { - m_system->m_step(); - phase = int (m_sr / m_freq); - phase = (phase > 2) ? phase : 2; - - for (int j = 0; j != outlets; ++j) - { - t_sample value = m_nextvalues[j]; - m_nextvalues[j]= m_system->get_data(j); - - m_values[j] = m_nextmidpts[j]; - m_nextmidpts[j] = (m_values[j] + value) * 0.5f; - - float fseglen = (float)phase; - m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - fseglen * m_slopes[j]) - / (fseglen * fseglen + fseglen); - - m_values[j] = value; - } - } - - int next = (phase < n) ? phase : n; - n -= next; - phase -=next; - - while (next--) - { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_values[j]; - m_slopes[j]+=m_curves[j]; - m_values[j]+=m_slopes[j]; - } - ++i; - } - } - m_phase = phase; -} - - -void chaos_dsp::m_dsp(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - m_sr = Samplerate(); -} diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 12efaa8..65e6203 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -20,12 +20,12 @@ #include "chaos_base.hpp" -class chaos_dsp +template class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp); -protected: +public: /* signal functions: */ /* for frequency = sr/2 */ @@ -38,11 +38,15 @@ protected: void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs); - virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs); - + virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) + { + m_sr = Samplerate(); + } + + /* local data for system, output and interpolation */ - chaos_base * m_system; /* the system */ + system * m_system; /* the system */ t_sample * m_values; /* actual value */ t_sample * m_slopes; /* actual slope for cubic interpolation */ @@ -59,3 +63,212 @@ protected: char m_method; /* interpolation method */ }; + + +/* create constructor / destructor */ \ +#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ + \ +SYSTEM##_dsp(int argc, t_atom* argv ) \ +{ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + for (int i = 0; i != size; ++i) \ + AddOutSignal(); \ + \ + m_values = new t_float[size]; \ + m_slopes = new t_float[size]; \ + m_nextvalues = new t_float[size]; \ + m_nextmidpts = new t_float[size]; \ + m_curves = new t_float[size]; \ + \ + m_freq = GetAFloat(argv[0]); \ + m_method = (char)GetAFloat(argv[1]); \ + m_phase = 0; \ + \ + ATTRIBUTES; \ +} \ + \ +~SYSTEM##_dsp() \ +{ \ + delete m_system; \ + delete m_values; \ + delete m_slopes; \ + delete m_nextvalues; \ + delete m_nextmidpts; \ + delete m_curves; \ +} + + + + +template +void chaos_dsp::m_signal(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + if (m_freq >= m_sr * 0.5) + { + m_signal_(n, insigs, outsigs); + return; + } + + switch (m_method) + { + case 0: + m_signal_n(n, insigs, outsigs); + return; + case 1: + m_signal_l(n, insigs, outsigs); + return; + case 2: + m_signal_c(n, insigs, outsigs); + return; + } +} + +template +void chaos_dsp::m_signal_(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + for (int i = 0; i!=n; ++i) + { + m_system->m_step(); + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_system->get_data(j); + } + } + +} + +template +void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_system->get_data(j); + } + ++i; + } + } + m_phase = phase; +} + + +/* linear and cubic interpolation adapted from supercollider by James McCartney */ + +template +void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + + for (int j = 0; j != outlets; ++j) + m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; +} + + +template +void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + int phase = m_phase; + + int i = 0; + + while (n) + { + if (m_phase == 0) + { + m_system->m_step(); + phase = int (m_sr / m_freq); + phase = (phase > 2) ? phase : 2; + + for (int j = 0; j != outlets; ++j) + { + t_sample value = m_nextvalues[j]; + m_nextvalues[j]= m_system->get_data(j); + + m_values[j] = m_nextmidpts[j]; + m_nextmidpts[j] = (m_values[j] + value) * 0.5f; + + float fseglen = (float)phase; + m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - fseglen * m_slopes[j]) + / (fseglen * fseglen + fseglen); + + m_values[j] = value; + } + } + + int next = (phase < n) ? phase : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_slopes[j]+=m_curves[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; +} diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index e0111f7..94b38d0 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -54,7 +54,7 @@ public: return (f > 0) && (f < 4); } - CHAOS_SYSVAR_FUNCS_PRED(x, m_pred_x); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f) { diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index e3e5ccd..700e4a1 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -26,14 +26,16 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lorenz - : protected ode_base + : public ode_base { public: - logistic() + lorenz() { m_num_eq = 3; m_data = new data_t[3]; + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,1); CHAOS_SYS_INIT(x1,0.8); CHAOS_SYS_INIT(x2,0.8); CHAOS_SYS_INIT(x3,0.8); @@ -44,7 +46,7 @@ public: set_method(0); } - ~logistic() + ~lorenz() { delete m_data; } diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index df25010..b0f2ad0 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,9 @@ void chaos_library_setup() { - post("chaos~ version"PACKAGE_VERSION"\n"); + post("chaos~ version "PACKAGE_VERSION"\n"); + + FLEXT_DSP_SETUP(lorenz_dsp); } - + FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index cfedeee..9665d83 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -83,7 +83,7 @@ void ode_base::m_step() rk2(); break; case 2: - rk3(); + rk4(); break; } diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 5fdd6d1..6fa7e27 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -24,14 +24,15 @@ #include "chaos_base.hpp" class ode_base - : protected chaos_base + : public chaos_base { public: void set_method(int i) { if (i >=0 && i <4) m_method = (unsigned char) i; - post("no such method"); + else + post("no such method"); } t_int get_method() @@ -39,44 +40,39 @@ public: return (int) m_method; } - void set_dt(t_float f) - { - if (f >= 0) - m_dt = (data_t)f; - else - post("invalid value for dt: %f", f); - } - - t_float get_dt() + CHAOS_SYSPAR_FUNCS_PRED(dt, m_pred_dt); + + bool m_pred_dt(t_float f) { - return (t_float) m_dt; + return (f >= 0); } - void m_step(); + virtual void m_step(); protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ - data_t m_dt; /* step width */ data_t* m_k[3]; /* temporary arrays for runge kutta */ data_t* m_tmp; - virtual void m_system (data_t* deriv, data_t* data); + virtual void m_system (data_t* deriv, data_t* data) + { + } void rk1 (); void rk2 (); void rk4 (); }; -#define ODE_CALLBACKS \ -CHAOS_CALLBACKS; \ -FLEXT_CALLVAR_I(m_system->get_method, m_system->set_method); \ -FLEXT_CALLVAR_F(m_system->get_dt, m_system->set_dt); +#define ODE_CALLBACKS \ +CHAOS_CALLBACKS; \ +CHAOS_SYS_CALLBACKS_I(method); \ +CHAOS_SYS_CALLBACKS(dt); -#define ODE_ATTRIBUTES \ -CHAOS_ATTRIBUTES; \ -FLEXT_ADDATTR_VAR("method", m_system->get_method, m_system->set_method); \ -FLEXT_ADDATTR_VAR("dt",m_system->get_dt, m_system->set_dt); +#define ODE_ATTRIBUTES \ +CHAOS_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(method); \ +CHAOS_SYS_ATTRIBUTE(dt); #define __ode_base_hpp -- cgit v1.2.1 From 5c3670b6322b60b8bc5f60e22d891fe39b854e3e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Dec 2004 23:20:22 +0000 Subject: more changes ... getting stable ... svn path=/trunk/externals/tb/; revision=2428 --- chaos/configure.ac | 5 ++++- chaos/src/Makefile.am | 2 +- chaos/src/chaos_dsp.hpp | 25 +++++++++++++++---------- chaos/src/logistic_map.hpp | 2 +- chaos/src/lorenz.hpp | 5 ++++- chaos/src/main.cpp | 2 +- chaos/src/map_base.hpp | 2 +- chaos/src/ode_base.hpp | 22 ++++++++++++++++++++++ 8 files changed, 49 insertions(+), 16 deletions(-) diff --git a/chaos/configure.ac b/chaos/configure.ac index c228f01..67bf056 100644 --- a/chaos/configure.ac +++ b/chaos/configure.ac @@ -49,7 +49,10 @@ AC_ARG_ENABLE(system, AC_ARG_WITH(sysdir, [ --with-sysdir path pd / max installation], - SYSDIR=$withval, + [ + SYSDIR=$withval + INCLUDEDIR="-I$withval $INCLUDEDIR" + ], [echo "path to pd / max installation required" && exit 1]) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 43ad73b..efbb7f1 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,7 +1,7 @@ NAME = chaos BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ - lorenz_dsp.cpp + lorenz_dsp.cpp logistic_dsp.cpp CXXFLAGS = @CXXFLAGS@ \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 65e6203..c340b88 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -60,12 +60,12 @@ public: int m_phase; /* phase counter */ float m_sr; /* sample rate */ - char m_method; /* interpolation method */ + int m_method; /* interpolation method */ }; -/* create constructor / destructor */ \ +/* create constructor / destructor */ #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ \ @@ -87,7 +87,10 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ m_freq = GetAFloat(argv[0]); \ m_method = (char)GetAFloat(argv[1]); \ m_phase = 0; \ - \ + \ + FLEXT_ADDATTR_VAR1("frequency",m_freq); \ + FLEXT_ADDATTR_VAR1("method",m_method); \ + \ ATTRIBUTES; \ } \ \ @@ -99,21 +102,23 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ delete m_nextvalues; \ delete m_nextmidpts; \ delete m_curves; \ -} - +} \ + \ +FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_I(m_method); template void chaos_dsp::m_signal(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { if (m_freq >= m_sr * 0.5) { m_signal_(n, insigs, outsigs); return; } - + switch (m_method) { case 0: @@ -157,7 +162,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, while (n) { - if (m_phase == 0) + if (phase == 0) { m_system->m_step(); phase = int (m_sr / m_freq); @@ -194,7 +199,7 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, while (n) { - if (m_phase == 0) + if (phase == 0) { m_system->m_step(); phase = int (m_sr / m_freq); @@ -233,7 +238,7 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, while (n) { - if (m_phase == 0) + if (phase == 0) { m_system->m_step(); phase = int (m_sr / m_freq); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 94b38d0..e72a3a7 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -25,7 +25,7 @@ // 0 <= alpha <= 4 class logistic: - protected map_base + public map_base { public: logistic() diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index 700e4a1..fdae428 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -32,7 +32,7 @@ public: lorenz() { m_num_eq = 3; - m_data = new data_t[3]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(method,0); CHAOS_SYS_INIT(dt,1); @@ -43,11 +43,14 @@ public: CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(r,40); + ode_base_alloc(); + set_method(0); } ~lorenz() { + ode_base_free(); delete m_data; } diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index b0f2ad0..3a322f0 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -19,13 +19,13 @@ // Boston, MA 02111-1307, USA. #include "chaos.hpp" -#include "logistic_map.hpp" void chaos_library_setup() { post("chaos~ version "PACKAGE_VERSION"\n"); FLEXT_DSP_SETUP(lorenz_dsp); + FLEXT_DSP_SETUP(logistic_dsp); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 35c8460..c88f9ba 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -24,7 +24,7 @@ #include "chaos_base.hpp" class map_base - : protected chaos_base + : public chaos_base { }; diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 6fa7e27..cc526ae 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -49,6 +49,28 @@ public: virtual void m_step(); + void ode_base_alloc() + { + int dimension = get_num_eq(); + + for (int i = 0; i != 3; ++i) + { + m_k[i] = new data_t[dimension]; + } + + m_tmp = new data_t[dimension]; + } + + void ode_base_free() + { + for (int i = 0; i != 3; ++i) + { + delete m_k[i]; + } + + delete m_tmp; + } + protected: unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ -- cgit v1.2.1 From eced45909ba691a454fec179360ec1c2663f773a Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 25 Dec 2004 12:50:41 +0000 Subject: getting stable svn path=/trunk/externals/tb/; revision=2429 --- chaos/src/Makefile.am | 3 ++- chaos/src/chaos_dsp.hpp | 9 ++++----- chaos/src/lorenz.hpp | 8 ++++---- chaos/src/main.cpp | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index efbb7f1..e1018bd 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,7 +1,8 @@ NAME = chaos BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ - lorenz_dsp.cpp logistic_dsp.cpp + lorenz_dsp.cpp lorenz_msg.cpp \ + logistic_dsp.cpp logistic_msg.cpp CXXFLAGS = @CXXFLAGS@ \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index c340b88..f03f7c9 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -185,8 +185,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, } -/* linear and cubic interpolation adapted from supercollider by James McCartney */ - +/* linear interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -226,6 +225,7 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, } +/* linear interpolation adapted from Numerical Recipes In C */ template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -253,10 +253,9 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, m_nextmidpts[j] = (m_values[j] + value) * 0.5f; float fseglen = (float)phase; - m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - fseglen * m_slopes[j]) + m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - + fseglen * m_slopes[j]) / (fseglen * fseglen + fseglen); - - m_values[j] = value; } } diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index fdae428..a31c151 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -35,10 +35,10 @@ public: m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,1); + CHAOS_SYS_INIT(dt,0.01); CHAOS_SYS_INIT(x1,0.8); - CHAOS_SYS_INIT(x2,0.8); - CHAOS_SYS_INIT(x3,0.8); + CHAOS_SYS_INIT(x2,0.7); + CHAOS_SYS_INIT(x3,0.6); CHAOS_SYS_INIT(sigma,16); CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(r,40); @@ -60,7 +60,7 @@ public: deriv[0] = CHAOS_PARAMETER(sigma) * (x2 - x1); deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; - deriv[3] = x1 * x2 - CHAOS_PARAMETER(b) * x3; + deriv[2] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } CHAOS_SYSVAR_FUNCS(x1, 0); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 3a322f0..42dc16d 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -25,7 +25,10 @@ void chaos_library_setup() post("chaos~ version "PACKAGE_VERSION"\n"); FLEXT_DSP_SETUP(lorenz_dsp); + FLEXT_SETUP(lorenz_msg); + FLEXT_DSP_SETUP(logistic_dsp); + FLEXT_SETUP(logistic_msg); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); -- cgit v1.2.1 From b2f2fd990f9059db784a7849726c6fc5006c70f9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 27 Dec 2004 14:44:11 +0000 Subject: a lot of new objects ... svn path=/trunk/externals/tb/; revision=2431 --- chaos/src/Makefile.am | 14 +++- chaos/src/bernoulli_dsp.cpp | 34 ++++++++++ chaos/src/bernoulli_map.hpp | 11 +-- chaos/src/bernoulli_msg.cpp | 34 ++++++++++ chaos/src/bungalow_tent_dsp.cpp | 34 ++++++++++ chaos/src/bungalow_tent_map.hpp | 6 +- chaos/src/bungalow_tent_msg.cpp | 34 ++++++++++ chaos/src/chaos_defs.hpp | 137 ++++++++++++++++++++++++++++++++++++++ chaos/src/chaos_dsp.hpp | 21 ++++-- chaos/src/chaos_msg.hpp | 68 +++++++++++++++++++ chaos/src/circle_map.hpp | 12 ++-- chaos/src/circle_map_dsp.cpp | 34 ++++++++++ chaos/src/circle_map_msg.cpp | 34 ++++++++++ chaos/src/gauss_map.hpp | 20 +++--- chaos/src/gauss_map_dsp.cpp | 34 ++++++++++ chaos/src/gauss_map_msg.cpp | 34 ++++++++++ chaos/src/henon_map.hpp | 2 +- chaos/src/henon_map_dsp.cpp | 34 ++++++++++ chaos/src/henon_map_msg.cpp | 34 ++++++++++ chaos/src/ikeda_laser_map.hpp | 20 +++--- chaos/src/ikeda_laser_map_dsp.cpp | 34 ++++++++++ chaos/src/ikeda_laser_map_msg.cpp | 34 ++++++++++ chaos/src/logistic_dsp.cpp | 34 ++++++++++ chaos/src/logistic_msg.cpp | 34 ++++++++++ chaos/src/lorenz_dsp.cpp | 34 ++++++++++ chaos/src/lorenz_msg.cpp | 34 ++++++++++ chaos/src/lozi_map.hpp | 12 ++-- chaos/src/lozi_map_dsp.cpp | 34 ++++++++++ chaos/src/lozi_map_msg.cpp | 34 ++++++++++ chaos/src/main.cpp | 34 +++++++++- chaos/src/sine_map.hpp | 14 ++-- chaos/src/sine_map_dsp.cpp | 34 ++++++++++ chaos/src/sine_map_msg.cpp | 34 ++++++++++ chaos/src/standard_map.hpp | 26 ++++---- chaos/src/standard_map_dsp.cpp | 34 ++++++++++ chaos/src/standard_map_msg.cpp | 34 ++++++++++ chaos/src/tent_map.hpp | 14 ++-- chaos/src/tent_map_dsp.cpp | 34 ++++++++++ chaos/src/tent_map_msg.cpp | 34 ++++++++++ 39 files changed, 1152 insertions(+), 75 deletions(-) create mode 100644 chaos/src/bernoulli_dsp.cpp create mode 100644 chaos/src/bernoulli_msg.cpp create mode 100644 chaos/src/bungalow_tent_dsp.cpp create mode 100644 chaos/src/bungalow_tent_msg.cpp create mode 100644 chaos/src/chaos_defs.hpp create mode 100644 chaos/src/chaos_msg.hpp create mode 100644 chaos/src/circle_map_dsp.cpp create mode 100644 chaos/src/circle_map_msg.cpp create mode 100644 chaos/src/gauss_map_dsp.cpp create mode 100644 chaos/src/gauss_map_msg.cpp create mode 100644 chaos/src/henon_map_dsp.cpp create mode 100644 chaos/src/henon_map_msg.cpp create mode 100644 chaos/src/ikeda_laser_map_dsp.cpp create mode 100644 chaos/src/ikeda_laser_map_msg.cpp create mode 100644 chaos/src/logistic_dsp.cpp create mode 100644 chaos/src/logistic_msg.cpp create mode 100644 chaos/src/lorenz_dsp.cpp create mode 100644 chaos/src/lorenz_msg.cpp create mode 100644 chaos/src/lozi_map_dsp.cpp create mode 100644 chaos/src/lozi_map_msg.cpp create mode 100644 chaos/src/sine_map_dsp.cpp create mode 100644 chaos/src/sine_map_msg.cpp create mode 100644 chaos/src/standard_map_dsp.cpp create mode 100644 chaos/src/standard_map_msg.cpp create mode 100644 chaos/src/tent_map_dsp.cpp create mode 100644 chaos/src/tent_map_msg.cpp diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index e1018bd..a524de5 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,9 +1,18 @@ NAME = chaos BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ + bernoulli_dsp.cpp bernoulli_msg.cpp \ + bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ + circle_map_dsp.cpp circle_map_msg.cpp \ + gauss_map_dsp.cpp gauss_map_msg.cpp \ + henon_map_dsp.cpp henon_map_msg.cpp \ + ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ + logistic_dsp.cpp logistic_msg.cpp \ lorenz_dsp.cpp lorenz_msg.cpp \ - logistic_dsp.cpp logistic_msg.cpp - + lozi_map_dsp.cpp lozi_map_msg.cpp \ + sine_map_dsp.cpp sine_map_msg.cpp \ + standard_map_dsp.cpp standard_map_msg.cpp \ + tent_map_dsp.cpp tent_map_msg.cpp CXXFLAGS = @CXXFLAGS@ \ @OPT_FLAGS@ \ @@ -37,6 +46,7 @@ all-local: $(OBJECTS) dist-hook: rm -f ./*~ rm -f ./*.@OBJEXT@ + rm ./Makefile clean-local: rm -f ../$(TARGET) diff --git a/chaos/src/bernoulli_dsp.cpp b/chaos/src/bernoulli_dsp.cpp new file mode 100644 index 0000000..8e8d0da --- /dev/null +++ b/chaos/src/bernoulli_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bernoulli_map.hpp" +#include "chaos_dsp.hpp" + +class bernoulli_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(bernoulli, BERNOULLI_ATTRIBUTES); + + BERNOULLI_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("bernoulli~", bernoulli_dsp); diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 50bca13..25d19f8 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -25,17 +25,17 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bernoulli: - protected map_base + public map_base { public: bernoulli() { - m_num_eq = 1: + m_num_eq = 1; m_data = new data_t[1]; - CHAOS_SYS_INIT(x,0.5) + CHAOS_SYS_INIT(x,0.5); } - ~Bernoulli() + ~bernoulli() { delete m_data; } @@ -43,6 +43,9 @@ public: virtual void m_step() { data_t x = m_data[0]; + + if (x <= 0) + x = 0.00001; //stability if (x < 0.5f) m_data[0] = 2.f * x; diff --git a/chaos/src/bernoulli_msg.cpp b/chaos/src/bernoulli_msg.cpp new file mode 100644 index 0000000..8e07ed5 --- /dev/null +++ b/chaos/src/bernoulli_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bernoulli_map.hpp" +#include "chaos_msg.hpp" + +class bernoulli_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(bernoulli, BERNOULLI_ATTRIBUTES); + + BERNOULLI_CALLBACKS; +}; + + + +FLEXT_LIB_V("bernoulli", bernoulli_msg); diff --git a/chaos/src/bungalow_tent_dsp.cpp b/chaos/src/bungalow_tent_dsp.cpp new file mode 100644 index 0000000..33bef1c --- /dev/null +++ b/chaos/src/bungalow_tent_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bungalow_tent_map.hpp" +#include "chaos_dsp.hpp" + +class bungalow_tent_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); + + BUNGALOW_TENT_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("bungalow_tent~", bungalow_tent_dsp); diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index dfb6e25..185753a 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -33,14 +33,14 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bungalow_tent: - protected map_base + public map_base { public: bungalow_tent() { m_num_eq = 1; m_data = new data_t[1]; - CHAOS_SYS_INIT(x, 0.5); + CHAOS_SYS_INIT(x, 0.6); CHAOS_SYS_INIT(r, 0.5); } @@ -83,7 +83,7 @@ public: return (f >= -1) && (f < 1); } - CHAOS_SYSVAR_FUNCS_PRED(r, 0, m_pred_r); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); bool m_pred_r(t_float f) { return (f >= -0.5) && (f < 1); diff --git a/chaos/src/bungalow_tent_msg.cpp b/chaos/src/bungalow_tent_msg.cpp new file mode 100644 index 0000000..8c6b1be --- /dev/null +++ b/chaos/src/bungalow_tent_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bungalow_tent_map.hpp" +#include "chaos_msg.hpp" + +class bungalow_tent_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); + + BUNGALOW_TENT_CALLBACKS; +}; + + + +FLEXT_LIB_V("bungalow_tent", bungalow_tent_msg); diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp new file mode 100644 index 0000000..ae86223 --- /dev/null +++ b/chaos/src/chaos_defs.hpp @@ -0,0 +1,137 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#ifndef __chaos_defs_hpp + + +// macros for simplified system state functions +#define CHAOS_SYS_SETFUNC(NAME, NR) \ + void set_##NAME(t_float f) \ + { \ + m_data[NR] = (data_t) f; \ + } + +#define CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ + void set_##NAME(t_float f) \ + { \ + if ( PRED(f) ) \ + m_data[NR] = (data_t) f; \ + else \ + post("value for dimension " #NAME " %f out of range", f); \ + } + +#define CHAOS_SYS_GETFUNC(NAME, NR) \ + t_float get_##NAME() \ + { \ + return (t_float)m_data[NR]; \ + } + +/* to be called in the public part */ +#define CHAOS_SYSVAR_FUNCS_PRED(NAME, NR, PRED) \ +CHAOS_SYS_SETFUNC_PRED(NAME, NR, PRED) \ +CHAOS_SYS_GETFUNC(NAME, NR) + +#define CHAOS_SYSVAR_FUNCS(NAME, NR) \ +CHAOS_SYS_SETFUNC(NAME, NR) \ +CHAOS_SYS_GETFUNC(NAME, NR) + + + +// macros for simplified system parameter functions +#define CHAOS_PAR_SETFUNC(NAME) \ + void set_##NAME(t_float f) \ + { \ + m_##NAME = (data_t) f; \ + } + +#define CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ + void set_##NAME(t_float f) \ + { \ + if ( PRED(f) ) \ + m_##NAME = (data_t) f; \ + else \ + post("value for parameter " #NAME " %f out of range", f); \ + } + +#define CHAOS_PAR_GETFUNC(NAME) \ + t_float get_##NAME() \ + { \ + return (t_float)m_##NAME; \ + } + + +#define CHAOS_SYSPAR_FUNCS_PRED(NAME, PRED) \ +CHAOS_PAR_SETFUNC_PRED(NAME, PRED) \ +CHAOS_PAR_GETFUNC(NAME) \ +data_t m_##NAME; + + +#define CHAOS_SYSPAR_FUNCS(NAME) \ +public: \ +CHAOS_PAR_SETFUNC(NAME) \ +CHAOS_PAR_GETFUNC(NAME) \ +data_t m_##NAME; + + +#define CHAOS_SYSPAR_FUNCS_I(NAME) \ +CHAOS_PAR_SETFUNC(NAME) \ +CHAOS_PAR_GETFUNC(NAME) \ +data_t m_##NAME; + + +#define CHAOS_SYS_CALLBACKS(NAME) \ +public:void get_##NAME(t_float &f) \ +{ \ + f = m_system->get_##NAME(); \ +} \ +void set_##NAME(t_float &f) \ +{ \ + m_system->set_##NAME(f); \ +} \ +FLEXT_CALLVAR_F(get_##NAME, set_##NAME); + +#define CHAOS_SYS_CALLBACKS_I(NAME) \ +public: \ +void get_##NAME(int &i) \ +{ \ + i = m_system->get_##NAME(); \ +} \ +void set_##NAME(int &i) \ +{ \ + m_system->set_##NAME(i); \ +} \ +FLEXT_CALLVAR_I(get_##NAME, set_##NAME); + + +#define CHAOS_SYS_ATTRIBUTE(NAME) \ +FLEXT_ADDATTR_VAR(#NAME,get_##NAME, set_##NAME); + +#define CHAOS_SYS_INIT(NAME, VALUE) \ +set_##NAME(VALUE); + +#define CHAOS_PARAMETER(NAME) m_##NAME + + + + + + +#define __chaos_defs_hpp +#endif /* __chaos_defs_hpp */ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index f03f7c9..1eff6fc 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -75,15 +75,25 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ \ int size = m_system->get_num_eq(); \ \ - for (int i = 0; i != size; ++i) \ - AddOutSignal(); \ - \ m_values = new t_float[size]; \ m_slopes = new t_float[size]; \ m_nextvalues = new t_float[size]; \ m_nextmidpts = new t_float[size]; \ m_curves = new t_float[size]; \ \ + /* create inlets and zero arrays*/ \ + for (int i = 0; i != size; ++i) \ + { \ + AddOutSignal(); \ + m_values[i] = 0; \ + m_slopes[i] = 0; \ + m_nextvalues[i] = 0; \ + m_nextmidpts[i] = 0; \ + m_curves[i] = 0; \ + } \ + \ + \ + \ m_freq = GetAFloat(argv[0]); \ m_method = (char)GetAFloat(argv[1]); \ m_phase = 0; \ @@ -185,7 +195,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, } -/* linear interpolation adapted from supercollider by James McCartney */ +/* linear and cubic interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -225,7 +235,6 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, } -/* linear interpolation adapted from Numerical Recipes In C */ template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -250,7 +259,7 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, m_nextvalues[j]= m_system->get_data(j); m_values[j] = m_nextmidpts[j]; - m_nextmidpts[j] = (m_values[j] + value) * 0.5f; + m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; float fseglen = (float)phase; m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp new file mode 100644 index 0000000..78bca06 --- /dev/null +++ b/chaos/src/chaos_msg.hpp @@ -0,0 +1,68 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos_base.hpp" + +template class chaos_msg + : public flext_base +{ + FLEXT_HEADER(chaos_msg, flext_base); + +public: + + /* local data for system, output and interpolation */ + system * m_system; /* the system */ + + void m_bang() + { + m_system->m_step(); + int outlets = m_system->get_num_eq(); + + while (outlets--) + { + ToOutFloat(outlets, m_system->get_data(outlets)); + } + } + + FLEXT_CALLBACK(m_bang); +}; + + +/* create constructor / destructor */ +#define CHAOS_MSG_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_msg, chaos_msg) \ + \ +SYSTEM##_msg(int argc, t_atom* argv ) \ +{ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + for (int i = 0; i != size; ++i) \ + AddOutFloat(); \ + \ + ATTRIBUTES; \ + FLEXT_ADDBANG(0, m_bang); \ +} \ + \ +~SYSTEM##_msg() \ +{ \ + delete m_system; \ +} diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 02817de..0e12ad0 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -20,21 +20,23 @@ #include "map_base.hpp" -// circle_map map: x[n+1] = x[n] * omega - r / (2*pi) * sin (2 * pi * x [n]) +#include + +// circle_map map: x[n+1] = x[n] + omega - r / (2*pi) * sin (2 * pi * x [n]) // // taken from Willi-Hans Steeb: Chaos and Fractals class circle_map: - protected map_base + public map_base { public: circle_map() { m_num_eq = 1; m_data = new data_t[1]; - CHAOS_SYS_INIT(omega, 0.4); - CHAOS_SYS_INIT(r, 1); - CHAOS_SYS_INIT(x, 0.5); + CHAOS_SYS_INIT(omega, 0.1); + CHAOS_SYS_INIT(r, 3); + CHAOS_SYS_INIT(x, 0.4); } ~circle_map() diff --git a/chaos/src/circle_map_dsp.cpp b/chaos/src/circle_map_dsp.cpp new file mode 100644 index 0000000..fbd7c9d --- /dev/null +++ b/chaos/src/circle_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "circle_map.hpp" +#include "chaos_dsp.hpp" + +class circle_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); + + CIRCLE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("circle_map~", circle_map_dsp); diff --git a/chaos/src/circle_map_msg.cpp b/chaos/src/circle_map_msg.cpp new file mode 100644 index 0000000..3e771b3 --- /dev/null +++ b/chaos/src/circle_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "circle_map.hpp" +#include "chaos_msg.hpp" + +class circle_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); + + CIRCLE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("circle_map", circle_map_msg); diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 537dcfb..523b1ca 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -20,23 +20,25 @@ #include "map_base.hpp" +#include + // gauss map: x[n+1] = 0 (for x[n] = 0) -// fmod(1 / x[n]) (else) +// fmod(1 / x[n], 1) (else) // 0 <= x[n] < 1 // taken from Willi-Hans Steeb: Chaos and Fractals -class gauss: - protected map_base +class gauss_map: + public map_base { public: - gauss() + gauss_map() { m_num_eq = 1; m_data = new data_t[1]; CHAOS_SYS_INIT(x,0.5); } - ~gauss() + ~gauss_map() { delete m_data; } @@ -46,9 +48,9 @@ public: data_t data = m_data[0]; if (data == 0) - m_data[0] = 0; + m_data[0] = 0.001; else - m_data[0] = fmod(1.f / data); + m_data[0] = fmod(1.f / data, 1); } CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); @@ -58,11 +60,11 @@ public: } }; -#define GAUSS_CALLBACKS \ +#define GAUSS_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(x); -#define GAUSS_ATTRIBUTES \ +#define GAUSS_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/gauss_map_dsp.cpp b/chaos/src/gauss_map_dsp.cpp new file mode 100644 index 0000000..70e659d --- /dev/null +++ b/chaos/src/gauss_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gauss_map.hpp" +#include "chaos_dsp.hpp" + +class gauss_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); + + GAUSS_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("gauss_map~", gauss_map_dsp); diff --git a/chaos/src/gauss_map_msg.cpp b/chaos/src/gauss_map_msg.cpp new file mode 100644 index 0000000..61e0379 --- /dev/null +++ b/chaos/src/gauss_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gauss_map.hpp" +#include "chaos_msg.hpp" + +class gauss_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); + + GAUSS_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("gauss_map", gauss_map_msg); diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 0aecbee..9e379ae 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -26,7 +26,7 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class henon: - protected map_base + public map_base { public: henon() diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp new file mode 100644 index 0000000..f28e83f --- /dev/null +++ b/chaos/src/henon_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "henon_map.hpp" +#include "chaos_dsp.hpp" + +class henon_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(henon, HENON_ATTRIBUTES); + + HENON_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("henon~", henon_dsp); diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp new file mode 100644 index 0000000..10849fd --- /dev/null +++ b/chaos/src/henon_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "henon_map.hpp" +#include "chaos_msg.hpp" + +class henon_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(henon, HENON_ATTRIBUTES); + + HENON_CALLBACKS; +}; + + + +FLEXT_LIB_V("henon", henon_msg); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index ccc14cc..e267204 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -31,11 +31,11 @@ // // taken from Willi-Hans Steeb: Chaos and Fractals -class ikeda: - protected map_base +class ikeda_laser_map: + public map_base { public: - ikeda() + ikeda_laser_map() { m_num_eq = 2; m_data = new data_t[2]; @@ -47,7 +47,7 @@ public: CHAOS_SYS_INIT(y,0.5); } - ~ikeda() + ~ikeda_laser_map() { delete m_data; } @@ -70,15 +70,15 @@ public: CHAOS_SYSVAR_FUNCS(x, 0); CHAOS_SYSVAR_FUNCS(y, 1); - CHAOS_PAR_FUNCS(c1); - CHAOS_PAR_FUNCS(c2); - CHAOS_PAR_FUNCS(c3); - CHAOS_PAR_FUNCS(roh); + CHAOS_SYSPAR_FUNCS(c1); + CHAOS_SYSPAR_FUNCS(c2); + CHAOS_SYSPAR_FUNCS(c3); + CHAOS_SYSPAR_FUNCS(roh); }; -#define IKEDA_CALLBACKS \ +#define IKEDA_LASER_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(c1); \ CHAOS_SYS_CALLBACKS(c2); \ @@ -87,7 +87,7 @@ CHAOS_SYS_CALLBACKS(roh); \ CHAOS_SYS_CALLBACKS(x); \ CHAOS_SYS_CALLBACKS(y); -#define IKEDA_ATTRIBUTES \ +#define IKEDA_LASER_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(c1); \ CHAOS_SYS_ATTRIBUTE(c2); \ diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp new file mode 100644 index 0000000..cf7c9cf --- /dev/null +++ b/chaos/src/ikeda_laser_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ikeda_laser_map.hpp" +#include "chaos_dsp.hpp" + +class ikeda_laser_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); + + IKEDA_LASER_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("ikeda~", ikeda_laser_map_dsp); diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp new file mode 100644 index 0000000..d5f775a --- /dev/null +++ b/chaos/src/ikeda_laser_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ikeda_laser_map.hpp" +#include "chaos_msg.hpp" + +class ikeda_laser_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); + + IKEDA_LASER_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("ikeda_laser_map", ikeda_laser_map_msg); diff --git a/chaos/src/logistic_dsp.cpp b/chaos/src/logistic_dsp.cpp new file mode 100644 index 0000000..1c20a05 --- /dev/null +++ b/chaos/src/logistic_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "logistic_map.hpp" +#include "chaos_dsp.hpp" + +class logistic_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(logistic, LOGISTIC_ATTRIBUTES); + + LOGISTIC_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("logistic~", logistic_dsp); diff --git a/chaos/src/logistic_msg.cpp b/chaos/src/logistic_msg.cpp new file mode 100644 index 0000000..db7bcbf --- /dev/null +++ b/chaos/src/logistic_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "logistic_map.hpp" +#include "chaos_msg.hpp" + +class logistic_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(logistic, LOGISTIC_ATTRIBUTES); + + LOGISTIC_CALLBACKS; +}; + + + +FLEXT_LIB_V("logistic", logistic_msg); diff --git a/chaos/src/lorenz_dsp.cpp b/chaos/src/lorenz_dsp.cpp new file mode 100644 index 0000000..8dc3763 --- /dev/null +++ b/chaos/src/lorenz_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lorenz.hpp" +#include "chaos_dsp.hpp" + +class lorenz_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(lorenz, LORENZ_ATTRIBUTES); + + LORENZ_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("lorenz~", lorenz_dsp); diff --git a/chaos/src/lorenz_msg.cpp b/chaos/src/lorenz_msg.cpp new file mode 100644 index 0000000..6ad3ed9 --- /dev/null +++ b/chaos/src/lorenz_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lorenz.hpp" +#include "chaos_msg.hpp" + +class lorenz_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(lorenz, LORENZ_ATTRIBUTES); + + LORENZ_CALLBACKS; +}; + + + +FLEXT_LIB_V("lorenz", lorenz_msg); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 8bee655..37cab54 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -25,11 +25,11 @@ // b != 0 // taken from Willi-Hans Steeb: Chaos and Fractals -class lozi: - protected map_base +class lozi_map: + public map_base { public: - lozi() + lozi_map() { m_num_eq = 2; m_data = new data_t[1]; @@ -39,7 +39,7 @@ public: CHAOS_SYS_INIT(b,0.3); } - ~lozi() + ~lozi_map() { delete m_data; } @@ -71,14 +71,14 @@ public: }; -#define LOZI_CALLBACKS \ +#define LOZI_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(a); \ CHAOS_SYS_CALLBACKS(b); \ CHAOS_SYS_CALLBACKS(x); \ CHAOS_SYS_CALLBACKS(y); -#define LOZI_ATTRIBUTES \ +#define LOZI_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(a); \ CHAOS_SYS_ATTRIBUTE(b); \ diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp new file mode 100644 index 0000000..f8c4695 --- /dev/null +++ b/chaos/src/lozi_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lozi_map.hpp" +#include "chaos_dsp.hpp" + +class lozi_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); + + LOZI_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("lozi~", lozi_map_dsp); diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp new file mode 100644 index 0000000..947e772 --- /dev/null +++ b/chaos/src/lozi_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lozi_map.hpp" +#include "chaos_msg.hpp" + +class lozi_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); + + LOZI_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("lozi", lozi_map_msg); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 42dc16d..16f2908 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,12 +23,42 @@ void chaos_library_setup() { post("chaos~ version "PACKAGE_VERSION"\n"); + + FLEXT_DSP_SETUP(bernoulli_dsp); + FLEXT_SETUP(bernoulli_msg); + + FLEXT_DSP_SETUP(bungalow_tent_dsp); + FLEXT_SETUP(bungalow_tent_msg); + + FLEXT_DSP_SETUP(circle_map_dsp); + FLEXT_SETUP(circle_map_msg); + + FLEXT_DSP_SETUP(gauss_map_dsp); + FLEXT_SETUP(gauss_map_msg); + + FLEXT_DSP_SETUP(henon_dsp); + FLEXT_SETUP(henon_msg); + + FLEXT_DSP_SETUP(ikeda_laser_map_dsp); + FLEXT_SETUP(ikeda_laser_map_msg); + FLEXT_DSP_SETUP(logistic_dsp); + FLEXT_SETUP(logistic_msg); + FLEXT_DSP_SETUP(lorenz_dsp); FLEXT_SETUP(lorenz_msg); - FLEXT_DSP_SETUP(logistic_dsp); - FLEXT_SETUP(logistic_msg); + FLEXT_DSP_SETUP(lozi_map_dsp); + FLEXT_SETUP(lozi_map_msg); + + FLEXT_DSP_SETUP(sine_map_dsp); + FLEXT_SETUP(sine_map_msg); + + FLEXT_DSP_SETUP(standard_map_dsp); + FLEXT_SETUP(standard_map_msg); + + FLEXT_DSP_SETUP(tent_map_dsp); + FLEXT_SETUP(tent_map_msg); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index d083270..376a245 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -25,19 +25,19 @@ // 0 <= x[n] <= 1 // taken from Willi-Hans Steeb: Chaos and Fractals -class sine: - protected map_base +class sine_map: + public map_base { public: - sine() + sine_map() { m_num_eq = 1; m_data = new data_t[1]; CHAOS_SYS_INIT(x,0); } - ~sine() + ~sine_map() { delete m_data; } @@ -47,7 +47,7 @@ public: m_data[0] = sin (M_PI * m_data[0]); } - CHAOS_SYSVAR_FUNCS_PRED(x, m_pred); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred); bool m_pred(t_float f) { @@ -55,11 +55,11 @@ public: } }; -#define SINE_CALLBACKS \ +#define SINE_MAP_CALLBACKS \ MAP_CALLBACKS \ CHAOS_SYS_CALLBACKS(x); -#define SINE_ATTRIBUTES \ +#define SINE_MAP_ATTRIBUTES \ MAP_ATTRIBUTES \ CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/sine_map_dsp.cpp b/chaos/src/sine_map_dsp.cpp new file mode 100644 index 0000000..a2d2929 --- /dev/null +++ b/chaos/src/sine_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "sine_map.hpp" +#include "chaos_dsp.hpp" + +class sine_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(sine_map, SINE_MAP_ATTRIBUTES); + + SINE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("sine_map~", sine_map_dsp); diff --git a/chaos/src/sine_map_msg.cpp b/chaos/src/sine_map_msg.cpp new file mode 100644 index 0000000..1d9a90e --- /dev/null +++ b/chaos/src/sine_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "sine_map.hpp" +#include "chaos_msg.hpp" + +class sine_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(sine_map, SINE_MAP_ATTRIBUTES); + + SINE_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("sine_map", sine_map_msg); diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 9515efe..c0f0b8d 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -26,11 +26,11 @@ // 0 <= theta <= 2*pi // taken from Willi-Hans Steeb: Chaos and Fractals -class standard: - protected map_base +class standard_map: + public map_base { public: - standard() + standard_map() { m_num_eq = 2; m_data = new data_t[2]; @@ -40,7 +40,7 @@ public: CHAOS_SYS_INIT(k, 0.8); } - ~standard() + ~standard_map() { delete m_data; } @@ -54,23 +54,23 @@ public: m_data[0] = I + k * sin(theta); theta = theta + I + k * sin(theta); - if (y > 2 * M_PI) + if (theta > 2 * M_PI) { do { - y -= 2*M_PI; + theta -= 2*M_PI; } - while (y > 2 * M_PI); + while (theta > 2 * M_PI); goto put_data; } - if (y < 0) + if (theta < 0) { do { - y += 2*M_PI; + theta += 2*M_PI; } - while (y < 0); + while (theta < 0); } put_data: @@ -86,18 +86,18 @@ public: return (f >= 0) && (f < 2*M_PI); } - CHAOS_SYSPAR_FUNCS(I, 1); + CHAOS_SYSPAR_FUNCS(k); }; -#define STANDARD_CALLBACKS \ +#define STANDARD_MAP_CALLBACKS \ MAP_CALLBACKS; \ CHAOS_SYS_CALLBACKS(I); \ CHAOS_SYS_CALLBACKS(theta); \ CHAOS_SYS_CALLBACKS(k); -#define STANDARD_ATTRIBUTES \ +#define STANDARD_MAP_ATTRIBUTES \ MAP_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(I); \ CHAOS_SYS_ATTRIBUTE(theta); \ diff --git a/chaos/src/standard_map_dsp.cpp b/chaos/src/standard_map_dsp.cpp new file mode 100644 index 0000000..fa7d3be --- /dev/null +++ b/chaos/src/standard_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "standard_map.hpp" +#include "chaos_dsp.hpp" + +class standard_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); + + STANDARD_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("standard_map~", standard_map_dsp); diff --git a/chaos/src/standard_map_msg.cpp b/chaos/src/standard_map_msg.cpp new file mode 100644 index 0000000..fdd3bda --- /dev/null +++ b/chaos/src/standard_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "standard_map.hpp" +#include "chaos_msg.hpp" + +class standard_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); + + STANDARD_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("standard_map", standard_map_msg); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 137599a..9ab59ec 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -25,18 +25,18 @@ // 0 <= x[n] < 1 // taken from Willi-Hans Steeb: Chaos and Fractals -class tent: - protected map_base +class tent_map: + public map_base { public: - tent() + tent_map() { m_num_eq = 1; m_data = new data_t[1]; CHAOS_SYS_INIT(x, 0.5); } - ~tent() + ~tent_map() { delete m_data; } @@ -59,12 +59,12 @@ public: }; -#define LOGISTIC_CALLBACKS \ +#define TENT_MAP_CALLBACKS \ MAP_CALLBACKS \ CHAOS_SYS_CALLBACKS(x); -#define LOGISTIC_ATTRIBUTES \ +#define TENT_MAP_ATTRIBUTES \ MAP_ATTRIBUTES \ CHAOS_SYS_ATTRIBUTE(x); - + diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp new file mode 100644 index 0000000..10fe609 --- /dev/null +++ b/chaos/src/tent_map_dsp.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "tent_map.hpp" +#include "chaos_dsp.hpp" + +class tent_map_dsp: + public chaos_dsp +{ + CHAOS_DSP_INIT(tent_map, TENT_MAP_ATTRIBUTES); + + TENT_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_DSP_V("tent~", tent_map_dsp); diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp new file mode 100644 index 0000000..60c3c63 --- /dev/null +++ b/chaos/src/tent_map_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "tent_map.hpp" +#include "chaos_msg.hpp" + +class tent_map_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(tent_map, TENT_MAP_ATTRIBUTES); + + TENT_MAP_CALLBACKS; +}; + + + +FLEXT_LIB_V("tent", tent_map_msg); -- cgit v1.2.1 From 6963657b3f3ee4321394953a2cc67cd7386cce2d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 27 Dec 2004 22:55:41 +0000 Subject: additions and better code reuse svn path=/trunk/externals/tb/; revision=2433 --- chaos/src/Makefile.am | 4 ++ chaos/src/bernoulli_dsp.cpp | 12 +--- chaos/src/bungalow_tent_dsp.cpp | 12 +--- chaos/src/bungalow_tent_msg.cpp | 12 +--- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 1 - chaos/src/chaos_defs.hpp | 42 ++++++++++++- chaos/src/circle_map_dsp.cpp | 12 +--- chaos/src/circle_map_msg.cpp | 12 +--- chaos/src/coupled_logistic.hpp | 82 ++++++++++++++++++++++++++ chaos/src/coupled_logistic_dsp.cpp | 25 ++++++++ chaos/src/coupled_logistic_msg.cpp | 34 +++++++++++ chaos/src/driven_anharmonic.hpp | 111 +++++++++++++++++++++++++++++++++++ chaos/src/driven_anharmonic_dsp.cpp | 25 ++++++++ chaos/src/driven_anharmonic_msg.cpp | 25 ++++++++ chaos/src/driven_van_der_pol.hpp | 95 ++++++++++++++++++++++++++++++ chaos/src/driven_van_der_pol_dsp.cpp | 25 ++++++++ chaos/src/driven_van_der_pol_msg.cpp | 25 ++++++++ chaos/src/gauss_map_dsp.cpp | 12 +--- chaos/src/gauss_map_msg.cpp | 12 +--- chaos/src/henon_map_dsp.cpp | 12 +--- chaos/src/henon_map_msg.cpp | 12 +--- chaos/src/ikeda_laser_map_dsp.cpp | 10 +--- chaos/src/ikeda_laser_map_msg.cpp | 12 +--- chaos/src/logistic_dsp.cpp | 12 +--- chaos/src/logistic_msg.cpp | 12 +--- chaos/src/lorenz.hpp | 2 - chaos/src/lorenz_dsp.cpp | 12 +--- chaos/src/lorenz_msg.cpp | 12 +--- chaos/src/lozi_map_dsp.cpp | 12 +--- chaos/src/lozi_map_msg.cpp | 12 +--- chaos/src/main.cpp | 52 ++++++---------- chaos/src/roessler.hpp | 89 ++++++++++++++++++++++++++++ chaos/src/roessler_dsp.cpp | 24 ++++++++ chaos/src/roessler_msg.cpp | 24 ++++++++ chaos/src/sine_map_dsp.cpp | 11 +--- chaos/src/sine_map_msg.cpp | 12 +--- chaos/src/standard_map_dsp.cpp | 11 +--- chaos/src/standard_map_msg.cpp | 12 +--- chaos/src/tent_map_dsp.cpp | 10 +--- chaos/src/tent_map_msg.cpp | 12 +--- 41 files changed, 670 insertions(+), 286 deletions(-) create mode 100644 chaos/src/coupled_logistic.hpp create mode 100644 chaos/src/coupled_logistic_dsp.cpp create mode 100644 chaos/src/coupled_logistic_msg.cpp create mode 100644 chaos/src/driven_anharmonic.hpp create mode 100644 chaos/src/driven_anharmonic_dsp.cpp create mode 100644 chaos/src/driven_anharmonic_msg.cpp create mode 100644 chaos/src/driven_van_der_pol.hpp create mode 100644 chaos/src/driven_van_der_pol_dsp.cpp create mode 100644 chaos/src/driven_van_der_pol_msg.cpp create mode 100644 chaos/src/roessler.hpp create mode 100644 chaos/src/roessler_dsp.cpp create mode 100644 chaos/src/roessler_msg.cpp diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index a524de5..6812701 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -4,12 +4,16 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ bernoulli_dsp.cpp bernoulli_msg.cpp \ bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ circle_map_dsp.cpp circle_map_msg.cpp \ + coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ + driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ + driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ gauss_map_dsp.cpp gauss_map_msg.cpp \ henon_map_dsp.cpp henon_map_msg.cpp \ ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ logistic_dsp.cpp logistic_msg.cpp \ lorenz_dsp.cpp lorenz_msg.cpp \ lozi_map_dsp.cpp lozi_map_msg.cpp \ + roessler_dsp.cpp roessler_msg.cpp \ sine_map_dsp.cpp sine_map_msg.cpp \ standard_map_dsp.cpp standard_map_msg.cpp \ tent_map_dsp.cpp tent_map_msg.cpp diff --git a/chaos/src/bernoulli_dsp.cpp b/chaos/src/bernoulli_dsp.cpp index 8e8d0da..3cf9480 100644 --- a/chaos/src/bernoulli_dsp.cpp +++ b/chaos/src/bernoulli_dsp.cpp @@ -21,14 +21,4 @@ #include "bernoulli_map.hpp" #include "chaos_dsp.hpp" -class bernoulli_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(bernoulli, BERNOULLI_ATTRIBUTES); - - BERNOULLI_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("bernoulli~", bernoulli_dsp); +CHAOS_DSP_CLASS(bernoulli, BERNOULLI); diff --git a/chaos/src/bungalow_tent_dsp.cpp b/chaos/src/bungalow_tent_dsp.cpp index 33bef1c..111a96a 100644 --- a/chaos/src/bungalow_tent_dsp.cpp +++ b/chaos/src/bungalow_tent_dsp.cpp @@ -21,14 +21,4 @@ #include "bungalow_tent_map.hpp" #include "chaos_dsp.hpp" -class bungalow_tent_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); - - BUNGALOW_TENT_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("bungalow_tent~", bungalow_tent_dsp); +CHAOS_DSP_CLASS(bungalow_tent,BUNGALOW_TENT); diff --git a/chaos/src/bungalow_tent_msg.cpp b/chaos/src/bungalow_tent_msg.cpp index 8c6b1be..6c3ae7e 100644 --- a/chaos/src/bungalow_tent_msg.cpp +++ b/chaos/src/bungalow_tent_msg.cpp @@ -21,14 +21,4 @@ #include "bungalow_tent_map.hpp" #include "chaos_msg.hpp" -class bungalow_tent_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(bungalow_tent, BUNGALOW_TENT_ATTRIBUTES); - - BUNGALOW_TENT_CALLBACKS; -}; - - - -FLEXT_LIB_V("bungalow_tent", bungalow_tent_msg); +CHAOS_MSG_CLASS(bungalow_tent, BUNGALOW_TENT); diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 65a9c46..4bf3ea3 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -23,6 +23,7 @@ #define FLEXT_ATTRIBUTES 1 #include "flext.h" +#include "chaos_defs.hpp" /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 795383e..ce6fc11 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -21,7 +21,6 @@ #ifndef __chaos_base_hpp #include "chaos.hpp" -#include "chaos_defs.hpp" class chaos_base { diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index ae86223..b4c2b46 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -131,7 +131,47 @@ set_##NAME(VALUE); - +/* macros for class generation */ +#define CHAOS_DSP_CLASS(CLASSNAME,CLASSNAME_UC) \ +class CLASSNAME##_dsp: \ + public chaos_dsp \ +{ \ + CHAOS_DSP_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_DSP_V(#CLASSNAME"~", CLASSNAME##_dsp); + +#define CHAOS_DSP_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ +class CLASSNAME##_dsp: \ + public chaos_dsp \ +{ \ + CHAOS_DSP_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_DSP_V(#NAME, CLASSNAME##_dsp); + + +#define CHAOS_MSG_CLASS(CLASSNAME,CLASSNAME_UC) \ +class CLASSNAME##_msg: \ + public chaos_msg \ +{ \ + CHAOS_MSG_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#CLASSNAME, CLASSNAME##_msg); + +#define CHAOS_MSG_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ +class CLASSNAME##_msg: \ + public chaos_msg \ +{ \ + CHAOS_MSG_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#NAME, CLASSNAME##_msg); + +#define CHAOS_ADD(NAME) \ +FLEXT_DSP_SETUP(NAME##_dsp); \ +FLEXT_SETUP(NAME##_msg); #define __chaos_defs_hpp #endif /* __chaos_defs_hpp */ diff --git a/chaos/src/circle_map_dsp.cpp b/chaos/src/circle_map_dsp.cpp index fbd7c9d..e5ddef4 100644 --- a/chaos/src/circle_map_dsp.cpp +++ b/chaos/src/circle_map_dsp.cpp @@ -21,14 +21,4 @@ #include "circle_map.hpp" #include "chaos_dsp.hpp" -class circle_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); - - CIRCLE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("circle_map~", circle_map_dsp); +CHAOS_DSP_CLASS(circle_map, CIRCLE_MAP) diff --git a/chaos/src/circle_map_msg.cpp b/chaos/src/circle_map_msg.cpp index 3e771b3..7fa6c9b 100644 --- a/chaos/src/circle_map_msg.cpp +++ b/chaos/src/circle_map_msg.cpp @@ -21,14 +21,4 @@ #include "circle_map.hpp" #include "chaos_msg.hpp" -class circle_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(circle_map, CIRCLE_MAP_ATTRIBUTES); - - CIRCLE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("circle_map", circle_map_msg); +CHAOS_MSG_CLASS(circle_map, CIRCLE_MAP); diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp new file mode 100644 index 0000000..eb5b326 --- /dev/null +++ b/chaos/src/coupled_logistic.hpp @@ -0,0 +1,82 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// coupled_logistic map: x[n+1] = r * x[n] * (1 - x[n]) + e * (y[n] - x[n]) +// y[n+1] = r * y[n] * (1 - y[n]) + e * (x[t] - y[t]) +// 1 <= r <= 4 +// taken from Willi-Hans Steeb: Chaos and Fractals + +class coupled_logistic: + public map_base +{ +public: + coupled_logistic() + { + m_num_eq = 2; + m_data = new data_t[2]; + CHAOS_SYS_INIT(e, 0.06); + CHAOS_SYS_INIT(r, 3.7); + CHAOS_SYS_INIT(x, 0.1); + CHAOS_SYS_INIT(x, 0.2); + } + + ~coupled_logistic() + { + delete m_data; + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + data_t e = CHAOS_PARAMETER(e); + data_t r = CHAOS_PARAMETER(r); + m_data[0] = r * x * (1.f - x) + e * (y - x); + m_data[1] = r * y * (1.f - y) + e * (x - y); + } + + CHAOS_SYSPAR_FUNCS(e); + CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); + bool m_pred_r(t_float f) + { + return (f > 0) && (f < 4); + } + + CHAOS_SYSVAR_FUNCS(x, 0); + CHAOS_SYSVAR_FUNCS(y, 0); + +}; + +#define COUPLED_LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(e); \ +CHAOS_SYS_CALLBACKS(r); \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); + +#define COUPLED_LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(e); \ +CHAOS_SYS_ATTRIBUTE(r); \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); + diff --git a/chaos/src/coupled_logistic_dsp.cpp b/chaos/src/coupled_logistic_dsp.cpp new file mode 100644 index 0000000..166ca79 --- /dev/null +++ b/chaos/src/coupled_logistic_dsp.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "coupled_logistic.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(coupled_logistic, COUPLED_LOGISTIC) + diff --git a/chaos/src/coupled_logistic_msg.cpp b/chaos/src/coupled_logistic_msg.cpp new file mode 100644 index 0000000..994a79d --- /dev/null +++ b/chaos/src/coupled_logistic_msg.cpp @@ -0,0 +1,34 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "coupled_logistic.hpp" +#include "chaos_msg.hpp" + +class coupled_logistic_msg: + public chaos_msg +{ + CHAOS_MSG_INIT(coupled_logistic, COUPLED_LOGISTIC_ATTRIBUTES); + + COUPLED_LOGISTIC_CALLBACKS; +}; + + + +FLEXT_LIB_V("coupled_logistic", coupled_logistic_msg); diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp new file mode 100644 index 0000000..8c319e9 --- /dev/null +++ b/chaos/src/driven_anharmonic.hpp @@ -0,0 +1,111 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" +#include + +// driven anharmonic: +// d2u/dt2 + a * du/dt + b*u + c * u*u*u = k1 + k2*cos(Omega*t) +// equivalent: +// du1/dt = u2 +// du2/dt = -a*u2 - b*u1 -c*u*u*u + k1 + k2*cos(Omega*t) +// taken from Willi-Hans Steeb: Chaos and Fractals + +class driven_anharmonic + : public ode_base +{ +public: + driven_anharmonic() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,0.01); + + CHAOS_SYS_INIT(u1,0); + CHAOS_SYS_INIT(u2,1); + + CHAOS_SYS_INIT(a,1); + CHAOS_SYS_INIT(b,-10); + CHAOS_SYS_INIT(c,100); + CHAOS_SYS_INIT(Omega,3.5); + CHAOS_SYS_INIT(k1,0.01); + CHAOS_SYS_INIT(k2,1); + + ode_base_alloc(); + m_t = 0; + } + + ~driven_anharmonic() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t u1 = data[0], u2 = data[1]; + + deriv[0] = u2; + deriv[1] = - CHAOS_PARAMETER(a) * u2 - CHAOS_PARAMETER(b) * u1 - + CHAOS_PARAMETER(c) * u1*u1*u1 + CHAOS_PARAMETER(k1) + + CHAOS_PARAMETER(k2) * cos (CHAOS_PARAMETER(Omega) * m_t); + m_t += m_dt; + + if (m_t > 2 * M_PI) + m_t = fmod(m_t, 2*M_PI); + } + + data_t m_t; + + CHAOS_SYSVAR_FUNCS(u1, 0); + CHAOS_SYSVAR_FUNCS(u2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); + CHAOS_SYSPAR_FUNCS(k1); + CHAOS_SYSPAR_FUNCS(k2); + CHAOS_SYSPAR_FUNCS(Omega); +}; + + +#define DRIVEN_ANHARMONIC_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(u1); \ +CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); \ +CHAOS_SYS_CALLBACKS(k1); \ +CHAOS_SYS_CALLBACKS(k2); \ +CHAOS_SYS_CALLBACKS(Omega); + +#define DRIVEN_ANHARMONIC_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(u1); \ +CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); \ +CHAOS_SYS_ATTRIBUTE(k1); \ +CHAOS_SYS_ATTRIBUTE(k2); \ +CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/driven_anharmonic_dsp.cpp b/chaos/src/driven_anharmonic_dsp.cpp new file mode 100644 index 0000000..c26deaf --- /dev/null +++ b/chaos/src/driven_anharmonic_dsp.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_anharmonic.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(driven_anharmonic, DRIVEN_ANHARMONIC); + diff --git a/chaos/src/driven_anharmonic_msg.cpp b/chaos/src/driven_anharmonic_msg.cpp new file mode 100644 index 0000000..934b0f0 --- /dev/null +++ b/chaos/src/driven_anharmonic_msg.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_anharmonic.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(driven_anharmonic, DRIVEN_ANHARMONIC); + diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp new file mode 100644 index 0000000..23386b3 --- /dev/null +++ b/chaos/src/driven_van_der_pol.hpp @@ -0,0 +1,95 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" +#include + +// driven van_der_pol: +// d2u/dt2 + a*(u*u -1)*du/dt + u = k * cos(Omega*t) +// equivalent: +// du1/dt = u2 +// du2/dt = -a*(u1*u1 - 1)*u2 - u1 + k*cos(u3) +// du3/dt = Omega +// taken from Willi-Hans Steeb: Chaos and Fractals + +class driven_van_der_pol + : public ode_base +{ +public: + driven_van_der_pol() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(dt,0.01); + + CHAOS_SYS_INIT(u1,0.8); + CHAOS_SYS_INIT(u2,0.6); + CHAOS_SYS_INIT(u3,0.4); + + CHAOS_SYS_INIT(a,5); + CHAOS_SYS_INIT(Omega,2.466); + CHAOS_SYS_INIT(k,5); + + ode_base_alloc(); + } + + ~driven_van_der_pol() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t u1 = data[0], u2 = data[1], u3 = data[2]; + + deriv[0] = u2; + deriv[1] = - CHAOS_PARAMETER(a) * (u1*u1 -1) * u2 - u1 + + CHAOS_PARAMETER(k)*cos(u3); + deriv[2] = CHAOS_PARAMETER(Omega); + } + + CHAOS_SYSVAR_FUNCS(u1, 0); + CHAOS_SYSVAR_FUNCS(u2, 1); + CHAOS_SYSVAR_FUNCS(u3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(k); + CHAOS_SYSPAR_FUNCS(Omega); +}; + + +#define DRIVEN_VAN_DER_POL_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(u1); \ +CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(k); \ +CHAOS_SYS_CALLBACKS(Omega); + +#define DRIVEN_VAN_DER_POL_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(u1); \ +CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(k); \ +CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/driven_van_der_pol_dsp.cpp b/chaos/src/driven_van_der_pol_dsp.cpp new file mode 100644 index 0000000..e0787ae --- /dev/null +++ b/chaos/src/driven_van_der_pol_dsp.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_van_der_pol.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(driven_van_der_pol, DRIVEN_VAN_DER_POL); + diff --git a/chaos/src/driven_van_der_pol_msg.cpp b/chaos/src/driven_van_der_pol_msg.cpp new file mode 100644 index 0000000..488d96e --- /dev/null +++ b/chaos/src/driven_van_der_pol_msg.cpp @@ -0,0 +1,25 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_van_der_pol.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(driven_van_der_pol, DRIVEN_VAN_DER_POL); + diff --git a/chaos/src/gauss_map_dsp.cpp b/chaos/src/gauss_map_dsp.cpp index 70e659d..f9d849e 100644 --- a/chaos/src/gauss_map_dsp.cpp +++ b/chaos/src/gauss_map_dsp.cpp @@ -21,14 +21,4 @@ #include "gauss_map.hpp" #include "chaos_dsp.hpp" -class gauss_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); - - GAUSS_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("gauss_map~", gauss_map_dsp); +CHAOS_DSP_CLASS(gauss_map, GAUSS_MAP); diff --git a/chaos/src/gauss_map_msg.cpp b/chaos/src/gauss_map_msg.cpp index 61e0379..6d00da6 100644 --- a/chaos/src/gauss_map_msg.cpp +++ b/chaos/src/gauss_map_msg.cpp @@ -21,14 +21,4 @@ #include "gauss_map.hpp" #include "chaos_msg.hpp" -class gauss_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(gauss_map, GAUSS_MAP_ATTRIBUTES); - - GAUSS_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("gauss_map", gauss_map_msg); +CHAOS_MSG_CLASS(gauss_map, GAUSS_MAP); diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp index f28e83f..f7e6103 100644 --- a/chaos/src/henon_map_dsp.cpp +++ b/chaos/src/henon_map_dsp.cpp @@ -21,14 +21,4 @@ #include "henon_map.hpp" #include "chaos_dsp.hpp" -class henon_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(henon, HENON_ATTRIBUTES); - - HENON_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("henon~", henon_dsp); +CHAOS_DSP_CLASS_NAME(henon, HENON, "henon~"); diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp index 10849fd..22cddde 100644 --- a/chaos/src/henon_map_msg.cpp +++ b/chaos/src/henon_map_msg.cpp @@ -21,14 +21,4 @@ #include "henon_map.hpp" #include "chaos_msg.hpp" -class henon_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(henon, HENON_ATTRIBUTES); - - HENON_CALLBACKS; -}; - - - -FLEXT_LIB_V("henon", henon_msg); +CHAOS_MSG_CLASS_NAME(henon, HENON, "henon"); diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp index cf7c9cf..ea18e21 100644 --- a/chaos/src/ikeda_laser_map_dsp.cpp +++ b/chaos/src/ikeda_laser_map_dsp.cpp @@ -21,14 +21,6 @@ #include "ikeda_laser_map.hpp" #include "chaos_dsp.hpp" -class ikeda_laser_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); - IKEDA_LASER_MAP_CALLBACKS; -}; +CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda"); - - -FLEXT_LIB_DSP_V("ikeda~", ikeda_laser_map_dsp); diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp index d5f775a..1659159 100644 --- a/chaos/src/ikeda_laser_map_msg.cpp +++ b/chaos/src/ikeda_laser_map_msg.cpp @@ -21,14 +21,4 @@ #include "ikeda_laser_map.hpp" #include "chaos_msg.hpp" -class ikeda_laser_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(ikeda_laser_map, IKEDA_LASER_MAP_ATTRIBUTES); - - IKEDA_LASER_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("ikeda_laser_map", ikeda_laser_map_msg); +CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda~"); diff --git a/chaos/src/logistic_dsp.cpp b/chaos/src/logistic_dsp.cpp index 1c20a05..6a88748 100644 --- a/chaos/src/logistic_dsp.cpp +++ b/chaos/src/logistic_dsp.cpp @@ -21,14 +21,4 @@ #include "logistic_map.hpp" #include "chaos_dsp.hpp" -class logistic_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(logistic, LOGISTIC_ATTRIBUTES); - - LOGISTIC_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("logistic~", logistic_dsp); +CHAOS_DSP_CLASS(logistic, LOGISTIC); diff --git a/chaos/src/logistic_msg.cpp b/chaos/src/logistic_msg.cpp index db7bcbf..60fef89 100644 --- a/chaos/src/logistic_msg.cpp +++ b/chaos/src/logistic_msg.cpp @@ -21,14 +21,4 @@ #include "logistic_map.hpp" #include "chaos_msg.hpp" -class logistic_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(logistic, LOGISTIC_ATTRIBUTES); - - LOGISTIC_CALLBACKS; -}; - - - -FLEXT_LIB_V("logistic", logistic_msg); +CHAOS_MSG_CLASS(logistic, LOGISTIC); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index a31c151..c876b4a 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -44,8 +44,6 @@ public: CHAOS_SYS_INIT(r,40); ode_base_alloc(); - - set_method(0); } ~lorenz() diff --git a/chaos/src/lorenz_dsp.cpp b/chaos/src/lorenz_dsp.cpp index 8dc3763..e1b8ad1 100644 --- a/chaos/src/lorenz_dsp.cpp +++ b/chaos/src/lorenz_dsp.cpp @@ -21,14 +21,4 @@ #include "lorenz.hpp" #include "chaos_dsp.hpp" -class lorenz_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(lorenz, LORENZ_ATTRIBUTES); - - LORENZ_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("lorenz~", lorenz_dsp); +CHAOS_DSP_CLASS(lorenz, LORENZ); diff --git a/chaos/src/lorenz_msg.cpp b/chaos/src/lorenz_msg.cpp index 6ad3ed9..09b02e8 100644 --- a/chaos/src/lorenz_msg.cpp +++ b/chaos/src/lorenz_msg.cpp @@ -21,14 +21,4 @@ #include "lorenz.hpp" #include "chaos_msg.hpp" -class lorenz_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(lorenz, LORENZ_ATTRIBUTES); - - LORENZ_CALLBACKS; -}; - - - -FLEXT_LIB_V("lorenz", lorenz_msg); +CHAOS_MSG_CLASS(lorenz, LORENZ); diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp index f8c4695..0448412 100644 --- a/chaos/src/lozi_map_dsp.cpp +++ b/chaos/src/lozi_map_dsp.cpp @@ -21,14 +21,4 @@ #include "lozi_map.hpp" #include "chaos_dsp.hpp" -class lozi_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); - - LOZI_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("lozi~", lozi_map_dsp); +CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp index 947e772..099cbec 100644 --- a/chaos/src/lozi_map_msg.cpp +++ b/chaos/src/lozi_map_msg.cpp @@ -21,14 +21,4 @@ #include "lozi_map.hpp" #include "chaos_msg.hpp" -class lozi_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(lozi_map, LOZI_MAP_ATTRIBUTES); - - LOZI_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("lozi", lozi_map_msg); +CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 16f2908..84589f8 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -19,46 +19,28 @@ // Boston, MA 02111-1307, USA. #include "chaos.hpp" +#include "chaos_defs.hpp" void chaos_library_setup() { post("chaos~ version "PACKAGE_VERSION"\n"); - FLEXT_DSP_SETUP(bernoulli_dsp); - FLEXT_SETUP(bernoulli_msg); - - FLEXT_DSP_SETUP(bungalow_tent_dsp); - FLEXT_SETUP(bungalow_tent_msg); - - FLEXT_DSP_SETUP(circle_map_dsp); - FLEXT_SETUP(circle_map_msg); - - FLEXT_DSP_SETUP(gauss_map_dsp); - FLEXT_SETUP(gauss_map_msg); - - FLEXT_DSP_SETUP(henon_dsp); - FLEXT_SETUP(henon_msg); - - FLEXT_DSP_SETUP(ikeda_laser_map_dsp); - FLEXT_SETUP(ikeda_laser_map_msg); - - FLEXT_DSP_SETUP(logistic_dsp); - FLEXT_SETUP(logistic_msg); - - FLEXT_DSP_SETUP(lorenz_dsp); - FLEXT_SETUP(lorenz_msg); - - FLEXT_DSP_SETUP(lozi_map_dsp); - FLEXT_SETUP(lozi_map_msg); - - FLEXT_DSP_SETUP(sine_map_dsp); - FLEXT_SETUP(sine_map_msg); - - FLEXT_DSP_SETUP(standard_map_dsp); - FLEXT_SETUP(standard_map_msg); - - FLEXT_DSP_SETUP(tent_map_dsp); - FLEXT_SETUP(tent_map_msg); + CHAOS_ADD(bernoulli); + CHAOS_ADD(bungalow_tent); + CHAOS_ADD(circle_map); + CHAOS_ADD(coupled_logistic); + CHAOS_ADD(driven_anharmonic); + CHAOS_ADD(driven_van_der_pol); + CHAOS_ADD(gauss_map); + CHAOS_ADD(henon); + CHAOS_ADD(ikeda_laser_map); + CHAOS_ADD(logistic); + CHAOS_ADD(lorenz); + CHAOS_ADD(lozi_map); + CHAOS_ADD(roesser); + CHAOS_ADD(sine_map); + CHAOS_ADD(standard_map); + CHAOS_ADD(tent_map); } FLEXT_LIB_SETUP(chaos, chaos_library_setup); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp new file mode 100644 index 0000000..85272ee --- /dev/null +++ b/chaos/src/roessler.hpp @@ -0,0 +1,89 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// roessler model: dx1/dt = - (x2 + x3) +// dx2/dt = x1 + a * x2 +// dx3/dt = b + (x1 - c) * x3 +// taken from Peitgen / Jürgens / Saupe: Chaos and Fractals + +class roessler + : public ode_base +{ +public: + roessler() + { + m_num_eq = 3; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(method,0); + CHAOS_SYS_INIT(x1,0); + CHAOS_SYS_INIT(x2,0); + CHAOS_SYS_INIT(x3,0); + CHAOS_SYS_INIT(a,4); + CHAOS_SYS_INIT(b,4); + CHAOS_SYS_INIT(c,4); + + ode_base_alloc(); + } + + ~roessler() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0], x2 = data[1], x3 = data[2]; + + deriv[0] = - (x2 - x1); + deriv[1] = x1 + CHAOS_PARAMETER(a) * x2; + deriv[2] = CHAOS_PARAMETER(b) + (x1 - CHAOS_PARAMETER(c)) * x3; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); +}; + + +#define ROESSLER_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); + +#define ROESSLER_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); diff --git a/chaos/src/roessler_dsp.cpp b/chaos/src/roessler_dsp.cpp new file mode 100644 index 0000000..e5ee834 --- /dev/null +++ b/chaos/src/roessler_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "roessler.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(roessler,ROESSLER); diff --git a/chaos/src/roessler_msg.cpp b/chaos/src/roessler_msg.cpp new file mode 100644 index 0000000..aad1bf6 --- /dev/null +++ b/chaos/src/roessler_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "roessler.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(roessler,ROESSLER); diff --git a/chaos/src/sine_map_dsp.cpp b/chaos/src/sine_map_dsp.cpp index a2d2929..b1ca11e 100644 --- a/chaos/src/sine_map_dsp.cpp +++ b/chaos/src/sine_map_dsp.cpp @@ -21,14 +21,5 @@ #include "sine_map.hpp" #include "chaos_dsp.hpp" -class sine_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(sine_map, SINE_MAP_ATTRIBUTES); - SINE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("sine_map~", sine_map_dsp); +CHAOS_DSP_CLASS(sine_map, SINE_MAP); diff --git a/chaos/src/sine_map_msg.cpp b/chaos/src/sine_map_msg.cpp index 1d9a90e..aacc51c 100644 --- a/chaos/src/sine_map_msg.cpp +++ b/chaos/src/sine_map_msg.cpp @@ -21,14 +21,4 @@ #include "sine_map.hpp" #include "chaos_msg.hpp" -class sine_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(sine_map, SINE_MAP_ATTRIBUTES); - - SINE_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("sine_map", sine_map_msg); +CHAOS_MSG_CLASS(sine_map, SINE_MAP); diff --git a/chaos/src/standard_map_dsp.cpp b/chaos/src/standard_map_dsp.cpp index fa7d3be..c16276c 100644 --- a/chaos/src/standard_map_dsp.cpp +++ b/chaos/src/standard_map_dsp.cpp @@ -21,14 +21,5 @@ #include "standard_map.hpp" #include "chaos_dsp.hpp" -class standard_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); - STANDARD_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_DSP_V("standard_map~", standard_map_dsp); +CHAOS_DSP_CLASS(standard_map, STANDARD_MAP); diff --git a/chaos/src/standard_map_msg.cpp b/chaos/src/standard_map_msg.cpp index fdd3bda..92c1084 100644 --- a/chaos/src/standard_map_msg.cpp +++ b/chaos/src/standard_map_msg.cpp @@ -21,14 +21,4 @@ #include "standard_map.hpp" #include "chaos_msg.hpp" -class standard_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(standard_map, STANDARD_MAP_ATTRIBUTES); - - STANDARD_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("standard_map", standard_map_msg); +CHAOS_MSG_CLASS(standard_map, STANDARD_MAP); diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp index 10fe609..44c909d 100644 --- a/chaos/src/tent_map_dsp.cpp +++ b/chaos/src/tent_map_dsp.cpp @@ -21,14 +21,6 @@ #include "tent_map.hpp" #include "chaos_dsp.hpp" -class tent_map_dsp: - public chaos_dsp -{ - CHAOS_DSP_INIT(tent_map, TENT_MAP_ATTRIBUTES); - TENT_MAP_CALLBACKS; -}; - - -FLEXT_LIB_DSP_V("tent~", tent_map_dsp); +CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, "tent~"); diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp index 60c3c63..3da82ab 100644 --- a/chaos/src/tent_map_msg.cpp +++ b/chaos/src/tent_map_msg.cpp @@ -21,14 +21,4 @@ #include "tent_map.hpp" #include "chaos_msg.hpp" -class tent_map_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(tent_map, TENT_MAP_ATTRIBUTES); - - TENT_MAP_CALLBACKS; -}; - - - -FLEXT_LIB_V("tent", tent_map_msg); +CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, "tent"); -- cgit v1.2.1 From 43dd4efedf1ecfe721cde5830bdcee67ffa48907 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 28 Dec 2004 12:38:45 +0000 Subject: a few new attractors ... svn path=/trunk/externals/tb/; revision=2434 --- chaos/src/Makefile.am | 5 ++ chaos/src/chaos.hpp | 4 +- chaos/src/chaos_defs.hpp | 1 + chaos/src/chaos_dsp.hpp | 160 +++++++++++++++++++++++++++------------- chaos/src/duffing_map.hpp | 76 +++++++++++++++++++ chaos/src/duffing_map_dsp.cpp | 24 ++++++ chaos/src/duffing_map_msg.cpp | 24 ++++++ chaos/src/latoocarfian.hpp | 98 ++++++++++++++++++++++++ chaos/src/latoocarfian_dsp.cpp | 24 ++++++ chaos/src/latoocarfian_msg.cpp | 24 ++++++ chaos/src/latoomutalpha.hpp | 88 ++++++++++++++++++++++ chaos/src/latoomutalpha_dsp.cpp | 24 ++++++ chaos/src/latoomutalpha_msg.cpp | 24 ++++++ chaos/src/latoomutbeta.hpp | 83 +++++++++++++++++++++ chaos/src/latoomutbeta_dsp.cpp | 24 ++++++ chaos/src/latoomutbeta_msg.cpp | 24 ++++++ chaos/src/latoomutgamma.hpp | 83 +++++++++++++++++++++ chaos/src/latoomutgamma_dsp.cpp | 24 ++++++ chaos/src/latoomutgamma_msg.cpp | 24 ++++++ chaos/src/logistic_map.hpp | 2 +- chaos/src/main.cpp | 7 +- 21 files changed, 792 insertions(+), 55 deletions(-) create mode 100644 chaos/src/duffing_map.hpp create mode 100644 chaos/src/duffing_map_dsp.cpp create mode 100644 chaos/src/duffing_map_msg.cpp create mode 100644 chaos/src/latoocarfian.hpp create mode 100644 chaos/src/latoocarfian_dsp.cpp create mode 100644 chaos/src/latoocarfian_msg.cpp create mode 100644 chaos/src/latoomutalpha.hpp create mode 100644 chaos/src/latoomutalpha_dsp.cpp create mode 100644 chaos/src/latoomutalpha_msg.cpp create mode 100644 chaos/src/latoomutbeta.hpp create mode 100644 chaos/src/latoomutbeta_dsp.cpp create mode 100644 chaos/src/latoomutbeta_msg.cpp create mode 100644 chaos/src/latoomutgamma.hpp create mode 100644 chaos/src/latoomutgamma_dsp.cpp create mode 100644 chaos/src/latoomutgamma_msg.cpp diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 6812701..cbaa287 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -7,9 +7,14 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ + duffing_map_dsp.cpp duffing_map_msg.cpp \ gauss_map_dsp.cpp gauss_map_msg.cpp \ henon_map_dsp.cpp henon_map_msg.cpp \ ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ + latoocarfian_dsp.cpp latoocarfian_msg.cpp \ + latoomutalpha_dsp.cpp latoomutalpha_msg.cpp \ + latoomutbeta_dsp.cpp latoomutbeta_msg.cpp \ + latoomutgamma_dsp.cpp latoomutgamma_msg.cpp \ logistic_dsp.cpp logistic_msg.cpp \ lorenz_dsp.cpp lorenz_msg.cpp \ lozi_map_dsp.cpp lozi_map_msg.cpp \ diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 4bf3ea3..231ecdc 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -28,8 +28,10 @@ /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; +#define CHAOS_ABS(x) fabs(x) #else -typedef t_float data_t; +typedef float data_t; +#define CHAOS_ABS(x) fabsf(x) #endif diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index b4c2b46..08c47d4 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -106,6 +106,7 @@ void set_##NAME(t_float &f) \ m_system->set_##NAME(f); \ } \ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); + #define CHAOS_SYS_CALLBACKS_I(NAME) \ public: \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 1eff6fc..c2f78b3 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -60,62 +60,118 @@ public: int m_phase; /* phase counter */ float m_sr; /* sample rate */ - int m_method; /* interpolation method */ + int m_imethod; /* interpolation method */ + + int get_imethod(int &i) + { + i = m_imethod; + } + + void set_imethod(int i) + { + if( (i >= 0) && (i <= 2) ) + m_imethod = i; + else + { + post("interpolation method out of range"); + return; + } + if( i != 2) + { + for (int j = 0; j != m_system->get_num_eq(); ++j) + { + m_nextvalues[i] = 0; + m_nextmidpts[i] = 0; + m_curves[i] = 0; + } + } + + } + + int get_freq(float &f) + { + f = m_freq; + } + + void set_freq(float f) + { + if( (f >= 0) && (f <= m_sr*0.5) ) + m_freq = f; + else + post("frequency out of range"); + } + FLEXT_CALLVAR_F(get_freq, set_freq); + FLEXT_CALLVAR_I(get_imethod, set_imethod); }; /* create constructor / destructor */ -#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ -FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ - \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - m_values = new t_float[size]; \ - m_slopes = new t_float[size]; \ - m_nextvalues = new t_float[size]; \ - m_nextmidpts = new t_float[size]; \ - m_curves = new t_float[size]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - \ - \ - m_freq = GetAFloat(argv[0]); \ - m_method = (char)GetAFloat(argv[1]); \ - m_phase = 0; \ - \ - FLEXT_ADDATTR_VAR1("frequency",m_freq); \ - FLEXT_ADDATTR_VAR1("method",m_method); \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ -{ \ - delete m_system; \ - delete m_values; \ - delete m_slopes; \ - delete m_nextvalues; \ - delete m_nextmidpts; \ - delete m_curves; \ -} \ - \ -FLEXT_ATTRVAR_F(m_freq); \ -FLEXT_ATTRVAR_I(m_method); +#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ + \ +SYSTEM##_dsp(int argc, t_atom* argv ) \ +{ \ + m_sr = 44100; /* assume default sampling rate (for max frequency) */ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + m_values = new t_float[size]; \ + m_slopes = new t_float[size]; \ + m_nextvalues = new t_float[size]; \ + m_nextmidpts = new t_float[size]; \ + m_curves = new t_float[size]; \ + \ + /* create inlets and zero arrays*/ \ + for (int i = 0; i != size; ++i) \ + { \ + AddOutSignal(); \ + m_values[i] = 0; \ + m_slopes[i] = 0; \ + m_nextvalues[i] = 0; \ + m_nextmidpts[i] = 0; \ + m_curves[i] = 0; \ + } \ + \ + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ + \ + if (argc > 0) \ + { \ + CHAOS_SYS_INIT(freq, GetAInt(argv[0])); \ + } \ + else \ + { \ + CHAOS_SYS_INIT(freq, 440); \ + } \ + \ + if (argc > 1) \ + { \ + CHAOS_SYS_INIT(imethod, GetAInt(argv[1])); \ + } \ + else \ + { \ + CHAOS_SYS_INIT(imethod, 0); \ + } \ + \ + m_phase = 0; \ + \ + ATTRIBUTES; \ +} \ + \ +~SYSTEM##_dsp() \ +{ \ + delete m_system; \ + delete m_values; \ + delete m_slopes; \ + delete m_nextvalues; \ + delete m_nextmidpts; \ + delete m_curves; \ +} \ + \ +FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_I(m_imethod); @@ -129,7 +185,7 @@ void chaos_dsp::m_signal(int n, t_sample *const *insigs, return; } - switch (m_method) + switch (m_imethod) { case 0: m_signal_n(n, insigs, outsigs); diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp new file mode 100644 index 0000000..71b8cbd --- /dev/null +++ b/chaos/src/duffing_map.hpp @@ -0,0 +1,76 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// duffing map: x1[n+1] = x2[n] +// x2[n+1] = -b*x1[n] + a*x2[n] - pow(x2,3) +// +// taken from Viktor Avrutin: AnT-Demos-4.669 + +class duffing_map: + public map_base +{ +public: + duffing_map() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + CHAOS_SYS_INIT(x1, 0.5); + CHAOS_SYS_INIT(x2, 0.5); + CHAOS_SYS_INIT(a, 0.5); + CHAOS_SYS_INIT(b, 0.5); + } + + ~duffing_map() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + + m_data[0] = x2; + m_data[1] = - CHAOS_PARAMETER(b)*x1 + CHAOS_PARAMETER(a)*x2 + - x2*x2*x2; + } + + CHAOS_SYSVAR_FUNCS(x1,0); + CHAOS_SYSVAR_FUNCS(x2,1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); +}; + +#define DUFFING_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); + +#define DUFFING_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); + diff --git a/chaos/src/duffing_map_dsp.cpp b/chaos/src/duffing_map_dsp.cpp new file mode 100644 index 0000000..39e1439 --- /dev/null +++ b/chaos/src/duffing_map_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing_map.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(duffing_map,DUFFING_MAP); diff --git a/chaos/src/duffing_map_msg.cpp b/chaos/src/duffing_map_msg.cpp new file mode 100644 index 0000000..a18817f --- /dev/null +++ b/chaos/src/duffing_map_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing_map.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(duffing_map,DUFFING_MAP); diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp new file mode 100644 index 0000000..c2a31a1 --- /dev/null +++ b/chaos/src/latoocarfian.hpp @@ -0,0 +1,98 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model: x1[n+1] = sin(x2[n]*b) + c*sin(x1[n]*b) +// x2[n+1] = sin(x1[n]*a) + d*sin(x2[n]*a) +// -3 < a,b < 3 +// -0.5 < c,d < 1.5 +// taken from Pickover: Chaos In Wonderland + +class latoocarfian + : public map_base +{ +public: + latoocarfian() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(c,0.765145); + CHAOS_SYS_INIT(d,0.744728); + } + + ~latoocarfian() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), + c = CHAOS_PARAMETER(c), d = CHAOS_PARAMETER(d); + + m_data[0] = sin(x2*b) + c*sin(x1*b); + m_data[1] = sin(x1*a) + d*sin(x2*a); + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS_PRED(a,m_pred_1); + CHAOS_SYSPAR_FUNCS_PRED(b,m_pred_1); + CHAOS_SYSPAR_FUNCS_PRED(c,m_pred_2); + CHAOS_SYSPAR_FUNCS_PRED(d,m_pred_2); + + bool m_pred_1(t_float f) + { + return (f > -3.f) && (f < 3.f); + } + + bool m_pred_2(t_float f) + { + return (f > -0.5) && (f < 1.5); + } +}; + + +#define LATOOCARFIAN_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); \ +CHAOS_SYS_CALLBACKS(d); + +#define LATOOCARFIAN_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); \ +CHAOS_SYS_ATTRIBUTE(d); diff --git a/chaos/src/latoocarfian_dsp.cpp b/chaos/src/latoocarfian_dsp.cpp new file mode 100644 index 0000000..81c773d --- /dev/null +++ b/chaos/src/latoocarfian_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoocarfian.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoocarfian,LATOOCARFIAN); diff --git a/chaos/src/latoocarfian_msg.cpp b/chaos/src/latoocarfian_msg.cpp new file mode 100644 index 0000000..92be013 --- /dev/null +++ b/chaos/src/latoocarfian_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoocarfian.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoocarfian,LATOOCARFIAN); diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp new file mode 100644 index 0000000..6926d1b --- /dev/null +++ b/chaos/src/latoomutalpha.hpp @@ -0,0 +1,88 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model, mutation alpha: +// x1[n+1] = sin(x2[n]*b) + pow(sin(x1[n]*b),2) + pow(sin(x1[n]*b),3) +// x2[n+1] = sin(x1[n]*a) + pow(sin(x2[n]*a),2) + pow(sin(x2[n]*c),3) +// taken from Pickover: Chaos In Wonderland + +class latoomutalpha + : public map_base +{ +public: + latoomutalpha() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0.2); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(c,0.765145); + } + + ~latoomutalpha() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), + c = CHAOS_PARAMETER(c); + data_t tmp1, tmp2; + + tmp1 = sin(x1*b); + m_data[0] = sin(x2*b) + tmp1*tmp1 + tmp1*tmp1*tmp1; + tmp1 = sin(x2*a); + tmp2 = sin(x2*c); + m_data[1] = sin(x1*a) + tmp1*tmp1 + tmp2*tmp2*tmp2; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); +}; + + +#define LATOOMUTALPHA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); + + +#define LATOOMUTALPHA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); diff --git a/chaos/src/latoomutalpha_dsp.cpp b/chaos/src/latoomutalpha_dsp.cpp new file mode 100644 index 0000000..c028ac6 --- /dev/null +++ b/chaos/src/latoomutalpha_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutalpha.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoomutalpha,LATOOMUTALPHA); diff --git a/chaos/src/latoomutalpha_msg.cpp b/chaos/src/latoomutalpha_msg.cpp new file mode 100644 index 0000000..0726708 --- /dev/null +++ b/chaos/src/latoomutalpha_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutalpha.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoomutalpha,LATOOMUTALPHA); diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp new file mode 100644 index 0000000..4940be1 --- /dev/null +++ b/chaos/src/latoomutbeta.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model, mutation beta: +// x1[n+1] = sin(x2[n]*b) + pow(sin(x1[n]*b),2) +// x2[n+1] = sin(x1[n]*a) + pow(sin(x2[n]*a),2) +// taken from Pickover: Chaos In Wonderland + +class latoomutbeta + : public map_base +{ +public: + latoomutbeta() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0.5); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + } + + ~latoomutbeta() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + data_t tmp; + + tmp = sin(x1*b); + m_data[0] = sin(x2*b) + tmp*tmp; + tmp = sin(x2*a); + m_data[1] = sin(x1*a) + tmp*tmp; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); +}; + + +#define LATOOMUTBETA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); + + +#define LATOOMUTBETA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); + diff --git a/chaos/src/latoomutbeta_dsp.cpp b/chaos/src/latoomutbeta_dsp.cpp new file mode 100644 index 0000000..b0f803e --- /dev/null +++ b/chaos/src/latoomutbeta_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutbeta.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoomutbeta,LATOOMUTBETA); diff --git a/chaos/src/latoomutbeta_msg.cpp b/chaos/src/latoomutbeta_msg.cpp new file mode 100644 index 0000000..41e5aaf --- /dev/null +++ b/chaos/src/latoomutbeta_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutbeta.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoomutbeta,LATOOMUTBETA); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp new file mode 100644 index 0000000..b4f3bf8 --- /dev/null +++ b/chaos/src/latoomutgamma.hpp @@ -0,0 +1,83 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" +#include + +// latoocarfian model, mutation gamma: +// x1[n+1] = abs(sin(x2[n]*b)) + pow(sin(x1[n]*b),2) +// x2[n+1] = abs(sin(x1[n]*a)) + pow(sin(x2[n]*a),2) +// taken from Pickover: Chaos In Wonderland + +class latoomutgamma + : public map_base +{ +public: + latoomutgamma() + { + m_num_eq = 2; + m_data = new data_t[m_num_eq]; + + CHAOS_SYS_INIT(x1,0.5); + CHAOS_SYS_INIT(x2,0.5); + CHAOS_SYS_INIT(a,-0.966918); + CHAOS_SYS_INIT(b,2.879879); + } + + ~latoomutgamma() + { + delete m_data; + } + + virtual void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + data_t tmp; + + tmp = sin(x1*b); + m_data[0] = CHAOS_ABS(sin(x2*b)) + tmp*tmp; + tmp = sin(x2*a); + m_data[1] = CHAOS_ABS(sin(x1*a)) + tmp*tmp; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); +}; + + +#define LATOOMUTGAMMA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); + + +#define LATOOMUTGAMMA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); + diff --git a/chaos/src/latoomutgamma_dsp.cpp b/chaos/src/latoomutgamma_dsp.cpp new file mode 100644 index 0000000..dbe625d --- /dev/null +++ b/chaos/src/latoomutgamma_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutgamma.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(latoomutgamma,LATOOMUTGAMMA); diff --git a/chaos/src/latoomutgamma_msg.cpp b/chaos/src/latoomutgamma_msg.cpp new file mode 100644 index 0000000..1b1c20d --- /dev/null +++ b/chaos/src/latoomutgamma_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutgamma.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(latoomutgamma,LATOOMUTGAMMA); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index e72a3a7..1808baa 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -31,7 +31,7 @@ public: logistic() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5); } diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 84589f8..eabb8d4 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -31,13 +31,18 @@ void chaos_library_setup() CHAOS_ADD(coupled_logistic); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); + CHAOS_ADD(duffing_map); CHAOS_ADD(gauss_map); CHAOS_ADD(henon); CHAOS_ADD(ikeda_laser_map); + CHAOS_ADD(latoocarfian); + CHAOS_ADD(latoomutalpha); + CHAOS_ADD(latoomutbeta); + CHAOS_ADD(latoomutgamma); CHAOS_ADD(logistic); CHAOS_ADD(lorenz); CHAOS_ADD(lozi_map); - CHAOS_ADD(roesser); + CHAOS_ADD(roessler); CHAOS_ADD(sine_map); CHAOS_ADD(standard_map); CHAOS_ADD(tent_map); -- cgit v1.2.1 From 2f98df88850ab893c7acf8ea2b9000c03c2e17da Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 28 Dec 2004 15:48:19 +0000 Subject: simd-optimized ramp svn path=/trunk/externals/tb/; revision=2435 --- volctl~/makefile | 2 +- volctl~/readme.txt | 3 +- volctl~/volctl~.c | 381 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 229 insertions(+), 157 deletions(-) diff --git a/volctl~/makefile b/volctl~/makefile index 9b4cc04..3457263 100644 --- a/volctl~/makefile +++ b/volctl~/makefile @@ -62,7 +62,7 @@ pd_linux: $(NAME).pd_linux LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ -Wall -W -Wshadow -Wstrict-prototypes -Werror \ - -Wno-unused -Wno-parentheses -Wno-switch + -Wno-unused -Wno-parentheses -Wno-switch LINUXINCLUDE = -I../../src diff --git a/volctl~/readme.txt b/volctl~/readme.txt index 5707467..4efff34 100644 --- a/volctl~/readme.txt +++ b/volctl~/readme.txt @@ -8,7 +8,7 @@ volctl~ is doing more or less the same as |line~ 0 10 | | | | | |*~ 0| = |volctl 0 10| -| | +| | except that it is faster @@ -20,5 +20,4 @@ volctl~ will only probably only compile against pd>=devel_0_37 with gcc. i'm not planing to do a port to win/osx or any pd without aligned dsp blocks... todo: -- write complete volctl_perform_simd function in assembler - check icc's segfault \ No newline at end of file diff --git a/volctl~/volctl~.c b/volctl~/volctl~.c index 9ef96de..60abfac 100644 --- a/volctl~/volctl~.c +++ b/volctl~/volctl~.c @@ -1,31 +1,30 @@ /* Copyright (c) 2004 Tim Blechmann. - *For information on usage and redistribution, and for a DISCLAIMER OF ALL - *WARRANTIES, see the file, "gpl.txt" in this distribution. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "gpl.txt" in this distribution. * - *This program is free software; you can redistribute it and/or - *modify it under the terms of the GNU General Public License - *as published by the Free Software Foundation; either version 2 - *of the License, or (at your option) any later version. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * - *See file LICENSE for further informations on licensing terms. + * See file LICENSE for further informations on licensing terms. * - *This program is distributed in the hope that it will be useful, - *but WITHOUT ANY WARRANTY; without even the implied warranty of - *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - *GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - *You should have received a copy of the GNU General Public License - *along with this program; if not, write to the Free Software - *Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - *Based on PureData by Miller Puckette and others. + * Based on PureData by Miller Puckette and others. * - * coded while listening to: Julien Ottavi: Nervure Magnetique + * coded while listening to: Julien Ottavi: Nervure Magnetique * */ #include "m_pd.h" - #include "m_simd.h" @@ -36,15 +35,16 @@ static t_class *volctl_class; typedef struct _volctl { t_object x_obj; - float x_f; + t_float x_f; - float x_h; //interpolation time - float x_value; //current factor + t_float x_h; //interpolation time + t_float x_value; //current factor int x_ticksleft; //ticks to go - float x_mspersample; //ms per sample - float x_slope; //slope - + t_float x_samples_per_ms; //ms per sample + t_float x_slope; //slope + t_float * x_slopes; //slopes for simd + t_float x_slope_step; int x_line; } t_volctl; @@ -54,7 +54,7 @@ void *volctl_new(t_symbol *s, int argc, t_atom *argv) if (argc > 2) post("volctl~: extra arguments ignored"); t_volctl *x = (t_volctl *)pd_new(volctl_class); - inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("f1")); + inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("f1")); inlet_settip(x->x_obj.ob_inlet,gensym("factor")); x->x_value = atom_getfloatarg(0, argc, argv); @@ -62,13 +62,22 @@ void *volctl_new(t_symbol *s, int argc, t_atom *argv) inlet_settip(time,gensym("interpolation_time")); x->x_h = atom_getfloatarg(1, argc, argv); - x->x_mspersample = 1000.f / 44100; // assume default samplerate + x->x_samples_per_ms = 44100.f / 1000.f; // assume default samplerate outlet_new(&x->x_obj, &s_signal); x->x_f = 0; + + x->x_slopes = getalignedbytes(4*sizeof(t_float)); + return (x); } +static void volctl_free(t_volctl *x) +{ + freealignedbytes(x->x_slopes, 4*sizeof(t_float)); +} + + t_int *volctl_perform(t_int *w) { t_volctl * x = (t_volctl *)(w[1]); @@ -76,40 +85,40 @@ t_int *volctl_perform(t_int *w) t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - float f = x->x_value; + t_float f = x->x_value; if (x->x_ticksleft) { - float x_slope = x->x_slope; - if (x->x_ticksleft < n) - { - int remain = x->x_ticksleft; - n-=remain; - while (remain--) - { - f+=x_slope; - *out++ = *in++ * f; - } - while (n--) - { - *out++ = *in++ * f; - } - x->x_value = f; - x->x_ticksleft = 0; - } - else - { - x->x_ticksleft -=n; - while (n--) - { - f+=x_slope; - *out++ = *in++ * f; - } - x->x_value = f; - } + t_float x_slope = x->x_slope; + if (x->x_ticksleft < n) + { + int remain = x->x_ticksleft; + n-=remain; + while (remain--) + { + f+=x_slope; + *out++ = *in++ * f; + } + while (n--) + { + *out++ = *in++ * f; + } + x->x_value = f; + x->x_ticksleft = 0; + } + else + { + x->x_ticksleft -=n; + while (n--) + { + f+=x_slope; + *out++ = *in++ * f; + } + x->x_value = f; + } } else - while (n--) *out++ = *in++ * f; + while (n--) *out++ = *in++ * f; return (w+5); } @@ -122,48 +131,63 @@ t_int *volctl_perf8(t_int *w) t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - float f = x->x_value; + t_float f = x->x_value; if (x->x_ticksleft) { - float x_slope = x->x_slope; - if (x->x_ticksleft < n) - { - int remain = x->x_ticksleft; - n-=remain; - while (remain--) - { - *out++ = *in++ * f; - f+=x_slope; - } - while (n--) - { - *out++ = *in++ * f; - } - x->x_value = f; - x->x_ticksleft = 0; - } - else - { - x->x_ticksleft -= n; - while (n--) - { - *out++ = *in++ * f; - f+=x_slope; - } - x->x_value = f; - } + t_float x_slope = x->x_slope; + if (x->x_ticksleft < n) + { + int remain = x->x_ticksleft; + n-=remain; + while (remain--) + { + *out++ = *in++ * f; + f+=x_slope; + } + while (n--) + { + *out++ = *in++ * f; + } + x->x_value = f; + x->x_ticksleft = 0; + } + else + { + x->x_ticksleft -= n; + n = n>>3; + while (n--) + { + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + } + x->x_value = f; + } } else { - for (; n; n -= 8, in += 8, out += 8) - { - float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + for (; n; n -= 8, in += 8, out += 8) + { + t_float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + t_float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - out[0] = f0 * f; out[1] = f1 * f; out[2] = f2 * f; out[3] = f3 * f; - out[4] = f4 * f; out[5] = f5 * f; out[6] = f6 * f; out[7] = f7 * f; - } + out[0] = f0 * f; out[1] = f1 * f; out[2] = f2 * f; out[3] = f3 * f; + out[4] = f4 * f; out[5] = f5 * f; out[6] = f6 * f; out[7] = f7 * f; + } } return (w+5); } @@ -176,67 +200,106 @@ t_int *volctl_perf_simd(t_int *w) if (x->x_ticksleft) { - int n = (int)(w[4]); + int n = (int)(w[4]); - float f = x->x_value; + t_float x_slope = x->x_slope; + if (x->x_ticksleft < n) + { + t_float f = x->x_value; + + int remain = x->x_ticksleft; + n-=remain; + while (remain--) + { + *out++ = *in++ * f; + f+=x_slope; + } + while (n--) + { + *out++ = *in++ * f; + } + x->x_value = f; + x->x_ticksleft = 0; + } + else + { + x->x_ticksleft -= n; + + asm( + ".set T_FLOAT,4 \n" + "movss (%3),%%xmm0 \n" /* value */ + "shufps $0, %%xmm0, %%xmm0 \n" + "movaps (%4), %%xmm1 \n" /* x_slopes */ + "addps %%xmm0, %%xmm1 \n" - float x_slope = x->x_slope; - if (x->x_ticksleft < n) - { - int remain = x->x_ticksleft; - n-=remain; - while (remain--) - { - *out++ = *in++ * f; - f+=x_slope; - } - while (n--) - { - *out++ = *in++ * f; - } - x->x_value = f; - x->x_ticksleft = 0; - } - else - { - x->x_ticksleft -= n; - while (n--) - { - *out++ = *in++ * f; - f+=x_slope; - } - x->x_value = f; - } + "movss (%5), %%xmm0 \n" + "shufps $0, %%xmm0, %%xmm0 \n" /* x_slope_step */ + + "shrl $4, %2 \n" /* n>>4 */ + + "1: \n" + "movaps (%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, (%1) \n" + "addps %%xmm0, %%xmm1 \n" + + "movaps 4*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, 4*T_FLOAT(%1) \n" + "addps %%xmm0, %%xmm1 \n" + + "movaps 8*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, 8*T_FLOAT(%1) \n" + "addps %%xmm0, %%xmm1 \n" + + "movaps 12*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, 12*T_FLOAT(%1) \n" + "addps %%xmm0, %%xmm1 \n" /* one instr. obsolete */ + + "addl $16*T_FLOAT, %0 \n" + "addl $16*T_FLOAT, %1 \n" + "loop 1b \n" + + : + :"r"(in), "r"(out), "c"(n), "r"(&(t_float)(x->x_value)), + "r"((t_float*)x->x_slopes), "r"(&(t_float)(x->x_slope_step)) + :"%xmm0", "%xmm1", "%xmm2"); + +/* post("value %f", x->x_value); */ + x->x_value += n*(x->x_slope); + } } else { - asm( - ".set T_FLOAT,4 \n" - - "movss (%3), %%xmm0 \n" - "shufps $0, %%xmm0, %%xmm0 \n" - "shrl $4, %2 \n" - - "volctl_loop: \n" - "movaps (%0), %%xmm1 \n" - "mulps %%xmm0, %%xmm1 \n" - "movaps %%xmm1, (%1) \n" - "movaps 4*T_FLOAT(%0), %%xmm2 \n" - "mulps %%xmm0, %%xmm2 \n" - "movaps %%xmm2, 4*T_FLOAT(%1) \n" - "movaps 8*T_FLOAT(%0), %%xmm3 \n" - "mulps %%xmm0, %%xmm3 \n" - "movaps %%xmm3, 8*T_FLOAT(%1) \n" - "movaps 12*T_FLOAT(%0), %%xmm4 \n" - "mulps %%xmm0, %%xmm4 \n" - "movaps %%xmm4, 12*T_FLOAT(%1) \n" - "addl $64, %0 \n" - "addl $64, %1 \n" - "loop volctl_loop \n" - : - : "r"(in), "r"(out), - "a"(w[4]),"r"(&(x->x_value)) - : "%xmm0","%xmm1","%xmm2","%xmm3","%xmm4"); + asm( + ".set T_FLOAT,4 \n" + + "movss (%3), %%xmm0 \n" + "shufps $0, %%xmm0, %%xmm0 \n" + "shrl $4, %2 \n" + + "volctl_loop: \n" + "movaps (%0), %%xmm1 \n" + "mulps %%xmm0, %%xmm1 \n" + "movaps %%xmm1, (%1) \n" + "movaps 4*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm0, %%xmm2 \n" + "movaps %%xmm2, 4*T_FLOAT(%1) \n" + "movaps 8*T_FLOAT(%0), %%xmm3 \n" + "mulps %%xmm0, %%xmm3 \n" + "movaps %%xmm3, 8*T_FLOAT(%1) \n" + "movaps 12*T_FLOAT(%0), %%xmm4 \n" + "mulps %%xmm0, %%xmm4 \n" + "movaps %%xmm4, 12*T_FLOAT(%1) \n" + "addl $16*T_FLOAT, %0 \n" + "addl $16*T_FLOAT, %1 \n" + "loop volctl_loop \n" + : + : "r"(in), "r"(out), + "c"(w[4]),"r"(&(t_float)(x->x_value)) + : "%xmm0", "%xmm1","%xmm2","%xmm3","%xmm4"); } return (w+5); } @@ -244,8 +307,18 @@ t_int *volctl_perf_simd(t_int *w) void volctl_set(t_volctl *x, t_float f) { - x->x_ticksleft = x->x_h / x->x_mspersample; - x->x_slope = (f - x->x_value) / x->x_ticksleft; + t_float slope; + int i; + + x->x_ticksleft = x->x_h * x->x_samples_per_ms; + slope = (f - x->x_value) / x->x_ticksleft; + x->x_slope = slope; + + for (i = 0; i != 4; ++i) + { + x->x_slopes[i] = i*slope; + } + x->x_slope_step = 4*slope; } void volctl_dsp(t_volctl *x, t_signal **sp) @@ -255,18 +328,18 @@ void volctl_dsp(t_volctl *x, t_signal **sp) dsp_add(volctl_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); else { - if(SIMD_CHECK2(n,sp[0]->s_vec,sp[1]->s_vec)) - dsp_add(volctl_perf_simd, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); - else - dsp_add(volctl_perf8, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); + if(SIMD_CHECK2(n,sp[0]->s_vec,sp[1]->s_vec)) + dsp_add(volctl_perf_simd, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); + else + dsp_add(volctl_perf8, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); } - x->x_mspersample = 1000.f / sp[0]->s_sr; + x->x_samples_per_ms = sp[0]->s_sr / 1000.f; } void volctl_tilde_setup(void) { - volctl_class = class_new(gensym("volctl~"), (t_newmethod)volctl_new, 0, - sizeof(t_volctl), 0, A_GIMME, 0); + volctl_class = class_new(gensym("volctl~"), (t_newmethod)volctl_new, + (t_method)volctl_free, sizeof(t_volctl), 0, A_GIMME, 0); CLASS_MAINSIGNALIN(volctl_class, t_volctl, x_f); class_addmethod(volctl_class, (t_method)volctl_dsp, gensym("dsp"), 0); class_addmethod(volctl_class, (t_method)volctl_set, gensym("f1"),A_FLOAT,0); -- cgit v1.2.1 From 2a0d532e5965402f19f74f70dfdcc7efd1055b15 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 1 Jan 2005 11:06:58 +0000 Subject: speedup using function pointers svn path=/trunk/externals/tb/; revision=2439 --- chaos/src/Makefile.am | 1 + chaos/src/bernoulli_map.hpp | 2 +- chaos/src/bungalow_tent_map.hpp | 2 +- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 17 +++++- chaos/src/chaos_dsp.hpp | 70 ++++++++++++------------ chaos/src/chaos_msg.hpp | 2 +- chaos/src/chua.hpp | 109 ++++++++++++++++++++++++++++++++++++++ chaos/src/chua_dsp.cpp | 24 +++++++++ chaos/src/chua_msg.cpp | 24 +++++++++ chaos/src/circle_map.hpp | 2 +- chaos/src/coupled_logistic.hpp | 2 +- chaos/src/gauss_map.hpp | 2 +- chaos/src/henon_map.hpp | 2 +- chaos/src/henon_map_dsp.cpp | 2 +- chaos/src/henon_map_msg.cpp | 2 +- chaos/src/ikeda_laser_map.hpp | 2 +- chaos/src/ikeda_laser_map_dsp.cpp | 2 +- chaos/src/ikeda_laser_map_msg.cpp | 2 +- chaos/src/logistic_map.hpp | 14 +++-- chaos/src/lozi_map.hpp | 2 +- chaos/src/lozi_map_dsp.cpp | 2 +- chaos/src/lozi_map_msg.cpp | 2 +- chaos/src/main.cpp | 1 + chaos/src/map_base.hpp | 5 +- chaos/src/ode_base.cpp | 16 ------ chaos/src/ode_base.hpp | 20 ++++++- chaos/src/roessler.hpp | 1 + chaos/src/sine_map.hpp | 2 +- chaos/src/standard_map.hpp | 2 +- chaos/src/tent_map.hpp | 23 ++++---- chaos/src/tent_map_dsp.cpp | 2 +- chaos/src/tent_map_msg.cpp | 2 +- 33 files changed, 273 insertions(+), 91 deletions(-) create mode 100644 chaos/src/chua.hpp create mode 100644 chaos/src/chua_dsp.cpp create mode 100644 chaos/src/chua_msg.cpp diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index cbaa287..213e313 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -5,6 +5,7 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ circle_map_dsp.cpp circle_map_msg.cpp \ coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ + chua_dsp.cpp chua_msg.cpp \ driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ duffing_map_dsp.cpp duffing_map_msg.cpp \ diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 25d19f8..821f24f 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -31,7 +31,7 @@ public: bernoulli() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0.5); } diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 185753a..0dfe709 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -39,7 +39,7 @@ public: bungalow_tent() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x, 0.6); CHAOS_SYS_INIT(r, 0.5); } diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 231ecdc..a1a3467 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -24,6 +24,7 @@ #include "flext.h" #include "chaos_defs.hpp" +#include /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index ce6fc11..a2072d0 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -36,16 +36,31 @@ public: return m_num_eq; } - virtual void m_step() + void m_perform() { + m_step(); + m_verify(); } + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0; +#endif + } + }; + data_t * m_data; // state of the system protected: + virtual void m_step(); int m_num_eq; // number of equations of the system }; + #define CHAOS_CALLBACKS \ public: \ void get_dimension(int &i) \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index c2f78b3..9704432 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -37,13 +37,17 @@ public: /* cubic interpolatio */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); - virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs); + virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs) + { + (this->*m_routine)(n,insigs,outsigs); + } virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) { m_sr = Samplerate(); } - + + void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); /* local data for system, output and interpolation */ system * m_system; /* the system */ @@ -57,12 +61,13 @@ public: /* local data for signal functions */ float m_freq; /* frequency of oscillations */ + float m_invfreq; /* inverse frequency */ int m_phase; /* phase counter */ float m_sr; /* sample rate */ int m_imethod; /* interpolation method */ - int get_imethod(int &i) + void get_imethod(int &i) { i = m_imethod; } @@ -70,7 +75,21 @@ public: void set_imethod(int i) { if( (i >= 0) && (i <= 2) ) + { m_imethod = i; + switch (i) + { + case 0: + m_routine = &thisType::m_signal_n; + break; + case 1: + m_routine = &thisType::m_signal_l; + break; + case 2: + m_routine = &thisType::m_signal_c; + break; + } + } else { post("interpolation method out of range"); @@ -88,7 +107,7 @@ public: } - int get_freq(float &f) + void get_freq(float &f) { f = m_freq; } @@ -96,7 +115,10 @@ public: void set_freq(float f) { if( (f >= 0) && (f <= m_sr*0.5) ) + { m_freq = f; + m_invfreq = 1.f / f; + } else post("frequency out of range"); } @@ -112,7 +134,7 @@ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ \ SYSTEM##_dsp(int argc, t_atom* argv ) \ { \ - m_sr = 44100; /* assume default sampling rate (for max frequency) */ \ + m_sr = 44100; /* assume default sampling rate */ \ m_system = new SYSTEM; \ \ int size = m_system->get_num_eq(); \ @@ -175,30 +197,6 @@ FLEXT_ATTRVAR_I(m_imethod); -template -void chaos_dsp::m_signal(int n, t_sample *const *insigs, - t_sample *const *outsigs) -{ - if (m_freq >= m_sr * 0.5) - { - m_signal_(n, insigs, outsigs); - return; - } - - switch (m_imethod) - { - case 0: - m_signal_n(n, insigs, outsigs); - return; - case 1: - m_signal_l(n, insigs, outsigs); - return; - case 2: - m_signal_c(n, insigs, outsigs); - return; - } -} - template void chaos_dsp::m_signal_(int n, t_sample *const *insigs, t_sample *const *outsigs) @@ -207,7 +205,7 @@ void chaos_dsp::m_signal_(int n, t_sample *const *insigs, for (int i = 0; i!=n; ++i) { - m_system->m_step(); + m_system->m_perform(); for (int j = 0; j != outlets; ++j) { outsigs[j][i] = m_system->get_data(j); @@ -230,8 +228,8 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_step(); - phase = int (m_sr / m_freq); + m_system->m_perform(); + phase = int (m_sr * m_invfreq); } int next = (phase < n) ? phase : n; @@ -266,8 +264,8 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_step(); - phase = int (m_sr / m_freq); + m_system->m_perform(); + phase = int (m_sr * m_invfreq); for (int j = 0; j != outlets; ++j) m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; @@ -305,8 +303,8 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_step(); - phase = int (m_sr / m_freq); + m_system->m_perform(); + phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; for (int j = 0; j != outlets; ++j) diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 78bca06..3f80101 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -32,7 +32,7 @@ public: void m_bang() { - m_system->m_step(); + m_system->m_perform(); int outlets = m_system->get_num_eq(); while (outlets--) diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp new file mode 100644 index 0000000..a5db1cb --- /dev/null +++ b/chaos/src/chua.hpp @@ -0,0 +1,109 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// chua system: dx1/dt = alpha * (x2 - x1 - h(x1)) +// dx2/dt = x1 - x2 + x3 +// dx3/dt = - beta * x2 +// +// with h(x) = b*x + a - b (for x > 1) +// a*x (for -1 <= x <= 1 +// b*x - a + b (for x < -1) +// +// taken from Viktor Avrutin: lecture note + +class chua: + public ode_base +{ +public: + chua() + { + m_num_eq = 3; + m_data = new data_t[m_num_eq]; + CHAOS_SYS_INIT(x1,1); + CHAOS_SYS_INIT(x2,1); + CHAOS_SYS_INIT(x3,1); + CHAOS_SYS_INIT(a,1.4); + CHAOS_SYS_INIT(b,0.3); + CHAOS_SYS_INIT(alpha,0.3); + CHAOS_SYS_INIT(beta,0.3); + + ode_base_alloc(); + } + + ~chua() + { + ode_base_free(); + delete m_data; + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0]; + data_t x2 = data[1]; + data_t x3 = data[2]; + + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + + data_t h; + + if (x1 > 1) + h = b*x1 + a - b; + else if (x1 < -1) + h = b*x1 - a + b; + else + h = a*x1; + + deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h); + deriv[1] = x1 - x2 + x3; + deriv[2] = - CHAOS_PARAMETER(beta) * x2; + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(alpha); + CHAOS_SYSPAR_FUNCS(beta); +}; + + +#define CHUA_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(beta); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(x3); + +#define CHUA_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(beta); \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(x3); diff --git a/chaos/src/chua_dsp.cpp b/chaos/src/chua_dsp.cpp new file mode 100644 index 0000000..6ae151c --- /dev/null +++ b/chaos/src/chua_dsp.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chua.hpp" +#include "chaos_dsp.hpp" + +CHAOS_DSP_CLASS(chua,CHUA); diff --git a/chaos/src/chua_msg.cpp b/chaos/src/chua_msg.cpp new file mode 100644 index 0000000..b00aa7f --- /dev/null +++ b/chaos/src/chua_msg.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chua.hpp" +#include "chaos_msg.hpp" + +CHAOS_MSG_CLASS(chua,CHUA); diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 0e12ad0..91f11d6 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -33,7 +33,7 @@ public: circle_map() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(omega, 0.1); CHAOS_SYS_INIT(r, 3); CHAOS_SYS_INIT(x, 0.4); diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index eb5b326..85b6928 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -32,7 +32,7 @@ public: coupled_logistic() { m_num_eq = 2; - m_data = new data_t[2]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(e, 0.06); CHAOS_SYS_INIT(r, 3.7); CHAOS_SYS_INIT(x, 0.1); diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 523b1ca..4d62654 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -34,7 +34,7 @@ public: gauss_map() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0.5); } diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 9e379ae..b43034a 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -32,7 +32,7 @@ public: henon() { m_num_eq = 2; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0); CHAOS_SYS_INIT(y,0); diff --git a/chaos/src/henon_map_dsp.cpp b/chaos/src/henon_map_dsp.cpp index f7e6103..7d73412 100644 --- a/chaos/src/henon_map_dsp.cpp +++ b/chaos/src/henon_map_dsp.cpp @@ -21,4 +21,4 @@ #include "henon_map.hpp" #include "chaos_dsp.hpp" -CHAOS_DSP_CLASS_NAME(henon, HENON, "henon~"); +CHAOS_DSP_CLASS_NAME(henon, HENON, henon~); diff --git a/chaos/src/henon_map_msg.cpp b/chaos/src/henon_map_msg.cpp index 22cddde..e70624f 100644 --- a/chaos/src/henon_map_msg.cpp +++ b/chaos/src/henon_map_msg.cpp @@ -21,4 +21,4 @@ #include "henon_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(henon, HENON, "henon"); +CHAOS_MSG_CLASS_NAME(henon, HENON, henon); diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index e267204..c62bc15 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -38,7 +38,7 @@ public: ikeda_laser_map() { m_num_eq = 2; - m_data = new data_t[2]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(c1,0.4); CHAOS_SYS_INIT(c2,0.9); CHAOS_SYS_INIT(c3,9); diff --git a/chaos/src/ikeda_laser_map_dsp.cpp b/chaos/src/ikeda_laser_map_dsp.cpp index ea18e21..fe2339b 100644 --- a/chaos/src/ikeda_laser_map_dsp.cpp +++ b/chaos/src/ikeda_laser_map_dsp.cpp @@ -22,5 +22,5 @@ #include "chaos_dsp.hpp" -CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda"); +CHAOS_DSP_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, ikeda~); diff --git a/chaos/src/ikeda_laser_map_msg.cpp b/chaos/src/ikeda_laser_map_msg.cpp index 1659159..e1c318d 100644 --- a/chaos/src/ikeda_laser_map_msg.cpp +++ b/chaos/src/ikeda_laser_map_msg.cpp @@ -21,4 +21,4 @@ #include "ikeda_laser_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, "ikeda~"); +CHAOS_MSG_CLASS_NAME(ikeda_laser_map, IKEDA_LASER_MAP, ikeda); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 1808baa..ef2f603 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -21,7 +21,7 @@ #include "map_base.hpp" // logistic map: x[n+1] = alpha * x[n] * (1 - x[n]) -// 0 <= x[n] < 1 +// 0 < x[n] < 1 // 0 <= alpha <= 4 class logistic: @@ -43,9 +43,9 @@ public: virtual void m_step() { - data_t data = m_data[0]; + data_t x = m_data[0]; data_t alpha = CHAOS_PARAMETER(alpha); - m_data[0] = alpha * data * (1.f - data); + m_data[0] = alpha * x * (1.f - x); } CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); @@ -60,6 +60,14 @@ public: { return (f > 0) && (f < 1); } + + virtual void m_verify() + { + data_t x = m_data[0]; + if (m_pred_x(x)) + return; + m_data[0] = 0.5; + } }; #define LOGISTIC_CALLBACKS \ diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 37cab54..9219390 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -32,7 +32,7 @@ public: lozi_map() { m_num_eq = 2; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0); CHAOS_SYS_INIT(y,0); CHAOS_SYS_INIT(a,1.4); diff --git a/chaos/src/lozi_map_dsp.cpp b/chaos/src/lozi_map_dsp.cpp index 0448412..06c603d 100644 --- a/chaos/src/lozi_map_dsp.cpp +++ b/chaos/src/lozi_map_dsp.cpp @@ -21,4 +21,4 @@ #include "lozi_map.hpp" #include "chaos_dsp.hpp" -CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); +CHAOS_DSP_CLASS_NAME(lozi_map, LOZI_MAP, lozi~); diff --git a/chaos/src/lozi_map_msg.cpp b/chaos/src/lozi_map_msg.cpp index 099cbec..719cf61 100644 --- a/chaos/src/lozi_map_msg.cpp +++ b/chaos/src/lozi_map_msg.cpp @@ -21,4 +21,4 @@ #include "lozi_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, "lozi"); +CHAOS_MSG_CLASS_NAME(lozi_map, LOZI_MAP, lozi); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index eabb8d4..dcb7ea8 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -29,6 +29,7 @@ void chaos_library_setup() CHAOS_ADD(bungalow_tent); CHAOS_ADD(circle_map); CHAOS_ADD(coupled_logistic); + CHAOS_ADD(chua); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); CHAOS_ADD(duffing_map); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index c88f9ba..e71fe61 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -26,7 +26,10 @@ class map_base : public chaos_base { - +protected: + virtual void m_step() + { + } }; #define MAP_CALLBACKS \ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index 9665d83..2830c2f 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -72,19 +72,3 @@ void ode_base::rk4() / 6.; } -void ode_base::m_step() -{ - switch (m_method) - { - case 0: - rk1(); - break; - case 1: - rk2(); - break; - case 2: - rk4(); - break; - } - -} diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index cc526ae..a15dc08 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -30,7 +30,20 @@ public: void set_method(int i) { if (i >=0 && i <4) + { m_method = (unsigned char) i; + switch (i) + { + case 0: + m_routine = &ode_base::rk1; + break; + case 1: + m_routine = &ode_base::rk2; + break; + case 2: + m_routine = &ode_base::rk4; + } + } else post("no such method"); } @@ -47,7 +60,10 @@ public: return (f >= 0); } - virtual void m_step(); + virtual void m_step() + { + (this->*m_routine)(); + } void ode_base_alloc() { @@ -67,11 +83,11 @@ public: { delete m_k[i]; } - delete m_tmp; } protected: + void (ode_base::*m_routine)(); unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ data_t* m_k[3]; /* temporary arrays for runge kutta */ diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index 85272ee..4b36666 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -41,6 +41,7 @@ public: CHAOS_SYS_INIT(a,4); CHAOS_SYS_INIT(b,4); CHAOS_SYS_INIT(c,4); + CHAOS_SYS_INIT(dt,0.01); ode_base_alloc(); } diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 376a245..8746345 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -33,7 +33,7 @@ public: sine_map() { m_num_eq = 1; - m_data = new data_t[1]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(x,0); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index c0f0b8d..cadcf1e 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -33,7 +33,7 @@ public: standard_map() { m_num_eq = 2; - m_data = new data_t[2]; + m_data = new data_t[m_num_eq]; CHAOS_SYS_INIT(I,0.1); CHAOS_SYS_INIT(theta,0.2); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 9ab59ec..8c00a19 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -20,10 +20,10 @@ #include "map_base.hpp" -// tent map: x[n+1] = 2 * x[n] (for 0 < x <= 0.5) -// 2 * (1 - x[n]) (else) -// 0 <= x[n] < 1 -// taken from Willi-Hans Steeb: Chaos and Fractals +// tent map: x[n+1] = 1 - 2*abs(x[n]) +// -1 < x[n] < 1 +// taken from Julien C. Sprott, Strange Attractors: Creating Patterns in Chaos + class tent_map: public map_base @@ -32,8 +32,8 @@ public: tent_map() { m_num_eq = 1; - m_data = new data_t[1]; - CHAOS_SYS_INIT(x, 0.5); + m_data = new data_t[m_num_eq]; + CHAOS_SYS_INIT(x, 0.6); } ~tent_map() @@ -44,17 +44,14 @@ public: virtual void m_step() { data_t data = m_data[0]; - - if (data < 0.5f) - m_data[0] = 2.f * data; - else - m_data[0] = 2.f * (1.f - data); + + m_data[0] = 1 - 2*CHAOS_ABS(data); } - CHAOS_SYSPAR_FUNCS_PRED(x, m_pred_x); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f) { - return (f >= 0) && (f < 1); + return (f > -1) && (f < 1); } }; diff --git a/chaos/src/tent_map_dsp.cpp b/chaos/src/tent_map_dsp.cpp index 44c909d..0abf7d5 100644 --- a/chaos/src/tent_map_dsp.cpp +++ b/chaos/src/tent_map_dsp.cpp @@ -23,4 +23,4 @@ -CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, "tent~"); +CHAOS_DSP_CLASS_NAME(tent_map, TENT_MAP, tent~); diff --git a/chaos/src/tent_map_msg.cpp b/chaos/src/tent_map_msg.cpp index 3da82ab..b2d5d8d 100644 --- a/chaos/src/tent_map_msg.cpp +++ b/chaos/src/tent_map_msg.cpp @@ -21,4 +21,4 @@ #include "tent_map.hpp" #include "chaos_msg.hpp" -CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, "tent"); +CHAOS_MSG_CLASS_NAME(tent_map, TENT_MAP, tent); -- cgit v1.2.1 From 4d68d5d045b975d50adba6bf40fa63264a7224b9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 3 Jan 2005 18:01:32 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2456, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=2457 --- detach/README | 4 + detach/detach.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ detach/makefile | 94 +++++++++++++++++++++ join/README | 6 ++ join/join.c | 155 ++++++++++++++++++++++++++++++++++ join/makefile | 94 +++++++++++++++++++++ 6 files changed, 605 insertions(+) create mode 100644 detach/README create mode 100644 detach/detach.c create mode 100644 detach/makefile create mode 100644 join/README create mode 100644 join/join.c create mode 100644 join/makefile diff --git a/detach/README b/detach/README new file mode 100644 index 0000000..1cdc041 --- /dev/null +++ b/detach/README @@ -0,0 +1,4 @@ +the message to the inlet will be sent to the outlet, but all +functions called as result of this message run in a helper thread. + +requirement: pd>=devel_0_38 \ No newline at end of file diff --git a/detach/detach.c b/detach/detach.c new file mode 100644 index 0000000..67c4b1e --- /dev/null +++ b/detach/detach.c @@ -0,0 +1,252 @@ +/* +* +* detatch +* Copyright (C) 2005 Tim Blechmann +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; see the file COPYING. If not, write to +* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 02111-1307, USA. +*/ + +#include "m_pd.h" +#include "m_fifo.h" + +#include "pthread.h" + + +static t_class *detatch_class; + +typedef t_fifo fifo_t; /* for emacs syntax highlighting */ + +typedef struct _detatch +{ + t_object x_obj; + + t_outlet * x_outlet; + + pthread_t x_thread; + pthread_mutex_t x_mutex; + pthread_cond_t x_cond; + + fifo_t * x_fifo; + +} detatch_t; + +typedef struct _detatch_content +{ + enum { BANG, + POINTER, + FLOAT, + SYMBOL, + LIST, + ANYTHING, + CANCEL} type; + int argc; + t_atom * argv; +} detatch_content_t; + + +static void detatch_thread(detatch_t* x) +{ + detatch_content_t * me; + while(1) + { + pthread_cond_wait(&x->x_cond, &x->x_mutex); + + me = (detatch_content_t*) fifo_get(x->x_fifo); + + while (me != NULL) + { + /* run function */ + switch (me->type) + { + case BANG: + outlet_bang(x->x_outlet); + break; + case FLOAT: + outlet_float(x->x_outlet, atom_getfloat(me->argv)); + break; + case SYMBOL: + outlet_symbol(x->x_outlet, atom_getsymbol(me->argv)); + break; + case LIST: + outlet_list(x->x_outlet, 0, me->argc, me->argv); + freebytes(me->argv, me->argc * sizeof(t_atom)); + break; + case ANYTHING: + outlet_anything(x->x_outlet, 0, me->argc, me->argv); + freebytes(me->argv, me->argc * sizeof(t_atom)); + break; + case CANCEL: + goto done; + + } + + /* free */ + if (me->argc) + freebytes(me->argv, me->argc * sizeof (t_atom)); + freebytes (me, sizeof(detatch_content_t)); + + me = (detatch_content_t*) fifo_get(x->x_fifo); + } + } + + done: /* free the fifo and exit */ + + do + { + if (me->argc) + freebytes(me->argv, me->argc * sizeof (t_atom)); + freebytes (me, sizeof(detatch_content_t)); + } + while (me = (detatch_content_t*) fifo_get(x->x_fifo)); + + fifo_destroy(x->x_fifo); + return; +} + +/* todo: take argument for thread priority */ +static detatch_t * detatch_new(void) +{ + detatch_t *x = (detatch_t*) pd_new(detatch_class); + pthread_attr_t thread_attr; + struct sched_param thread_sched; + int status; + + x->x_outlet = outlet_new(&x->x_obj, NULL); + x->x_fifo = fifo_init(); + + /* thread initialisation */ + pthread_mutex_init (&x->x_mutex,NULL); + pthread_mutex_unlock (&x->x_mutex); + pthread_cond_init (&x->x_cond,NULL); + + pthread_attr_init(&thread_attr); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING + thread_sched.sched_priority=sched_get_priority_min(SCHED_OTHER); + pthread_attr_setschedparam(&thread_attr,&thread_sched); +#endif + status = pthread_create(&x->x_thread, &thread_attr, + (void*)detatch_thread, x); + +#if 1 + if (status == 0) + post("detatching thread"); +#endif + return x; +} + + +static void detatch_free(detatch_t * x) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = CANCEL; + me->argc = 0; + fifo_put(x->x_fifo, me); + pthread_cond_broadcast(&x->x_cond); +} + + +static void detatch_bang(detatch_t * x) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = BANG; + me->argc = 0; + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + + +static void detatch_float(detatch_t * x, t_float f) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = FLOAT; + me->argc = 1; + me->argv = getbytes(sizeof(t_atom)); + SETFLOAT(me->argv, f); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + +static void detatch_pointer(detatch_t * x, t_gpointer* gp) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = POINTER; + me->argc = 1; + me->argv = getbytes(sizeof(t_atom)); + SETPOINTER(me->argv, gp); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + +static void detatch_symbol(detatch_t * x, t_symbol * s) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = SYMBOL; + me->argc = 1; + me->argv = getbytes(sizeof(t_atom)); + SETSYMBOL(me->argv, s); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + + +static void detatch_list(detatch_t * x, t_symbol * s, + int argc, t_atom* argv) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = LIST; + me->argc = argc; + me->argv = copybytes(argv, argc * sizeof(t_atom)); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + +static void detatch_anything(detatch_t * x, t_symbol * s, + int argc, t_atom* argv) +{ + detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + + me->type = ANYTHING; + me->argc = argc; + me->argv = copybytes(argv, argc * sizeof(t_atom)); + fifo_put(x->x_fifo, me); + + pthread_cond_broadcast(&x->x_cond); +} + + +void detatch_setup(void) +{ + detatch_class = class_new(gensym("detatch"), (t_newmethod)detatch_new, + (t_method)detatch_free, sizeof(detatch_t), + CLASS_DEFAULT, 0); + class_addbang(detatch_class, detatch_bang); + class_addfloat(detatch_class, detatch_float); + class_addpointer(detatch_class, detatch_pointer); + class_addsymbol(detatch_class, detatch_symbol); + class_addlist(detatch_class, detatch_list); + class_addanything(detatch_class, detatch_anything); +} diff --git a/detach/makefile b/detach/makefile new file mode 100644 index 0000000..7a578d6 --- /dev/null +++ b/detach/makefile @@ -0,0 +1,94 @@ +NAME=detatch +CSYM=detatch + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations diff --git a/join/README b/join/README new file mode 100644 index 0000000..5175792 --- /dev/null +++ b/join/README @@ -0,0 +1,6 @@ +the message to the inlet will be sent to the outlet during the +next idle callback of the scheduler. it doesn't matter, which thread the +message was coming from. messages from the main pd thread will be +rescheduled. + +requirement: pd>=devel_0_38 \ No newline at end of file diff --git a/join/join.c b/join/join.c new file mode 100644 index 0000000..fd7b5ad --- /dev/null +++ b/join/join.c @@ -0,0 +1,155 @@ +/* +* +* detatch +* Copyright (C) 2005 Tim Blechmann +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; see the file COPYING. If not, write to +* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 02111-1307, USA. +*/ + +#include "m_pd.h" + +static t_class *join_class; + +typedef struct _join +{ + t_object x_obj; + t_outlet * x_outlet; +} join_t; + + +static join_t * join_new(void) +{ + join_t *x = (join_t*) pd_new(join_class); + + x->x_outlet = outlet_new(&x->x_obj, NULL); + return x; +} + + +static t_int join_bang_callback(t_int * argv) +{ + outlet_bang((t_outlet*)argv[0]); + return 0; +} + +static void join_bang(join_t * x) +{ + t_int* argv = getbytes(sizeof(t_int*)); + argv[0] = (t_int)x->x_outlet; + set_callback(join_bang_callback, argv, 1); +} + + +static t_int join_pointer_callback(t_int * argv) +{ + outlet_pointer((t_outlet*)argv[0], (t_gpointer*)argv[1]); + return 0; +} + +static void join_pointer(join_t * x, t_gpointer * gp) +{ + t_int* argv = getbytes(2*sizeof(t_int*)); + argv[0] = (t_int)x->x_outlet; + argv[1] = (t_int)gp; + + set_callback(join_pointer_callback, argv, 2); +} + + +static t_int join_float_callback(t_int * argv) +{ + outlet_float((t_outlet*)argv[0], (t_float)argv[1]); + return 0; +} + +static void join_float(join_t * x, t_float f) +{ + t_int* argv = getbytes(2*sizeof(t_int*)); + argv[0] = (t_int)x->x_outlet; + argv[1] = (t_int)f; + + set_callback(join_float_callback, argv, 2); +} + + +static t_int join_symbol_callback(t_int * argv) +{ + outlet_symbol((t_outlet*)argv[0], (t_symbol*)argv[1]); + return 0; +} + +static void join_symbol(join_t * x, t_symbol * s) +{ + t_int* argv = getbytes(2*sizeof(t_int*)); + argv[0] = (t_int)x->x_outlet; + argv[1] = (t_int)s; + + set_callback(join_symbol_callback, argv, 2); +} + +static t_int join_list_callback(t_int * argv) +{ + outlet_list((t_outlet*)argv[0], 0, (int)argv[1], (t_atom*)argv[2]); + freebytes ((t_atom*)argv[2], (int)argv[1] * sizeof(t_atom)); + return 0; +} + +static void join_list(join_t * x, t_symbol * s, int argc, t_atom* largv) +{ + t_int* argv = getbytes(3*sizeof(t_int*)); + t_atom* copied_argv = copybytes(largv, argc * sizeof(t_atom)); + + argv[0] = (t_int)x->x_outlet; + argv[1] = (t_int)argc; + argv[2] = (t_int)copied_argv; + + set_callback(join_list_callback, argv, 3); +} + + +static t_int join_anything_callback(t_int * argv) +{ + outlet_anything((t_outlet*)argv[0], &s_list, + (int)argv[1], (t_atom*)argv[2]); + freebytes ((t_atom*)argv[2], (int)argv[1] * sizeof(t_atom)); + return 0; +} + +static void join_anything(join_t * x, t_symbol * s, int argc, t_atom* largv) +{ + t_int* argv = getbytes(3*sizeof(t_int*)); + t_atom* copied_argv = copybytes(largv, argc * sizeof(t_atom)); + + argv[0] = (t_int)x->x_outlet; + argv[1] = (t_int)argc; + argv[2] = (t_int)copied_argv; + + set_callback(join_anything_callback, argv, 3); +} + + +void join_setup(void) +{ + join_class = class_new(gensym("join"), (t_newmethod)join_new, + NULL, sizeof(join_t), + CLASS_DEFAULT, 0); + class_addbang(join_class, join_bang); + class_addfloat(join_class, join_float); + class_addpointer(join_class, join_pointer); + class_addsymbol(join_class, join_symbol); + class_addlist(join_class, join_list); + class_addanything(join_class, join_anything); +} diff --git a/join/makefile b/join/makefile new file mode 100644 index 0000000..bcad613 --- /dev/null +++ b/join/makefile @@ -0,0 +1,94 @@ +NAME=join +CSYM=join + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From 37221809e95b99fdf73c39d73efc861875647fa1 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 6 Jan 2005 17:00:45 +0000 Subject: fixed spelling mistake svn path=/trunk/externals/tb/; revision=2468 --- detach/detach.c | 80 ++++++++++++++++++++++++++++----------------------------- detach/makefile | 4 +-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/detach/detach.c b/detach/detach.c index 67c4b1e..6460f6b 100644 --- a/detach/detach.c +++ b/detach/detach.c @@ -1,6 +1,6 @@ /* * -* detatch +* detach * Copyright (C) 2005 Tim Blechmann * * This program is free software; you can redistribute it and/or modify @@ -25,11 +25,11 @@ #include "pthread.h" -static t_class *detatch_class; +static t_class *detach_class; typedef t_fifo fifo_t; /* for emacs syntax highlighting */ -typedef struct _detatch +typedef struct _detach { t_object x_obj; @@ -41,9 +41,9 @@ typedef struct _detatch fifo_t * x_fifo; -} detatch_t; +} detach_t; -typedef struct _detatch_content +typedef struct _detach_content { enum { BANG, POINTER, @@ -54,17 +54,17 @@ typedef struct _detatch_content CANCEL} type; int argc; t_atom * argv; -} detatch_content_t; +} detach_content_t; -static void detatch_thread(detatch_t* x) +static void detach_thread(detach_t* x) { - detatch_content_t * me; + detach_content_t * me; while(1) { pthread_cond_wait(&x->x_cond, &x->x_mutex); - me = (detatch_content_t*) fifo_get(x->x_fifo); + me = (detach_content_t*) fifo_get(x->x_fifo); while (me != NULL) { @@ -96,9 +96,9 @@ static void detatch_thread(detatch_t* x) /* free */ if (me->argc) freebytes(me->argv, me->argc * sizeof (t_atom)); - freebytes (me, sizeof(detatch_content_t)); + freebytes (me, sizeof(detach_content_t)); - me = (detatch_content_t*) fifo_get(x->x_fifo); + me = (detach_content_t*) fifo_get(x->x_fifo); } } @@ -108,18 +108,18 @@ static void detatch_thread(detatch_t* x) { if (me->argc) freebytes(me->argv, me->argc * sizeof (t_atom)); - freebytes (me, sizeof(detatch_content_t)); + freebytes (me, sizeof(detach_content_t)); } - while (me = (detatch_content_t*) fifo_get(x->x_fifo)); + while (me = (detach_content_t*) fifo_get(x->x_fifo)); fifo_destroy(x->x_fifo); return; } /* todo: take argument for thread priority */ -static detatch_t * detatch_new(void) +static detach_t * detach_new(void) { - detatch_t *x = (detatch_t*) pd_new(detatch_class); + detach_t *x = (detach_t*) pd_new(detach_class); pthread_attr_t thread_attr; struct sched_param thread_sched; int status; @@ -138,19 +138,19 @@ static detatch_t * detatch_new(void) pthread_attr_setschedparam(&thread_attr,&thread_sched); #endif status = pthread_create(&x->x_thread, &thread_attr, - (void*)detatch_thread, x); + (void*)detach_thread, x); #if 1 if (status == 0) - post("detatching thread"); + post("detaching thread"); #endif return x; } -static void detatch_free(detatch_t * x) +static void detach_free(detach_t * x) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = CANCEL; me->argc = 0; @@ -159,9 +159,9 @@ static void detatch_free(detatch_t * x) } -static void detatch_bang(detatch_t * x) +static void detach_bang(detach_t * x) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = BANG; me->argc = 0; @@ -171,9 +171,9 @@ static void detatch_bang(detatch_t * x) } -static void detatch_float(detatch_t * x, t_float f) +static void detach_float(detach_t * x, t_float f) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = FLOAT; me->argc = 1; @@ -184,9 +184,9 @@ static void detatch_float(detatch_t * x, t_float f) pthread_cond_broadcast(&x->x_cond); } -static void detatch_pointer(detatch_t * x, t_gpointer* gp) +static void detach_pointer(detach_t * x, t_gpointer* gp) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = POINTER; me->argc = 1; @@ -197,9 +197,9 @@ static void detatch_pointer(detatch_t * x, t_gpointer* gp) pthread_cond_broadcast(&x->x_cond); } -static void detatch_symbol(detatch_t * x, t_symbol * s) +static void detach_symbol(detach_t * x, t_symbol * s) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = SYMBOL; me->argc = 1; @@ -211,10 +211,10 @@ static void detatch_symbol(detatch_t * x, t_symbol * s) } -static void detatch_list(detatch_t * x, t_symbol * s, +static void detach_list(detach_t * x, t_symbol * s, int argc, t_atom* argv) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = LIST; me->argc = argc; @@ -224,10 +224,10 @@ static void detatch_list(detatch_t * x, t_symbol * s, pthread_cond_broadcast(&x->x_cond); } -static void detatch_anything(detatch_t * x, t_symbol * s, +static void detach_anything(detach_t * x, t_symbol * s, int argc, t_atom* argv) { - detatch_content_t * me = getbytes(sizeof(detatch_content_t)); + detach_content_t * me = getbytes(sizeof(detach_content_t)); me->type = ANYTHING; me->argc = argc; @@ -238,15 +238,15 @@ static void detatch_anything(detatch_t * x, t_symbol * s, } -void detatch_setup(void) +void detach_setup(void) { - detatch_class = class_new(gensym("detatch"), (t_newmethod)detatch_new, - (t_method)detatch_free, sizeof(detatch_t), + detach_class = class_new(gensym("detach"), (t_newmethod)detach_new, + (t_method)detach_free, sizeof(detach_t), CLASS_DEFAULT, 0); - class_addbang(detatch_class, detatch_bang); - class_addfloat(detatch_class, detatch_float); - class_addpointer(detatch_class, detatch_pointer); - class_addsymbol(detatch_class, detatch_symbol); - class_addlist(detatch_class, detatch_list); - class_addanything(detatch_class, detatch_anything); + class_addbang(detach_class, detach_bang); + class_addfloat(detach_class, detach_float); + class_addpointer(detach_class, detach_pointer); + class_addsymbol(detach_class, detach_symbol); + class_addlist(detach_class, detach_list); + class_addanything(detach_class, detach_anything); } diff --git a/detach/makefile b/detach/makefile index 7a578d6..979bba0 100644 --- a/detach/makefile +++ b/detach/makefile @@ -1,5 +1,5 @@ -NAME=detatch -CSYM=detatch +NAME=detach +CSYM=detach current: pd_linux -- cgit v1.2.1 From a0e797de4a660aa2af4b309fe258fb287e3d38e1 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 8 Jan 2005 22:13:53 +0000 Subject: improvement for zero factor ... x * 0 = 0 svn path=/trunk/externals/tb/; revision=2482 --- volctl~/volctl~.c | 319 ++++++++++++++++++++++++++---------------------------- 1 file changed, 151 insertions(+), 168 deletions(-) diff --git a/volctl~/volctl~.c b/volctl~/volctl~.c index 60abfac..1a9e451 100644 --- a/volctl~/volctl~.c +++ b/volctl~/volctl~.c @@ -39,14 +39,16 @@ typedef struct _volctl t_float x_h; //interpolation time t_float x_value; //current factor + t_float x_target; //target factor - int x_ticksleft; //ticks to go + int x_ticksleft; //dsp ticks to go t_float x_samples_per_ms; //ms per sample t_float x_slope; //slope t_float * x_slopes; //slopes for simd t_float x_slope_step; int x_line; - + int x_blocksize; + t_float x_1overblocksize; } t_volctl; void *volctl_new(t_symbol *s, int argc, t_atom *argv) @@ -63,6 +65,8 @@ void *volctl_new(t_symbol *s, int argc, t_atom *argv) x->x_h = atom_getfloatarg(1, argc, argv); x->x_samples_per_ms = 44100.f / 1000.f; // assume default samplerate + x->x_blocksize = 64; + x->x_1overblocksize = 1.f/64.f; outlet_new(&x->x_obj, &s_signal); x->x_f = 0; @@ -77,122 +81,97 @@ static void volctl_free(t_volctl *x) freealignedbytes(x->x_slopes, 4*sizeof(t_float)); } - -t_int *volctl_perform(t_int *w) +static t_int *volctl_perform(t_int *w) { t_volctl * x = (t_volctl *)(w[1]); t_float *in = (t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - t_float f = x->x_value; if (x->x_ticksleft) { + t_float f = x->x_value; t_float x_slope = x->x_slope; - if (x->x_ticksleft < n) - { - int remain = x->x_ticksleft; - n-=remain; - while (remain--) - { - f+=x_slope; - *out++ = *in++ * f; - } - while (n--) - { - *out++ = *in++ * f; - } - x->x_value = f; - x->x_ticksleft = 0; - } - else + + x->x_ticksleft--; + while (n--) { - x->x_ticksleft -=n; - while (n--) - { - f+=x_slope; - *out++ = *in++ * f; - } - x->x_value = f; + f+=x_slope; + *out++ = *in++ * f; } + x->x_value = f; } else + { + t_float f = x->x_target; while (n--) *out++ = *in++ * f; + } return (w+5); } -t_int *volctl_perf8(t_int *w) +static t_int *volctl_perf8(t_int *w) { t_volctl * x = (t_volctl *)(w[1]); t_float *in = (t_float *)(w[2]); t_float *out = (t_float *)(w[3]); int n = (int)(w[4]); - t_float f = x->x_value; - if (x->x_ticksleft) { + t_float f = x->x_value; + t_float x_slope = x->x_slope; - if (x->x_ticksleft < n) + x->x_ticksleft--; + n = n>>3; + while (n--) { - int remain = x->x_ticksleft; - n-=remain; - while (remain--) - { - *out++ = *in++ * f; - f+=x_slope; - } - while (n--) + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + *out++ = *in++ * f; + f+=x_slope; + } + x->x_value = f; + } + else + { + t_float f = x->x_target; + + if (f) + for (; n; n -= 8, in += 8, out += 8) { - *out++ = *in++ * f; + t_float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; + t_float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; + + out[0] = f0 * f; out[1] = f1 * f; out[2] = f2 * f; out[3] = f3 * f; + out[4] = f4 * f; out[5] = f5 * f; out[6] = f6 * f; out[7] = f7 * f; } - x->x_value = f; - x->x_ticksleft = 0; - } else - { - x->x_ticksleft -= n; - n = n>>3; - while (n--) + for (; n; n -= 8, in += 8, out += 8) { - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; - *out++ = *in++ * f; - f+=x_slope; + out[0] = 0; out[1] = 0; out[2] = 0; out[3] = 0; + out[4] = 0; out[5] = 0; out[6] = 0; out[7] = 0; } - x->x_value = f; - } - } - else - { - for (; n; n -= 8, in += 8, out += 8) - { - t_float f0 = in[0], f1 = in[1], f2 = in[2], f3 = in[3]; - t_float f4 = in[4], f5 = in[5], f6 = in[6], f7 = in[7]; - - out[0] = f0 * f; out[1] = f1 * f; out[2] = f2 * f; out[3] = f3 * f; - out[4] = f4 * f; out[5] = f5 * f; out[6] = f6 * f; out[7] = f7 * f; - } + } return (w+5); } -t_int *volctl_perf_simd(t_int *w) +static t_int *volctl_perf_simd(t_int *w) { t_volctl * x = (t_volctl *)(w[1]); t_float *in = (t_float *)(w[2]); @@ -202,116 +181,115 @@ t_int *volctl_perf_simd(t_int *w) { int n = (int)(w[4]); - t_float x_slope = x->x_slope; - if (x->x_ticksleft < n) - { - t_float f = x->x_value; + x->x_ticksleft--; + + asm( + ".set T_FLOAT,4 \n" + "movss (%3),%%xmm0 \n" /* value */ + "shufps $0, %%xmm0, %%xmm0 \n" + "movaps (%4), %%xmm1 \n" /* x_slopes */ + "addps %%xmm0, %%xmm1 \n" - int remain = x->x_ticksleft; - n-=remain; - while (remain--) - { - *out++ = *in++ * f; - f+=x_slope; - } - while (n--) - { - *out++ = *in++ * f; - } - x->x_value = f; - x->x_ticksleft = 0; - } - else - { - x->x_ticksleft -= n; + "movss (%5), %%xmm0 \n" + "shufps $0, %%xmm0, %%xmm0 \n" /* x_slope_step */ + + "shrl $4, %2 \n" /* n>>4 */ + + "1: \n" + "movaps (%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, (%1) \n" + "addps %%xmm0, %%xmm1 \n" + "movaps 4*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, 4*T_FLOAT(%1) \n" + "addps %%xmm0, %%xmm1 \n" + + "movaps 8*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, 8*T_FLOAT(%1) \n" + "addps %%xmm0, %%xmm1 \n" + + "movaps 12*T_FLOAT(%0), %%xmm2 \n" + "mulps %%xmm1, %%xmm2 \n" + "movaps %%xmm2, 12*T_FLOAT(%1) \n" + "addps %%xmm0, %%xmm1 \n" /* one instr. obsolete */ + + "addl $16*T_FLOAT, %0 \n" + "addl $16*T_FLOAT, %1 \n" + "loop 1b \n" + + : + :"r"(in), "r"(out), "c"(n), "r"(&(t_float)(x->x_value)), + "r"((t_float*)x->x_slopes), "r"(&(t_float)(x->x_slope_step)) + :"%xmm0", "%xmm1", "%xmm2"); + + x->x_value += n*(x->x_slope); + } + else + { + if(x->x_target) asm( ".set T_FLOAT,4 \n" - "movss (%3),%%xmm0 \n" /* value */ + + "movss (%3), %%xmm0 \n" "shufps $0, %%xmm0, %%xmm0 \n" - "movaps (%4), %%xmm1 \n" /* x_slopes */ - "addps %%xmm0, %%xmm1 \n" - - "movss (%5), %%xmm0 \n" - "shufps $0, %%xmm0, %%xmm0 \n" /* x_slope_step */ - - "shrl $4, %2 \n" /* n>>4 */ - + "shrl $4, %2 \n" + "1: \n" - "movaps (%0), %%xmm2 \n" - "mulps %%xmm1, %%xmm2 \n" - "movaps %%xmm2, (%1) \n" - "addps %%xmm0, %%xmm1 \n" - + "movaps (%0), %%xmm1 \n" + "mulps %%xmm0, %%xmm1 \n" + "movaps %%xmm1, (%1) \n" "movaps 4*T_FLOAT(%0), %%xmm2 \n" - "mulps %%xmm1, %%xmm2 \n" + "mulps %%xmm0, %%xmm2 \n" "movaps %%xmm2, 4*T_FLOAT(%1) \n" - "addps %%xmm0, %%xmm1 \n" - - "movaps 8*T_FLOAT(%0), %%xmm2 \n" - "mulps %%xmm1, %%xmm2 \n" - "movaps %%xmm2, 8*T_FLOAT(%1) \n" - "addps %%xmm0, %%xmm1 \n" - - "movaps 12*T_FLOAT(%0), %%xmm2 \n" - "mulps %%xmm1, %%xmm2 \n" - "movaps %%xmm2, 12*T_FLOAT(%1) \n" - "addps %%xmm0, %%xmm1 \n" /* one instr. obsolete */ - + "movaps 8*T_FLOAT(%0), %%xmm3 \n" + "mulps %%xmm0, %%xmm3 \n" + "movaps %%xmm3, 8*T_FLOAT(%1) \n" + "movaps 12*T_FLOAT(%0), %%xmm4 \n" + "mulps %%xmm0, %%xmm4 \n" + "movaps %%xmm4, 12*T_FLOAT(%1) \n" "addl $16*T_FLOAT, %0 \n" "addl $16*T_FLOAT, %1 \n" "loop 1b \n" - : - :"r"(in), "r"(out), "c"(n), "r"(&(t_float)(x->x_value)), - "r"((t_float*)x->x_slopes), "r"(&(t_float)(x->x_slope_step)) - :"%xmm0", "%xmm1", "%xmm2"); + : "r"(in), "r"(out), + "c"(w[4]),"r"(&(t_float)(x->x_target)) + : "%xmm0", "%xmm1","%xmm2","%xmm3","%xmm4"); + else + asm( + ".set T_FLOAT,4 \n" -/* post("value %f", x->x_value); */ - x->x_value += n*(x->x_slope); - } - } - else - { - asm( - ".set T_FLOAT,4 \n" + "xorps %%xmm0, %%xmm0 \n" + "shrl $4, %1 \n" - "movss (%3), %%xmm0 \n" - "shufps $0, %%xmm0, %%xmm0 \n" - "shrl $4, %2 \n" + "1: \n" + "movaps %%xmm0, (%0) \n" + "movaps %%xmm0, 4*T_FLOAT(%0) \n" + "movaps %%xmm0, 8*T_FLOAT(%0) \n" + "movaps %%xmm0, 12*T_FLOAT(%0) \n" + "addl $16*T_FLOAT, %0 \n" + "loop 1b \n" + : + :"r"(out), + "c"(w[4]) + : "%xmm0"); - "volctl_loop: \n" - "movaps (%0), %%xmm1 \n" - "mulps %%xmm0, %%xmm1 \n" - "movaps %%xmm1, (%1) \n" - "movaps 4*T_FLOAT(%0), %%xmm2 \n" - "mulps %%xmm0, %%xmm2 \n" - "movaps %%xmm2, 4*T_FLOAT(%1) \n" - "movaps 8*T_FLOAT(%0), %%xmm3 \n" - "mulps %%xmm0, %%xmm3 \n" - "movaps %%xmm3, 8*T_FLOAT(%1) \n" - "movaps 12*T_FLOAT(%0), %%xmm4 \n" - "mulps %%xmm0, %%xmm4 \n" - "movaps %%xmm4, 12*T_FLOAT(%1) \n" - "addl $16*T_FLOAT, %0 \n" - "addl $16*T_FLOAT, %1 \n" - "loop volctl_loop \n" - : - : "r"(in), "r"(out), - "c"(w[4]),"r"(&(t_float)(x->x_value)) - : "%xmm0", "%xmm1","%xmm2","%xmm3","%xmm4"); } return (w+5); } -void volctl_set(t_volctl *x, t_float f) +static void volctl_set(t_volctl *x, t_float f) { t_float slope; int i; - - x->x_ticksleft = x->x_h * x->x_samples_per_ms; - slope = (f - x->x_value) / x->x_ticksleft; + int samplesleft = x->x_h * x->x_samples_per_ms; + samplesleft += x->x_blocksize - ( samplesleft & (x->x_blocksize - 1)); + x->x_ticksleft = (int) (t_float)samplesleft * x->x_1overblocksize; + + slope = (f - x->x_value) / samplesleft; x->x_slope = slope; for (i = 0; i != 4; ++i) @@ -319,9 +297,11 @@ void volctl_set(t_volctl *x, t_float f) x->x_slopes[i] = i*slope; } x->x_slope_step = 4*slope; + + x->x_target = f; } -void volctl_dsp(t_volctl *x, t_signal **sp) +static void volctl_dsp(t_volctl *x, t_signal **sp) { const int n = sp[0]->s_n; if (n&7) @@ -333,7 +313,10 @@ void volctl_dsp(t_volctl *x, t_signal **sp) else dsp_add(volctl_perf8, 4, x, sp[0]->s_vec, sp[1]->s_vec, n); } - x->x_samples_per_ms = sp[0]->s_sr / 1000.f; + + x->x_blocksize = n; + x->x_1overblocksize = 1./n; + x->x_samples_per_ms = sp[0]->s_sr / 1000.f; } void volctl_tilde_setup(void) -- cgit v1.2.1 From 7087c18fec98b899854bd8672dfcc7f52a02e8cb Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 12 Jan 2005 11:24:27 +0000 Subject: bugfix svn path=/trunk/externals/tb/; revision=2493 --- sc4pd/source/Median.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sc4pd/source/Median.cpp b/sc4pd/source/Median.cpp index f89f934..4383a1b 100644 --- a/sc4pd/source/Median.cpp +++ b/sc4pd/source/Median.cpp @@ -199,12 +199,12 @@ Median_kr::Median_kr(int argc,t_atom * argv) AtomList Args(argc,argv); - m_size=sc_getfloatarg(Args,0); + m_size=(int)sc_getfloatarg(Args,0); float m_set=sc_getfloatarg(Args,1); Median.Init(m_size,m_set); - AddOutSignal(); + AddOutFloat(); } void Median_kr::m_perform(float f) -- cgit v1.2.1 From 29520a2b958bcefe3dd774bd71a7b9e0fd2fa18e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 13 Jan 2005 13:39:57 +0000 Subject: smooth interpolation changing svn path=/trunk/externals/tb/; revision=2500 --- chaos/src/chaos_dsp.hpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 9704432..879eb49 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -74,6 +74,7 @@ public: void set_imethod(int i) { + int imethod = m_imethod; if( (i >= 0) && (i <= 2) ) { m_imethod = i; @@ -95,13 +96,21 @@ public: post("interpolation method out of range"); return; } - if( i != 2) + + if (imethod == 0) + for (int j = 0; j != m_system->get_num_eq(); ++j) + { + m_values[j] = m_system->get_data(j); + m_slopes[j] = 0; + } + + if( i == 2) { for (int j = 0; j != m_system->get_num_eq(); ++j) { - m_nextvalues[i] = 0; - m_nextmidpts[i] = 0; - m_curves[i] = 0; + m_phase = 0; /* reschedule to avoid click, find a better way later*/ + m_nextvalues[j] = m_values[j]; + m_nextmidpts[j] = m_values[j]; } } @@ -221,9 +230,8 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, int outlets = m_system->get_num_eq(); int phase = m_phase; - - int i = 0; - + + int offset = 0; while (n) { if (phase == 0) @@ -236,19 +244,15 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, n -= next; phase -=next; - while (next--) + for (int i = 0; i != outlets; ++i) { - for (int j = 0; j != outlets; ++j) - { - outsigs[j][i] = m_system->get_data(j); - } - ++i; + SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); } + offset += next; } m_phase = phase; } - /* linear and cubic interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, -- cgit v1.2.1 From bee409f85b7facc33e9e2b9fb7920edb7c3520bd Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 24 Jan 2005 21:22:31 +0000 Subject: improvement for factor 1 svn path=/trunk/externals/tb/; revision=2539 --- volctl~/volctl~.c | 71 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/volctl~/volctl~.c b/volctl~/volctl~.c index 1a9e451..e49c267 100644 --- a/volctl~/volctl~.c +++ b/volctl~/volctl~.c @@ -53,7 +53,7 @@ typedef struct _volctl void *volctl_new(t_symbol *s, int argc, t_atom *argv) { - if (argc > 2) post("volctl~: extra arguments ignored"); + if (argc > 3) post("volctl~: extra arguments ignored"); t_volctl *x = (t_volctl *)pd_new(volctl_class); inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("f1")); @@ -171,6 +171,7 @@ static t_int *volctl_perf8(t_int *w) return (w+5); } + static t_int *volctl_perf_simd(t_int *w) { t_volctl * x = (t_volctl *)(w[1]); @@ -229,7 +230,53 @@ static t_int *volctl_perf_simd(t_int *w) } else { - if(x->x_target) + switch(x->x_target) + { + case 0: + asm( + ".set T_FLOAT,4 \n" + + "xorps %%xmm0, %%xmm0 \n" + "shrl $4, %1 \n" + + "1: \n" + "movaps %%xmm0, (%0) \n" + "movaps %%xmm0, 4*T_FLOAT(%0) \n" + "movaps %%xmm0, 8*T_FLOAT(%0) \n" + "movaps %%xmm0, 12*T_FLOAT(%0) \n" + "addl $16*T_FLOAT, %0 \n" + "loop 1b \n" + : + :"r"(out), + "c"(w[4]) + : "%xmm0"); + break; + + case 1: + asm( + ".set T_FLOAT,4 \n" + + "shrl $4, %1 \n" + + "1: \n" + "movaps (%1), %%xmm0 \n" + "movaps 4*T_FLOAT(%1), %%xmm1 \n" + "movaps 8*T_FLOAT(%1), %%xmm2 \n" + "movaps 12*T_FLOAT(%1), %%xmm3 \n" + "movaps %%xmm0, (%2) \n" + "movaps %%xmm1, 4*T_FLOAT(%2) \n" + "movaps %%xmm2, 8*T_FLOAT(%2) \n" + "movaps %%xmm3, 12*T_FLOAT(%2) \n" + + "addl $16*T_FLOAT,%1 \n" + "addl $16*T_FLOAT,%2 \n" + "loop 1b \n" + : + :"c"(w[4]),"r"(in),"r"(out) + :"%xmm0","%xmm1","%xmm2","%xmm3"); + break; + + default: asm( ".set T_FLOAT,4 \n" @@ -257,25 +304,7 @@ static t_int *volctl_perf_simd(t_int *w) : "r"(in), "r"(out), "c"(w[4]),"r"(&(t_float)(x->x_target)) : "%xmm0", "%xmm1","%xmm2","%xmm3","%xmm4"); - else - asm( - ".set T_FLOAT,4 \n" - - "xorps %%xmm0, %%xmm0 \n" - "shrl $4, %1 \n" - - "1: \n" - "movaps %%xmm0, (%0) \n" - "movaps %%xmm0, 4*T_FLOAT(%0) \n" - "movaps %%xmm0, 8*T_FLOAT(%0) \n" - "movaps %%xmm0, 12*T_FLOAT(%0) \n" - "addl $16*T_FLOAT, %0 \n" - "loop 1b \n" - : - :"r"(out), - "c"(w[4]) - : "%xmm0"); - + } } return (w+5); } -- cgit v1.2.1 From 2393d5bab1917825e806871d9050ca54dc3041f3 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 12 Feb 2005 08:58:21 +0000 Subject: stability improvement and others svn path=/trunk/externals/tb/; revision=2568 --- chaos/src/Makefile.am | 2 +- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 2 +- chaos/src/driven_anharmonic.hpp | 2 +- chaos/src/latoocarfian.hpp | 12 ++++++++++++ chaos/src/latoomutalpha.hpp | 12 ++++++++++++ chaos/src/latoomutbeta.hpp | 13 +++++++++++++ chaos/src/latoomutgamma.hpp | 13 +++++++++++++ chaos/src/main.cpp | 3 ++- 9 files changed, 56 insertions(+), 4 deletions(-) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 213e313..2b87927 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -1,6 +1,6 @@ NAME = chaos -BUILT_SOURCES = main.cpp ode_base.cpp chaos_base.cpp chaos_dsp.cpp \ +BUILT_SOURCES = main.cpp ode_base.cpp chaos_dsp.cpp \ bernoulli_dsp.cpp bernoulli_msg.cpp \ bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ circle_map_dsp.cpp circle_map_msg.cpp \ diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index a1a3467..0f87b51 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -22,6 +22,7 @@ #define FLEXT_ATTRIBUTES 1 +#define _USE_MATH_DEFINES /* tg says: define this before including cmath */ #include "flext.h" #include "chaos_defs.hpp" #include diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index a2072d0..3e11201 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -56,7 +56,7 @@ public: data_t * m_data; // state of the system protected: - virtual void m_step(); + virtual void m_step() = 0; int m_num_eq; // number of equations of the system }; diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 8c319e9..56d81e0 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -71,7 +71,7 @@ public: m_t += m_dt; if (m_t > 2 * M_PI) - m_t = fmod(m_t, 2*M_PI); + m_t = fmod(m_t, (data_t)2*M_PI); } data_t m_t; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index c2a31a1..1fe1b9a 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -76,6 +76,18 @@ public: { return (f > -0.5) && (f < 1.5); } + + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; }; diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index 6926d1b..015eddf 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -61,6 +61,18 @@ public: m_data[1] = sin(x1*a) + tmp1*tmp1 + tmp2*tmp2*tmp2; } + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index 4940be1..fac43d6 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -58,6 +58,19 @@ public: m_data[1] = sin(x1*a) + tmp*tmp; } + + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index b4f3bf8..d83059e 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -58,6 +58,19 @@ public: m_data[1] = CHAOS_ABS(sin(x1*a)) + tmp*tmp; } + + /* function has a fix point for x1 == x2 == 0 */ + virtual void m_verify() + { + for (int i = 0; i != get_num_eq(); ++i) + { +#ifndef DOUBLE_PRECISION + if (PD_BIGORSMALL(m_data[i])) + m_data[i] = 0.01; +#endif + } + }; + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index dcb7ea8..c78a7b5 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,8 @@ void chaos_library_setup() { - post("chaos~ version "PACKAGE_VERSION"\n"); + post("chaos~ version "PACKAGE_VERSION", compiled on "__DATE__" \n"); + CHAOS_ADD(bernoulli); CHAOS_ADD(bungalow_tent); -- cgit v1.2.1 From 002257b4186392ad2a70a9b8d55c757d26858cf9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 29 Apr 2005 16:29:40 +0000 Subject: optimized for inplace operation svn path=/trunk/externals/tb/; revision=2853 --- volctl~/volctl~.c | Bin 10137 -> 10282 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/volctl~/volctl~.c b/volctl~/volctl~.c index e49c267..6a3466d 100644 Binary files a/volctl~/volctl~.c and b/volctl~/volctl~.c differ -- cgit v1.2.1 From 26404fcb66045f5b08923d9be037fbd3f6f22ebf Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 29 Apr 2005 19:04:37 +0000 Subject: simd code for msvc ... svn path=/trunk/externals/tb/; revision=2855 --- volctl~/volctl~.c | Bin 10282 -> 9347 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/volctl~/volctl~.c b/volctl~/volctl~.c index 6a3466d..946beb3 100644 Binary files a/volctl~/volctl~.c and b/volctl~/volctl~.c differ -- cgit v1.2.1 From e50bf5fa3c18516c4bbebb0149cdee83d2c8ae57 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 2 May 2005 14:48:25 +0000 Subject: fixed compiling failure ... added support for flext build system ... thnx thomas svn path=/trunk/externals/tb/; revision=2881 --- sc4pd/package.txt | 24 ++++++++++++++++++++++++ sc4pd/source/support.cpp | 8 ++++---- sc4pd/source/support.hpp | 8 ++++---- 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 sc4pd/package.txt diff --git a/sc4pd/package.txt b/sc4pd/package.txt new file mode 100644 index 0000000..c366fee --- /dev/null +++ b/sc4pd/package.txt @@ -0,0 +1,24 @@ +NAME=sc4pd + +SRCDIR=source + +SRCS=main.cpp Dust.cpp MantissaMask.cpp Hasher.cpp Median.cpp \ + BrownNoise.cpp ClipNoise.cpp GrayNoise.cpp WhiteNoise.cpp \ + PinkNoise.cpp Dust2.cpp Crackle.cpp Rand.cpp TRand.cpp TExpRand.cpp \ + IRand.cpp TIRand.cpp CoinGate.cpp support.cpp LinRand.cpp NRand.cpp\ + ExpRand.cpp LFClipNoise.cpp LFNoise0.cpp LFNoise1.cpp LFNoise2.cpp \ + Logistic.cpp Latoocarfian.cpp LinCong.cpp amclip.cpp scaleneg.cpp \ + excess.cpp hypot.cpp ring1.cpp ring2.cpp ring3.cpp ring4.cpp \ + difsqr.cpp sumsqr.cpp sqrdif.cpp sqrsum.cpp absdif.cpp LFSaw.cpp \ + LFPulse.cpp Impulse.cpp Integrator.cpp Decay.cpp Decay2.cpp Lag.cpp \ + Lag2.cpp Lag3.cpp LinExp.cpp DelayUnit.cpp DelayN.cpp DelayL.cpp \ + DelayC.cpp CombN.cpp CombL.cpp CombC.cpp AllpassN.cpp AllpassL.cpp \ + AllpassC.cpp PitchShift.cpp Resonz.cpp OnePole.cpp OneZero.cpp \ + TwoPole.cpp TwoZero.cpp FOS.cpp SOS.cpp RLPF.cpp RHPF.cpp LPF.cpp \ + HPF.cpp BPF.cpp BRF.cpp LPZ1.cpp HPZ1.cpp LPZ2.cpp HPZ2.cpp \ + BPZ2.cpp BRZ2.cpp LFDNoise0.cpp LFDNoise1.cpp LFDNoise2.cpp \ + sc+.cpp sc-.cpp scmul.cpp scdiv.cpp Convolution.cpp + +HDRS=DelayUnit.hpp fftlib.h sc4pd.hpp support.hpp + +INCPATH=-I./headers/plugin_interface -I./headers/common -I./headers/server \ No newline at end of file diff --git a/sc4pd/source/support.cpp b/sc4pd/source/support.cpp index 69aaf2b..e753056 100644 --- a/sc4pd/source/support.cpp +++ b/sc4pd/source/support.cpp @@ -39,7 +39,7 @@ #include -bool sc_add (flext::AtomList a) +bool sc_add (flext::AtomList& a) { for (int i = 0; i!=a.Count();++i) { @@ -54,7 +54,7 @@ bool sc_add (flext::AtomList a) return false; } -float sc_getfloatarg (flext::AtomList a,int i) +float sc_getfloatarg (flext::AtomList& a,int i) { if (a.Count() > 0 && a.Count() > i) return flext::GetAFloat(a[i]); @@ -62,7 +62,7 @@ float sc_getfloatarg (flext::AtomList a,int i) return 0; } -bool sc_ar(flext::AtomList a) +bool sc_ar(flext::AtomList& a) { for (int i = 0; i!=a.Count();++i) { @@ -77,7 +77,7 @@ bool sc_ar(flext::AtomList a) return false; } -bool sc_inv(flext::AtomList a) +bool sc_inv(flext::AtomList& a) { for (int i = 0; i!=a.Count();++i) { diff --git a/sc4pd/source/support.hpp b/sc4pd/source/support.hpp index c9cedae..12885cb 100644 --- a/sc4pd/source/support.hpp +++ b/sc4pd/source/support.hpp @@ -47,10 +47,10 @@ /* for argument parsing */ -bool sc_add (flext::AtomList a); -float sc_getfloatarg (flext::AtomList a,int i); -bool sc_ar(flext::AtomList a); -bool sc_inv(flext::AtomList a); +bool sc_add (flext::AtomList& a); +float sc_getfloatarg (flext::AtomList& a,int i); +bool sc_ar(flext::AtomList& a); +bool sc_inv(flext::AtomList& a); /* for rngs */ -- cgit v1.2.1 From 47761b1ad9fbf6eaca7faaa5fe2c8bbcbdcf4cd6 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 4 May 2005 11:56:46 +0000 Subject: initial checkin svn path=/trunk/externals/tb/; revision=2894 --- jack_transport/jack_transport.c | 116 +++++++++++++++++++++++++++++++++++++++ jack_transport/jack_transport.pd | 11 ++++ jack_transport/makefile | 94 +++++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 jack_transport/jack_transport.c create mode 100644 jack_transport/jack_transport.pd create mode 100644 jack_transport/makefile diff --git a/jack_transport/jack_transport.c b/jack_transport/jack_transport.c new file mode 100644 index 0000000..053e75b --- /dev/null +++ b/jack_transport/jack_transport.c @@ -0,0 +1,116 @@ +/* +* +* jack_transport Copyright (C) 2005 Tim Blechmann +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; see the file COPYING. If not, write to +* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 02111-1307, USA. +*/ + +#include "m_pd.h" +#include "jack/jack.h" +#include "stdio.h" + +static t_class *jack_transport_class; + +typedef struct _jack_transport +{ + t_object x_obj; + t_outlet * x_outlet; + jack_client_t* x_jack_client; + jack_position_t* x_pos; +} jack_transport_t; + + +/* connect to jack server */ +static int jack_transport_connect(jack_transport_t * x) +{ + char port_name[80] = ""; + + static int client = 0; + do + { + sprintf(port_name,"pure_data_jack_transport_%d",client); + client++; + } + while (((x->x_jack_client = jack_client_new (port_name)) == 0) && + client < 100); + client = 0; + + if (!x->x_jack_client) + { + post("jack_transport: can't connect to jack server"); + return 1; + } + + post("jack_transport: connecting as %s", port_name); + + jack_activate(x->x_jack_client); + + return 0; +} + + +static jack_transport_t * jack_transport_new(void) +{ + int status = 0; + jack_transport_t *x = (jack_transport_t*) pd_new(jack_transport_class); + + x->x_outlet = outlet_new(&x->x_obj, NULL); + x->x_pos = (jack_position_t*) getbytes(sizeof(jack_position_t)); + + status = jack_transport_connect(x); + + return x; +} + +static void jack_transport_starter(jack_transport_t * x) +{ + jack_transport_start(x->x_jack_client); + return; +} + +static void jack_transport_stoper(jack_transport_t * x) +{ + jack_transport_stop(x->x_jack_client); + return; +} + +static void jack_transport_bang(jack_transport_t * x) +{ + float f; + if (!x->x_jack_client) + return; + + jack_transport_query(x->x_jack_client,x->x_pos); + + f = x->x_pos->frame; + + outlet_float(x->x_outlet, f); +} + + +void jack_transport_setup(void) +{ + jack_transport_class = class_new(gensym("jack_transport"), + (t_newmethod)jack_transport_new, + NULL, sizeof(jack_transport_t), + CLASS_DEFAULT, 0); + class_addmethod(jack_transport_class, (t_method)jack_transport_starter, + gensym("start"),0,0); + class_addmethod(jack_transport_class, (t_method)jack_transport_stoper, + gensym("stop"),0,0); + class_addbang(jack_transport_class, (t_method)jack_transport_bang); + +} diff --git a/jack_transport/jack_transport.pd b/jack_transport/jack_transport.pd new file mode 100644 index 0000000..e29286b --- /dev/null +++ b/jack_transport/jack_transport.pd @@ -0,0 +1,11 @@ +#N canvas 0 0 450 300 10; +#X floatatom 243 177 10 0 0 0 - - -; +#X obj 243 129 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 243 153 jack_transport; +#X obj 243 203 / 48000; +#X floatatom 243 227 5 0 0 0 - - -; +#X connect 0 0 3 0; +#X connect 1 0 2 0; +#X connect 2 0 0 0; +#X connect 3 0 4 0; diff --git a/jack_transport/makefile b/jack_transport/makefile new file mode 100644 index 0000000..d4bb5fb --- /dev/null +++ b/jack_transport/makefile @@ -0,0 +1,94 @@ +NAME=jack_transport +CSYM=jack_transport + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch -g + +LINUXINCLUDE = -I../../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From ccfab7528a3acb2703eabb59e05b10de9a0026c8 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 5 May 2005 19:31:39 +0000 Subject: setting jack transport frame svn path=/trunk/externals/tb/; revision=2903 --- jack_transport/jack_transport.c | 13 ++++++++++--- jack_transport/jack_transport.pd | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/jack_transport/jack_transport.c b/jack_transport/jack_transport.c index 053e75b..84b269e 100644 --- a/jack_transport/jack_transport.c +++ b/jack_transport/jack_transport.c @@ -92,14 +92,20 @@ static void jack_transport_bang(jack_transport_t * x) float f; if (!x->x_jack_client) return; - - jack_transport_query(x->x_jack_client,x->x_pos); - f = x->x_pos->frame; + f = (float)jack_get_current_transport_frame(x->x_jack_client); outlet_float(x->x_outlet, f); } +static void jack_transport_float(jack_transport_t * x, float f) +{ + if (!x->x_jack_client) + return; + + jack_transport_locate(x->x_jack_client, (jack_nframes_t)f); +} + void jack_transport_setup(void) { @@ -112,5 +118,6 @@ void jack_transport_setup(void) class_addmethod(jack_transport_class, (t_method)jack_transport_stoper, gensym("stop"),0,0); class_addbang(jack_transport_class, (t_method)jack_transport_bang); + class_addfloat(jack_transport_class, (t_method)jack_transport_float); } diff --git a/jack_transport/jack_transport.pd b/jack_transport/jack_transport.pd index e29286b..4460085 100644 --- a/jack_transport/jack_transport.pd +++ b/jack_transport/jack_transport.pd @@ -1,11 +1,13 @@ #N canvas 0 0 450 300 10; -#X floatatom 243 177 10 0 0 0 - - -; -#X obj 243 129 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +#X obj 100 141 jack_transport; +#X floatatom 140 118 5 0 0 0 - - -; +#X msg 191 120 stop; +#X msg 191 97 start; +#X floatatom 87 174 9 0 0 0 - - -; +#X obj 42 58 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X obj 243 153 jack_transport; -#X obj 243 203 / 48000; -#X floatatom 243 227 5 0 0 0 - - -; -#X connect 0 0 3 0; -#X connect 1 0 2 0; +#X connect 0 0 4 0; +#X connect 1 0 0 0; #X connect 2 0 0 0; -#X connect 3 0 4 0; +#X connect 3 0 0 0; +#X connect 5 0 0 0; -- cgit v1.2.1 From 5e3a5a223c834adc8b27d76cbe4b1e57f73b6cc0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 11 May 2005 20:26:46 +0000 Subject: thnx thomas svn path=/trunk/externals/tb/; revision=2960 --- chaos/src/driven_anharmonic.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 56d81e0..f4c8da4 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -71,7 +71,7 @@ public: m_t += m_dt; if (m_t > 2 * M_PI) - m_t = fmod(m_t, (data_t)2*M_PI); + m_t = fmod(m_t, (data_t)(M_PI*2)); } data_t m_t; -- cgit v1.2.1 From 0a333caec5eb5ed2a97d4d1b5fbde37724280fdc Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 11 May 2005 20:28:00 +0000 Subject: add flext build system support svn path=/trunk/externals/tb/; revision=2961 --- chaos/package.txt | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 chaos/package.txt diff --git a/chaos/package.txt b/chaos/package.txt new file mode 100644 index 0000000..cd87590 --- /dev/null +++ b/chaos/package.txt @@ -0,0 +1,86 @@ +NAME=chaos + +SRCDIR=src + +#PRECOMPILE=chaos.hpp + +SRCS= \ +main.cpp \ +bernoulli_dsp.cpp \ +bernoulli_msg.cpp \ +bungalow_tent_dsp.cpp \ +bungalow_tent_msg.cpp \ +chaos_base.cpp \ +chaos_dsp.cpp \ +chua_dsp.cpp \ +chua_msg.cpp \ +circle_map_dsp.cpp \ +circle_map_msg.cpp \ +coupled_logistic_dsp.cpp \ +coupled_logistic_msg.cpp \ +driven_anharmonic_dsp.cpp \ +driven_anharmonic_msg.cpp \ +driven_van_der_pol_dsp.cpp \ +driven_van_der_pol_msg.cpp \ +duffing_map_dsp.cpp \ +duffing_map_msg.cpp \ +gauss_map_dsp.cpp \ +gauss_map_msg.cpp \ +henon_map_dsp.cpp \ +henon_map_msg.cpp \ +ikeda_laser_map_dsp.cpp \ +ikeda_laser_map_msg.cpp \ +latoocarfian_dsp.cpp \ +latoocarfian_msg.cpp \ +latoomutalpha_dsp.cpp \ +latoomutalpha_msg.cpp \ +latoomutbeta_dsp.cpp \ +latoomutbeta_msg.cpp \ +latoomutgamma_dsp.cpp \ +latoomutgamma_msg.cpp \ +logistic_dsp.cpp \ +logistic_msg.cpp \ +lorenz_dsp.cpp \ +lorenz_msg.cpp \ +lozi_map_dsp.cpp \ +lozi_map_msg.cpp \ +ode_base.cpp \ +roessler_dsp.cpp \ +roessler_msg.cpp \ +sine_map_dsp.cpp \ +sine_map_msg.cpp \ +standard_map_dsp.cpp \ +standard_map_msg.cpp \ +tent_map_dsp.cpp \ +tent_map_msg.cpp \ + +HDRS= \ +bernoulli_map.hpp \ +bungalow_tent_map.hpp \ +chaos.hpp \ +chaos_base.hpp \ +chaos_defs.hpp \ +chaos_dsp.hpp \ +chaos_msg.hpp \ +chua.hpp \ +circle_map.hpp \ +coupled_logistic.hpp \ +driven_anharmonic.hpp \ +driven_van_der_pol.hpp \ +duffing_map.hpp \ +gauss_map.hpp \ +henon_map.hpp \ +ikeda_laser_map.hpp \ +latoocarfian.hpp \ +latoomutalpha.hpp \ +latoomutbeta.hpp \ +latoomutgamma.hpp \ +logistic_map.hpp \ +lorenz.hpp \ +lozi_map.hpp \ +map_base.hpp \ +ode_base.hpp \ +roessler.hpp \ +sine_map.hpp \ +standard_map.hpp \ +tent_map.hpp -- cgit v1.2.1 From 5fda6973fd8d94872a61d99d264ee5902824139d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 9 Jun 2005 12:48:20 +0000 Subject: adapted for updated fifo implementation svn path=/trunk/externals/tb/; revision=3144 --- detach/detach.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/detach/detach.c b/detach/detach.c index 6460f6b..661e073 100644 --- a/detach/detach.c +++ b/detach/detach.c @@ -45,6 +45,7 @@ typedef struct _detach typedef struct _detach_content { + struct _detach_content_t * next; enum { BANG, POINTER, FLOAT, @@ -54,6 +55,7 @@ typedef struct _detach_content CANCEL} type; int argc; t_atom * argv; + t_symbol * symbol; } detach_content_t; @@ -85,7 +87,7 @@ static void detach_thread(detach_t* x) freebytes(me->argv, me->argc * sizeof(t_atom)); break; case ANYTHING: - outlet_anything(x->x_outlet, 0, me->argc, me->argv); + outlet_anything(x->x_outlet, me->symbol, me->argc, me->argv); freebytes(me->argv, me->argc * sizeof(t_atom)); break; case CANCEL: @@ -232,6 +234,7 @@ static void detach_anything(detach_t * x, t_symbol * s, me->type = ANYTHING; me->argc = argc; me->argv = copybytes(argv, argc * sizeof(t_atom)); + me->symbol = s; fifo_put(x->x_fifo, me); pthread_cond_broadcast(&x->x_cond); -- cgit v1.2.1 From 2434290915cda6ed855e4dc2249312153b995817 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 9 Jun 2005 12:52:17 +0000 Subject: changed initialisation svn path=/trunk/externals/tb/; revision=3145 --- chaos/src/Makefile.am | 4 +- chaos/src/bernoulli_map.hpp | 11 ++-- chaos/src/bungalow_tent_map.hpp | 12 ++-- chaos/src/chaos_base.hpp | 26 ++++++-- chaos/src/chaos_defs.hpp | 43 +++++++++++- chaos/src/chaos_dsp.hpp | 138 +++++++++++++++++++++------------------ chaos/src/chua.hpp | 22 ++++--- chaos/src/circle_map.hpp | 15 +++-- chaos/src/coupled_logistic.hpp | 38 ++++++++--- chaos/src/driven_anharmonic.hpp | 26 ++++---- chaos/src/driven_van_der_pol.hpp | 22 +++---- chaos/src/duffing_map.hpp | 16 +++-- chaos/src/gauss_map.hpp | 10 +-- chaos/src/henon_map.hpp | 16 +++-- chaos/src/ikeda_laser_map.hpp | 21 +++--- chaos/src/latoocarfian.hpp | 20 +++--- chaos/src/latoomutalpha.hpp | 20 +++--- chaos/src/latoomutbeta.hpp | 16 +++-- chaos/src/latoomutgamma.hpp | 16 +++-- chaos/src/logistic_map.hpp | 10 +-- chaos/src/lorenz.hpp | 25 +++---- chaos/src/lozi_map.hpp | 24 ++++--- chaos/src/main.cpp | 2 +- chaos/src/roessler.hpp | 24 +++---- chaos/src/sine_map.hpp | 10 +-- chaos/src/standard_map.hpp | 14 ++-- chaos/src/tent_map.hpp | 10 +-- 27 files changed, 371 insertions(+), 240 deletions(-) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am index 2b87927..e85310c 100644 --- a/chaos/src/Makefile.am +++ b/chaos/src/Makefile.am @@ -16,13 +16,13 @@ BUILT_SOURCES = main.cpp ode_base.cpp chaos_dsp.cpp \ latoomutalpha_dsp.cpp latoomutalpha_msg.cpp \ latoomutbeta_dsp.cpp latoomutbeta_msg.cpp \ latoomutgamma_dsp.cpp latoomutgamma_msg.cpp \ - logistic_dsp.cpp logistic_msg.cpp \ + logistic_dsp.cpp logistic_msg.cpp logistic_search.cpp\ lorenz_dsp.cpp lorenz_msg.cpp \ lozi_map_dsp.cpp lozi_map_msg.cpp \ roessler_dsp.cpp roessler_msg.cpp \ sine_map_dsp.cpp sine_map_msg.cpp \ standard_map_dsp.cpp standard_map_msg.cpp \ - tent_map_dsp.cpp tent_map_msg.cpp + tent_map_dsp.cpp tent_map_msg.cpp CXXFLAGS = @CXXFLAGS@ \ @OPT_FLAGS@ \ diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 821f24f..31db7f7 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -28,16 +28,19 @@ class bernoulli: public map_base { public: + bernoulli() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0.5,0); + + CHAOS_POSTCONSTRUCTOR; } ~bernoulli() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 0dfe709..5da431d 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -38,15 +38,17 @@ class bungalow_tent: public: bungalow_tent() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x, 0.6); - CHAOS_SYS_INIT(r, 0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.6,0); + CHAOS_PAR_INIT(r, 0.5); + + CHAOS_POSTCONSTRUCTOR; } ~bungalow_tent() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 3e11201..959afdf 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -21,6 +21,9 @@ #ifndef __chaos_base_hpp #include "chaos.hpp" +#include + +#define MAXDIMENSION 5 // this should be enough for the first class chaos_base { @@ -42,6 +45,9 @@ public: m_verify(); } + std::map attr_ind; + + // check the integrity of the system virtual void m_verify() { for (int i = 0; i != get_num_eq(); ++i) @@ -52,14 +58,25 @@ public: #endif } }; - - data_t * m_data; // state of the system + + data_t m_data[MAXDIMENSION]; // state of the system protected: - virtual void m_step() = 0; - int m_num_eq; // number of equations of the system + virtual void m_step() = 0; // iteration + int m_num_eq; // number of equations of the system + flext::AtomList Parameter; // parameter + flext::AtomList System; // system }; +#define CHAOS_PRECONSTRUCTOR \ + /* dummy */ + +#define CHAOS_POSTCONSTRUCTOR \ +m_num_eq = System.Count(); + +#define CHAOS_DESTRUCTOR \ + + #define CHAOS_CALLBACKS \ public: \ @@ -69,6 +86,7 @@ void get_dimension(int &i) \ } \ FLEXT_CALLGET_I(get_dimension); + #define CHAOS_ATTRIBUTES \ FLEXT_ADDATTR_GET("dimension",get_dimension); diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index 08c47d4..d9f60d8 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -124,9 +124,24 @@ FLEXT_CALLVAR_I(get_##NAME, set_##NAME); #define CHAOS_SYS_ATTRIBUTE(NAME) \ FLEXT_ADDATTR_VAR(#NAME,get_##NAME, set_##NAME); -#define CHAOS_SYS_INIT(NAME, VALUE) \ + +#define CHAOS_INIT(NAME, VALUE) \ set_##NAME(VALUE); +#define CHAOS_SYS_INIT(NAME, VALUE, INDEX) \ +set_##NAME(VALUE); \ +t_atom atom_##NAME; \ +flext::SetSymbol(atom_##NAME, flext::MakeSymbol(#NAME)); \ +System.Append(atom_##NAME); \ +attr_ind[flext::MakeSymbol(#NAME)] = INDEX; + +#define CHAOS_PAR_INIT(NAME, VALUE) \ +set_##NAME(VALUE); \ +t_atom atom_##NAME; \ +flext::SetSymbol(atom_##NAME, flext::MakeSymbol(#NAME)); \ +Parameter.Append(atom_##NAME); + + #define CHAOS_PARAMETER(NAME) m_##NAME @@ -142,6 +157,7 @@ class CLASSNAME##_dsp: \ }; \ FLEXT_LIB_DSP_V(#CLASSNAME"~", CLASSNAME##_dsp); + #define CHAOS_DSP_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ class CLASSNAME##_dsp: \ public chaos_dsp \ @@ -161,6 +177,7 @@ class CLASSNAME##_msg: \ }; \ FLEXT_LIB_V(#CLASSNAME, CLASSNAME##_msg); + #define CHAOS_MSG_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ class CLASSNAME##_msg: \ public chaos_msg \ @@ -170,9 +187,31 @@ class CLASSNAME##_msg: \ }; \ FLEXT_LIB_V(#NAME, CLASSNAME##_msg); +#define CHAOS_SEARCH_CLASS(CLASSNAME,CLASSNAME_UC) \ +class CLASSNAME##_search: \ + public chaos_search \ +{ \ + CHAOS_SEARCH_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#CLASSNAME"_search", CLASSNAME##_search); + + +#define CHAOS_SEARCH_CLASS_NAME(CLASSNAME,CLASSNAME_UC, NAME) \ +class CLASSNAME##_msg: \ + public chaos_search \ +{ \ + CHAOS_SEARCH_INIT(CLASSNAME, CLASSNAME_UC##_ATTRIBUTES); \ + CLASSNAME_UC##_CALLBACKS; \ +}; \ +FLEXT_LIB_V(#NAME, CLASSNAME##_msg); + + + #define CHAOS_ADD(NAME) \ FLEXT_DSP_SETUP(NAME##_dsp); \ -FLEXT_SETUP(NAME##_msg); +FLEXT_SETUP(NAME##_msg); \ +FLEXT_SETUP(NAME##_search); #define __chaos_defs_hpp #endif /* __chaos_defs_hpp */ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 879eb49..bb3c5fa 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -104,7 +104,7 @@ public: m_slopes[j] = 0; } - if( i == 2) + if(i == 2 && imethod != 2) { for (int j = 0; j != m_system->get_num_eq(); ++j) { @@ -125,9 +125,17 @@ public: { if( (f >= 0) && (f <= m_sr*0.5) ) { + if (m_freq == -1) + set_imethod(m_imethod); m_freq = f; m_invfreq = 1.f / f; } + else if (f == -1) + { + m_freq = -1; + + m_routine = &thisType::m_signal_; + } else post("frequency out of range"); } @@ -138,70 +146,70 @@ public: /* create constructor / destructor */ -#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ -FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ - \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_sr = 44100; /* assume default sampling rate */ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - m_values = new t_float[size]; \ - m_slopes = new t_float[size]; \ - m_nextvalues = new t_float[size]; \ - m_nextmidpts = new t_float[size]; \ - m_curves = new t_float[size]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ - FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ - \ - if (argc > 0) \ - { \ - CHAOS_SYS_INIT(freq, GetAInt(argv[0])); \ - } \ - else \ - { \ - CHAOS_SYS_INIT(freq, 440); \ - } \ - \ - if (argc > 1) \ - { \ - CHAOS_SYS_INIT(imethod, GetAInt(argv[1])); \ - } \ - else \ - { \ - CHAOS_SYS_INIT(imethod, 0); \ - } \ - \ - m_phase = 0; \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ -{ \ - delete m_system; \ - delete m_values; \ - delete m_slopes; \ - delete m_nextvalues; \ - delete m_nextmidpts; \ - delete m_curves; \ -} \ - \ -FLEXT_ATTRVAR_F(m_freq); \ +#define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ + \ +SYSTEM##_dsp(int argc, t_atom* argv ) \ +{ \ + m_sr = 44100; /* assume default sampling rate */ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + m_values = new t_float[size]; \ + m_slopes = new t_float[size]; \ + m_nextvalues = new t_float[size]; \ + m_nextmidpts = new t_float[size]; \ + m_curves = new t_float[size]; \ + \ + /* create inlets and zero arrays*/ \ + for (int i = 0; i != size; ++i) \ + { \ + AddOutSignal(); \ + m_values[i] = 0; \ + m_slopes[i] = 0; \ + m_nextvalues[i] = 0; \ + m_nextmidpts[i] = 0; \ + m_curves[i] = 0; \ + } \ + \ + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ + \ + if (argc > 0) \ + { \ + CHAOS_INIT(freq, GetAInt(argv[0])); \ + } \ + else \ + { \ + CHAOS_INIT(freq, 440); \ + } \ + \ + if (argc > 1) \ + { \ + CHAOS_INIT(imethod, GetAInt(argv[1])); \ + } \ + else \ + { \ + CHAOS_INIT(imethod, 0); \ + } \ + \ + m_phase = 0; \ + \ + ATTRIBUTES; \ +} \ + \ +~SYSTEM##_dsp() \ +{ \ + delete m_system; \ + delete m_values; \ + delete m_slopes; \ + delete m_nextvalues; \ + delete m_nextmidpts; \ + delete m_curves; \ +} \ + \ +FLEXT_ATTRVAR_F(m_freq); \ FLEXT_ATTRVAR_I(m_imethod); diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index a5db1cb..e54df47 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -36,15 +36,18 @@ class chua: public: chua() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x1,1); - CHAOS_SYS_INIT(x2,1); - CHAOS_SYS_INIT(x3,1); - CHAOS_SYS_INIT(a,1.4); - CHAOS_SYS_INIT(b,0.3); - CHAOS_SYS_INIT(alpha,0.3); - CHAOS_SYS_INIT(beta,0.3); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x1,1,0); + CHAOS_SYS_INIT(x2,1,1); + CHAOS_SYS_INIT(x3,1,2); + + CHAOS_PAR_INIT(a,1.4); + CHAOS_PAR_INIT(b,0.3); + CHAOS_PAR_INIT(alpha,0.3); + CHAOS_PAR_INIT(beta,0.3); + + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); } @@ -52,7 +55,6 @@ public: ~chua() { ode_base_free(); - delete m_data; } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 91f11d6..b6442a8 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -32,16 +32,19 @@ class circle_map: public: circle_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(omega, 0.1); - CHAOS_SYS_INIT(r, 3); - CHAOS_SYS_INIT(x, 0.4); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.4,0); + + CHAOS_PAR_INIT(omega, 0.1); + CHAOS_PAR_INIT(r, 3); + + CHAOS_POSTCONSTRUCTOR; } ~circle_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 85b6928..7cc8602 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -21,7 +21,7 @@ #include "map_base.hpp" // coupled_logistic map: x[n+1] = r * x[n] * (1 - x[n]) + e * (y[n] - x[n]) -// y[n+1] = r * y[n] * (1 - y[n]) + e * (x[t] - y[t]) +// y[n+1] = r * y[n] * (1 - y[n]) + e * (x[n] - y[n]) // 1 <= r <= 4 // taken from Willi-Hans Steeb: Chaos and Fractals @@ -31,17 +31,19 @@ class coupled_logistic: public: coupled_logistic() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(e, 0.06); - CHAOS_SYS_INIT(r, 3.7); - CHAOS_SYS_INIT(x, 0.1); - CHAOS_SYS_INIT(x, 0.2); + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(e, 0.06); + CHAOS_PAR_INIT(r, 3.7); + + CHAOS_SYS_INIT(x, 0.1,0); + CHAOS_SYS_INIT(y, 0.2,1); + + CHAOS_POSTCONSTRUCTOR; } ~coupled_logistic() { - delete m_data; } virtual void m_step() @@ -61,8 +63,24 @@ public: return (f > 0) && (f < 4); } - CHAOS_SYSVAR_FUNCS(x, 0); - CHAOS_SYSVAR_FUNCS(y, 0); + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_xy); + CHAOS_SYSVAR_FUNCS_PRED(y, 0, m_pred_xy); + + bool m_pred_xy(t_float f) + { + return (f > 0) && (f < 1); + } + + virtual void m_verify() + { + data_t x = m_data[0]; + data_t y = m_data[1]; + if (!m_pred_xy(x)) + m_data[0] = 0.5; + if (!m_pred_xy(y)) + m_data[1] = 0.5; + } + }; diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index f4c8da4..16e053b 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -34,22 +34,22 @@ class driven_anharmonic public: driven_anharmonic() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); - CHAOS_SYS_INIT(u1,0); - CHAOS_SYS_INIT(u2,1); + CHAOS_SYS_INIT(u1,0,0); + CHAOS_SYS_INIT(u2,1,1); - CHAOS_SYS_INIT(a,1); - CHAOS_SYS_INIT(b,-10); - CHAOS_SYS_INIT(c,100); - CHAOS_SYS_INIT(Omega,3.5); - CHAOS_SYS_INIT(k1,0.01); - CHAOS_SYS_INIT(k2,1); + CHAOS_PAR_INIT(a,1); + CHAOS_PAR_INIT(b,-10); + CHAOS_PAR_INIT(c,100); + CHAOS_PAR_INIT(Omega,3.5); + CHAOS_PAR_INIT(k1,0.01); + CHAOS_PAR_INIT(k2,1); + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); m_t = 0; } @@ -57,7 +57,7 @@ public: ~driven_anharmonic() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 23386b3..65290ee 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -35,27 +35,27 @@ class driven_van_der_pol public: driven_van_der_pol() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); - CHAOS_SYS_INIT(u1,0.8); - CHAOS_SYS_INIT(u2,0.6); - CHAOS_SYS_INIT(u3,0.4); + CHAOS_SYS_INIT(u1,0.8, 0); + CHAOS_SYS_INIT(u2,0.6, 1); + CHAOS_SYS_INIT(u3,0.4, 2); - CHAOS_SYS_INIT(a,5); - CHAOS_SYS_INIT(Omega,2.466); - CHAOS_SYS_INIT(k,5); + CHAOS_PAR_INIT(a,5); + CHAOS_PAR_INIT(Omega,2.466); + CHAOS_PAR_INIT(k,5); + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); } ~driven_van_der_pol() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index 71b8cbd..5110873 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -31,17 +31,19 @@ class duffing_map: public: duffing_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x1, 0.5); - CHAOS_SYS_INIT(x2, 0.5); - CHAOS_SYS_INIT(a, 0.5); - CHAOS_SYS_INIT(b, 0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x1, 0.5, 0); + CHAOS_SYS_INIT(x2, 0.5, 1); + CHAOS_PAR_INIT(a, 0.5); + CHAOS_PAR_INIT(b, 0.5); + + CHAOS_POSTCONSTRUCTOR; } ~duffing_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 4d62654..1e023d2 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -33,14 +33,16 @@ class gauss_map: public: gauss_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0.5, 0); + + CHAOS_POSTCONSTRUCTOR; } ~gauss_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index b43034a..73aed66 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -31,18 +31,20 @@ class henon: public: henon() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0); - CHAOS_SYS_INIT(y,0); - CHAOS_SYS_INIT(a,1.4); - CHAOS_SYS_INIT(b,0.3); + CHAOS_SYS_INIT(x,0,0); + CHAOS_SYS_INIT(y,0,1); + + CHAOS_PAR_INIT(a,1.4); + CHAOS_PAR_INIT(b,0.3); + + CHAOS_POSTCONSTRUCTOR; } ~henon() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index c62bc15..ece0b9f 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -37,19 +37,22 @@ class ikeda_laser_map: public: ikeda_laser_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(c1,0.4); - CHAOS_SYS_INIT(c2,0.9); - CHAOS_SYS_INIT(c3,9); - CHAOS_SYS_INIT(roh,0.85); - CHAOS_SYS_INIT(x,0.5); - CHAOS_SYS_INIT(y,0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(c1,0.4); + CHAOS_PAR_INIT(c2,0.9); + CHAOS_PAR_INIT(c3,9); + CHAOS_PAR_INIT(roh,0.85); + + CHAOS_SYS_INIT(x,0.5,0); + CHAOS_SYS_INIT(y,0.5,1); + + CHAOS_POSTCONSTRUCTOR; } ~ikeda_laser_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 1fe1b9a..9884fd1 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -33,20 +33,22 @@ class latoocarfian public: latoocarfian() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); - CHAOS_SYS_INIT(c,0.765145); - CHAOS_SYS_INIT(d,0.744728); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + CHAOS_PAR_INIT(c,0.765145); + CHAOS_PAR_INIT(d,0.744728); + + CHAOS_POSTCONSTRUCTOR; } ~latoocarfian() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index 015eddf..ca99c12 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -32,19 +32,21 @@ class latoomutalpha public: latoomutalpha() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0.2); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); - CHAOS_SYS_INIT(c,0.765145); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.2,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + CHAOS_PAR_INIT(c,0.765145); + + CHAOS_POSTCONSTRUCTOR; } ~latoomutalpha() { - delete m_data; + } virtual void m_step() @@ -68,7 +70,7 @@ public: { #ifndef DOUBLE_PRECISION if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; + m_data[i] = 0.5; #endif } }; diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index fac43d6..e27e5a2 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -32,18 +32,20 @@ class latoomutbeta public: latoomutbeta() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0.5); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.5,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + + CHAOS_POSTCONSTRUCTOR; } ~latoomutbeta() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index d83059e..fcdf6a6 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -32,18 +32,20 @@ class latoomutgamma public: latoomutgamma() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5); - CHAOS_SYS_INIT(x2,0.5); - CHAOS_SYS_INIT(a,-0.966918); - CHAOS_SYS_INIT(b,2.879879); + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.5,1); + + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + + CHAOS_POSTCONSTRUCTOR; } ~latoomutgamma() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index ef2f603..16e824e 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -30,10 +30,12 @@ class logistic: public: logistic() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(alpha, 3.8); - CHAOS_SYS_INIT(x, 0.5); + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(alpha, 3.8); + CHAOS_SYS_INIT(x, 0.5,0); + + CHAOS_POSTCONSTRUCTOR; } ~logistic() diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index c876b4a..ee4e516 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -31,25 +31,28 @@ class lorenz public: lorenz() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(dt,0.01); - CHAOS_SYS_INIT(x1,0.8); - CHAOS_SYS_INIT(x2,0.7); - CHAOS_SYS_INIT(x3,0.6); - CHAOS_SYS_INIT(sigma,16); - CHAOS_SYS_INIT(b,4); - CHAOS_SYS_INIT(r,40); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + CHAOS_SYS_INIT(x1,0.8,0); + CHAOS_SYS_INIT(x2,0.7,1); + CHAOS_SYS_INIT(x3,0.6,2); + + CHAOS_PAR_INIT(sigma,16); + CHAOS_PAR_INIT(b,4); + CHAOS_PAR_INIT(r,40); + + CHAOS_POSTCONSTRUCTOR; + ode_base_alloc(); } ~lorenz() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 9219390..3358cf5 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -31,17 +31,20 @@ class lozi_map: public: lozi_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0); - CHAOS_SYS_INIT(y,0); - CHAOS_SYS_INIT(a,1.4); - CHAOS_SYS_INIT(b,0.3); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0,0); + CHAOS_SYS_INIT(y,0,1); + + CHAOS_PAR_INIT(a,1.4); + CHAOS_PAR_INIT(b,0.3); + + CHAOS_POSTCONSTRUCTOR; } ~lozi_map() { - delete m_data; + } virtual void m_step() @@ -57,7 +60,12 @@ public: m_data[1] = CHAOS_PARAMETER(b) * x; } - + virtual void m_verify() + { + if (PD_BIGORSMALL(m_data[0])) + m_data[0] = 1; + } + CHAOS_SYSVAR_FUNCS(x, 0); CHAOS_SYSVAR_FUNCS(y, 1); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index c78a7b5..f781f7d 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,7 @@ void chaos_library_setup() { - post("chaos~ version "PACKAGE_VERSION", compiled on "__DATE__" \n"); + post("chaos~ version 0.01, compiled on "__DATE__" \n"); CHAOS_ADD(bernoulli); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index 4b36666..3603a58 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -31,25 +31,27 @@ class roessler public: roessler() { - m_num_eq = 3; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(method,0); - CHAOS_SYS_INIT(x1,0); - CHAOS_SYS_INIT(x2,0); - CHAOS_SYS_INIT(x3,0); - CHAOS_SYS_INIT(a,4); - CHAOS_SYS_INIT(b,4); - CHAOS_SYS_INIT(c,4); - CHAOS_SYS_INIT(dt,0.01); + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + CHAOS_SYS_INIT(x1,0,0); + CHAOS_SYS_INIT(x2,0,1); + CHAOS_SYS_INIT(x3,0,2); + + CHAOS_PAR_INIT(a,4); + CHAOS_PAR_INIT(b,4); + CHAOS_PAR_INIT(c,4); + + CHAOS_POSTCONSTRUCTOR; ode_base_alloc(); } ~roessler() { ode_base_free(); - delete m_data; + } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 8746345..21c7e39 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -32,14 +32,16 @@ class sine_map: public: sine_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x,0); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x,0,0); + + CHAOS_POSTCONSTRUCTOR; } ~sine_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index cadcf1e..663280a 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -32,17 +32,19 @@ class standard_map: public: standard_map() { - m_num_eq = 2; - m_data = new data_t[m_num_eq]; + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(I,0.1,0); + CHAOS_SYS_INIT(theta,0.2,1); + + CHAOS_PAR_INIT(k, 0.8); - CHAOS_SYS_INIT(I,0.1); - CHAOS_SYS_INIT(theta,0.2); - CHAOS_SYS_INIT(k, 0.8); + CHAOS_POSTCONSTRUCTOR; } ~standard_map() { - delete m_data; + } virtual void m_step() diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 8c00a19..e23fb73 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -31,14 +31,16 @@ class tent_map: public: tent_map() { - m_num_eq = 1; - m_data = new data_t[m_num_eq]; - CHAOS_SYS_INIT(x, 0.6); + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.6,0); + + CHAOS_POSTCONSTRUCTOR; } ~tent_map() { - delete m_data; + } virtual void m_step() -- cgit v1.2.1 From d1ed55f96f9cecc818844006fb36cd58ca70da5e Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 16 Jun 2005 13:02:02 +0000 Subject: - parameter searching (broken) - misc. updates svn path=/trunk/externals/tb/; revision=3192 --- chaos/src/bernoulli_search.cpp | 24 ++++ chaos/src/bungalow_tent_search.cpp | 24 ++++ chaos/src/chaos.hpp | 17 +++ chaos/src/chaos_base.hpp | 16 ++- chaos/src/chaos_defs.hpp | 6 +- chaos/src/chaos_dsp.hpp | 55 +++++++-- chaos/src/chaos_search.hpp | 191 ++++++++++++++++++++++++++++++++ chaos/src/chua.hpp | 83 ++++++++++++-- chaos/src/chua_search.cpp | 24 ++++ chaos/src/circle_map_search.cpp | 24 ++++ chaos/src/coupled_logistic.hpp | 12 +- chaos/src/coupled_logistic_msg.cpp | 14 +-- chaos/src/coupled_logistic_search.cpp | 24 ++++ chaos/src/delayed_logistic.hpp | 92 +++++++++++++++ chaos/src/delayed_logistic__search.cpp | 24 ++++ chaos/src/delayed_logistic_dsp.cpp | 23 ++++ chaos/src/delayed_logistic_msg.cpp | 23 ++++ chaos/src/delayed_logistic_search.cpp | 24 ++++ chaos/src/driven_anharmonic_search.cpp | 24 ++++ chaos/src/driven_van_der_pol.hpp | 13 ++- chaos/src/driven_van_der_pol_search.cpp | 24 ++++ chaos/src/duffing_map_search.cpp | 24 ++++ chaos/src/gauss_map_search.cpp | 24 ++++ chaos/src/gaussian_map.hpp | 84 ++++++++++++++ chaos/src/gaussian_map_dsp.cpp | 23 ++++ chaos/src/gaussian_map_msg.cpp | 23 ++++ chaos/src/gaussian_map_search.cpp | 24 ++++ chaos/src/henon_map_search.cpp | 24 ++++ chaos/src/hydrogen.hpp | 156 ++++++++++++++++++++++++++ chaos/src/hydrogen_dsp.cpp | 23 ++++ chaos/src/hydrogen_msg.cpp | 23 ++++ chaos/src/hydrogen_search.cpp | 24 ++++ chaos/src/ikeda_laser_map_search.cpp | 24 ++++ chaos/src/latoocarfian.hpp | 12 +- chaos/src/latoocarfian_search.cpp | 24 ++++ chaos/src/latoomutalpha.hpp | 16 +-- chaos/src/latoomutalpha_search.cpp | 24 ++++ chaos/src/latoomutbeta.hpp | 13 +-- chaos/src/latoomutbeta_search.cpp | 24 ++++ chaos/src/latoomutgamma.hpp | 14 +-- chaos/src/latoomutgamma_search.cpp | 24 ++++ chaos/src/logistic_map.hpp | 4 +- chaos/src/logistic_search.cpp | 24 ++++ chaos/src/lorenz.hpp | 10 ++ chaos/src/lorenz_search.cpp | 24 ++++ chaos/src/lozi_map.hpp | 5 - chaos/src/lozi_map_search.cpp | 24 ++++ chaos/src/main.cpp | 3 + chaos/src/ode_base.hpp | 9 +- chaos/src/roessler.hpp | 10 +- chaos/src/roessler_search.cpp | 24 ++++ chaos/src/sine_map_search.cpp | 24 ++++ chaos/src/standard_map_search.cpp | 24 ++++ chaos/src/tent_map_search.cpp | 24 ++++ 54 files changed, 1504 insertions(+), 93 deletions(-) create mode 100644 chaos/src/bernoulli_search.cpp create mode 100644 chaos/src/bungalow_tent_search.cpp create mode 100644 chaos/src/chaos_search.hpp create mode 100644 chaos/src/chua_search.cpp create mode 100644 chaos/src/circle_map_search.cpp create mode 100644 chaos/src/coupled_logistic_search.cpp create mode 100644 chaos/src/delayed_logistic.hpp create mode 100644 chaos/src/delayed_logistic__search.cpp create mode 100644 chaos/src/delayed_logistic_dsp.cpp create mode 100644 chaos/src/delayed_logistic_msg.cpp create mode 100644 chaos/src/delayed_logistic_search.cpp create mode 100644 chaos/src/driven_anharmonic_search.cpp create mode 100644 chaos/src/driven_van_der_pol_search.cpp create mode 100644 chaos/src/duffing_map_search.cpp create mode 100644 chaos/src/gauss_map_search.cpp create mode 100644 chaos/src/gaussian_map.hpp create mode 100644 chaos/src/gaussian_map_dsp.cpp create mode 100644 chaos/src/gaussian_map_msg.cpp create mode 100644 chaos/src/gaussian_map_search.cpp create mode 100644 chaos/src/henon_map_search.cpp create mode 100644 chaos/src/hydrogen.hpp create mode 100644 chaos/src/hydrogen_dsp.cpp create mode 100644 chaos/src/hydrogen_msg.cpp create mode 100644 chaos/src/hydrogen_search.cpp create mode 100644 chaos/src/ikeda_laser_map_search.cpp create mode 100644 chaos/src/latoocarfian_search.cpp create mode 100644 chaos/src/latoomutalpha_search.cpp create mode 100644 chaos/src/latoomutbeta_search.cpp create mode 100644 chaos/src/latoomutgamma_search.cpp create mode 100644 chaos/src/logistic_search.cpp create mode 100644 chaos/src/lorenz_search.cpp create mode 100644 chaos/src/lozi_map_search.cpp create mode 100644 chaos/src/roessler_search.cpp create mode 100644 chaos/src/sine_map_search.cpp create mode 100644 chaos/src/standard_map_search.cpp create mode 100644 chaos/src/tent_map_search.cpp diff --git a/chaos/src/bernoulli_search.cpp b/chaos/src/bernoulli_search.cpp new file mode 100644 index 0000000..e4fc398 --- /dev/null +++ b/chaos/src/bernoulli_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bernoulli_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(bernoulli, BERNOULLI); diff --git a/chaos/src/bungalow_tent_search.cpp b/chaos/src/bungalow_tent_search.cpp new file mode 100644 index 0000000..d76d195 --- /dev/null +++ b/chaos/src/bungalow_tent_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "bungalow_tent_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(bungalow_tent, BUNGALOW_TENT); diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 0f87b51..2e2eb8b 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -27,6 +27,8 @@ #include "chaos_defs.hpp" #include +#include + /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; @@ -36,6 +38,21 @@ typedef float data_t; #define CHAOS_ABS(x) fabsf(x) #endif +inline data_t chaos_mod(data_t x, data_t y) +{ +#ifdef DOUBLE_PRECISION + return fmod(x,y); +#else + return fmodf(x,y); +#endif +} + +inline data_t rand_range(data_t low, data_t high) +{ + return low + ( (rand() * (high - low)) / RAND_MAX); +} + + #define __chaos_hpp #endif /* __chaos_hpp */ diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 959afdf..5e2a99f 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -29,26 +29,32 @@ class chaos_base { public: - t_sample get_data(unsigned int i) + inline t_sample get_data(unsigned int i) { return (t_sample)m_data[i]; /* this is not save, but fast */ } - int get_num_eq() + inline int get_num_eq() { return m_num_eq; } - void m_perform() + inline void m_perform() { m_step(); + m_bash_denormals(); m_verify(); } - std::map attr_ind; + std::map attr_ind; + // TableAnyMap attr_ind; /* thomas fragen :-) */ // check the integrity of the system virtual void m_verify() + { + } + + inline void m_bash_denormals() { for (int i = 0; i != get_num_eq(); ++i) { @@ -58,7 +64,7 @@ public: #endif } }; - + data_t m_data[MAXDIMENSION]; // state of the system protected: diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index d9f60d8..bf8607c 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -97,7 +97,8 @@ data_t m_##NAME; #define CHAOS_SYS_CALLBACKS(NAME) \ -public:void get_##NAME(t_float &f) \ +public: \ +void get_##NAME(t_float &f) \ { \ f = m_system->get_##NAME(); \ } \ @@ -135,6 +136,9 @@ flext::SetSymbol(atom_##NAME, flext::MakeSymbol(#NAME)); \ System.Append(atom_##NAME); \ attr_ind[flext::MakeSymbol(#NAME)] = INDEX; +#define CHAOS_SYS_INIT_HIDDEN(NAME, VALUE, INDEX) \ +set_##NAME(VALUE); + #define CHAOS_PAR_INIT(NAME, VALUE) \ set_##NAME(VALUE); \ t_atom atom_##NAME; \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index bb3c5fa..16e2820 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -28,13 +28,15 @@ template class chaos_dsp public: /* signal functions: */ - /* for frequency = sr/2 */ + /* for frequency = sr */ void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); /* sample & hold */ void m_signal_n(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* sample & hold for high frequencies */ + void m_signal_n_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); /* linear interpolation */ void m_signal_l(int n, t_sample *const *insigs,t_sample *const *outsigs); - /* cubic interpolatio */ + /* cubic interpolation */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs) @@ -45,8 +47,9 @@ public: virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) { m_sr = Samplerate(); + set_freq(m_freq); /* maybe we have to change the interpolation mode */ } - + void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); /* local data for system, output and interpolation */ @@ -63,6 +66,7 @@ public: float m_freq; /* frequency of oscillations */ float m_invfreq; /* inverse frequency */ int m_phase; /* phase counter */ + float m_fphase; /* phase for high frequency linear interpolation */ float m_sr; /* sample rate */ int m_imethod; /* interpolation method */ @@ -123,18 +127,22 @@ public: void set_freq(float f) { - if( (f >= 0) && (f <= m_sr*0.5) ) + if (f < 0) /* we can't go back in time :-) */ + f = -f; + + if( f <= m_sr * 0.5 ) { - if (m_freq == -1) + if (m_freq >= m_sr * 0.5) set_imethod(m_imethod); m_freq = f; m_invfreq = 1.f / f; } - else if (f == -1) + else if (f > m_sr * 0.5) { - m_freq = -1; + m_freq = f; + m_invfreq = 1.f / f; - m_routine = &thisType::m_signal_; + m_routine = &thisType::m_signal_n_hf; } else post("frequency out of range"); @@ -145,6 +153,7 @@ public: }; + /* create constructor / destructor */ #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ @@ -228,9 +237,39 @@ void chaos_dsp::m_signal_(int n, t_sample *const *insigs, outsigs[j][i] = m_system->get_data(j); } } +} + + +template +void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + float phase = m_fphase; + + int offset = 0; + while (n) + { + while (phase <= 0) + { + m_system->m_perform(); + phase += m_sr * m_invfreq; + } + int next = (phase < n) ? int(ceilf (phase)) : n; + n -= next; + phase -=next; + + for (int i = 0; i != outlets; ++i) + { + SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + } + offset += next; + } + m_fphase = phase; } + template void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, t_sample *const *outsigs) diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp new file mode 100644 index 0000000..a7fc44d --- /dev/null +++ b/chaos/src/chaos_search.hpp @@ -0,0 +1,191 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chaos_base.hpp" + +template class chaos_search + : public flext_base +{ + FLEXT_HEADER(chaos_search, flext_base); + +public: + + /* local data for system, output and interpolation */ + system * m_system; /* the system */ + + + data_t min[MAXDIMENSION]; /* minimal coordinates */ + data_t max[MAXDIMENSION]; /* maximal coordinates */ + data_t final[MAXDIMENSION]; /* initial coordinates for outlet */ + + data_t ly; /* lyapunov exponent */ + + int m_transient_steps; /* steps before starting the analysis */ + int m_asymptotic_steps; /* steps for the analysis */ + + + void get_tsteps(int &i) + { + i = m_transient_steps; + } + + void set_tsteps(int i) + { + if (i > 0) + m_transient_steps = i; + else + m_transient_steps = 0; + } + + void get_asteps(int &i) + { + i = m_asymptotic_steps; + } + + void set_asteps(int &i) + { + if (i > 0) + m_asymptotic_steps = i; + else + m_asymptotic_steps = 0; + } + + void print_results(void) + { + /* - send parameters to 1 + - send initial coordinates to 2 + - send minimal coordinates to 3 + - send lyapunov exponent to 4 + */ + + for (std::map::iterator it = m_system->attr_ind.begin(); + it != m_system->attr_ind.end(); ++it) + { + post("key %s", it->first->s_name); + post("value %f", m_system->get_data(it->second)); + } + } + + void m_search(); + + FLEXT_CALLBACK(m_bang); + FLEXT_CALLVAR_I(get_tsteps, set_tsteps); + FLEXT_CALLVAR_I(get_asteps, set_asteps); + FLEXT_THREAD(m_search); +}; + + +/* create constructor / destructor */ + +#define CHAOS_SEARCH_INIT(SYSTEM, ATTRIBUTES) \ +FLEXT_HEADER(SYSTEM##_search, chaos_search) \ + \ +SYSTEM##_search(int argc, t_atom* argv ) \ +{ \ + m_system = new SYSTEM; \ + \ + int size = m_system->get_num_eq(); \ + \ + \ + m_asymptotic_steps = 10000; \ + m_transient_steps = 100; \ + \ + AddOutList("parameters"); \ + AddOutList("initial coordinates"); \ + AddOutList("minimal coordinates"); \ + AddOutList("maximal coordinates"); \ + AddOutFloat("lyapunov exponent"); \ + \ + FLEXT_ADDATTR_VAR("transient_steps", get_tsteps, set_tsteps); \ + FLEXT_ADDATTR_VAR("steps", get_asteps, set_asteps); \ + ATTRIBUTES; \ + FLEXT_ADDMETHOD_(0,"search", m_search); \ +} \ + \ +~SYSTEM##_search() \ +{ \ + delete m_system; \ +} \ + \ +FLEXT_ATTRVAR_I(m_transient_steps); \ +FLEXT_ATTRVAR_I(m_asymptotic_steps); + + + +template +void chaos_search::m_search() +{ + int dimensions = m_system->get_num_eq(); + + ly = 0; + data_t diff_old = 0.1; + data_t last[MAXDIMENSION]; + + /* transient dynamics */ + for (int i = 0; i != m_transient_steps; ++i) + { + m_system->m_perform(); + } + + for (int i = 0; i != dimensions; ++i) + { + last[i] = min[i] = max[i] = m_system->m_data[i]; + } + + /* now we start the analysis */ + + for (int i = 0; i != m_asymptotic_steps; ++i) + { + + m_system->m_perform(); + + data_t diff = 0; + for (int j = 0; j != dimensions; ++j) + { + /* update min/max */ + data_t datum = m_system->m_data[j]; + if (datum > max[j]) + max[j] = datum; + else if (datum < min[j]) + min[j] = datum; + + /* sum up diff */ + diff += (last[j] - datum) * (last[j] - datum); + + last[j] = datum; + } + diff = sqrt(diff); + + if (diff < 0) + diff = -diff; + + ly += log(diff / diff_old); + diff_old = diff; + + /* todo: maybe some overflow checking */ + if (diff == 0) + break; + } + + + ly /= m_asymptotic_steps; + + print_results(); +} diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index e54df47..3d44708 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -28,7 +28,7 @@ // a*x (for -1 <= x <= 1 // b*x - a + b (for x < -1) // -// taken from Viktor Avrutin: lecture note +// taken from Viktor Avrutin: lecture notes class chua: public ode_base @@ -38,14 +38,17 @@ public: { CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,1,0); + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.05); + + CHAOS_SYS_INIT(x1,1,1); CHAOS_SYS_INIT(x2,1,1); - CHAOS_SYS_INIT(x3,1,2); + CHAOS_SYS_INIT(x3,1,1); - CHAOS_PAR_INIT(a,1.4); - CHAOS_PAR_INIT(b,0.3); - CHAOS_PAR_INIT(alpha,0.3); - CHAOS_PAR_INIT(beta,0.3); + CHAOS_PAR_INIT(a,140); + CHAOS_PAR_INIT(b,30); + CHAOS_PAR_INIT(alpha,30); + CHAOS_PAR_INIT(beta,30); CHAOS_POSTCONSTRUCTOR; @@ -79,12 +82,74 @@ public: deriv[2] = - CHAOS_PARAMETER(beta) * x2; } + virtual void m_verify() + { + data_t x1 = m_data[0]; + data_t x2 = m_data[1]; + data_t x3 = m_data[2]; + + if ( CHAOS_ABS(x3) < 1e-10) + x3 = 0; + + if (x1 == 0 && x2 == 0 && x3 == 0) /* fixpoint at (0,0,0) */ + { + reset(); + return; + } + else + { + data_t c = m_c; + if (m_c) + { + data_t mc = - c; + if (x1 == c && x3 == mc) /* fixpoint at (c,0,-c) */ + { + reset(); + return; + } + if (x1 == mc && x3 == c) /* fixpoint at (-c,0,c) */ + { + reset(); + return; + } + } + } + } + + inline void reset() + { + m_data[0] = rand_range(-1,1); + m_data[1] = rand_range(-1,1); + m_data[2] = rand_range(-1,1); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); CHAOS_SYSVAR_FUNCS(x3, 2); - CHAOS_SYSPAR_FUNCS(a); - CHAOS_SYSPAR_FUNCS(b); + /* due to stability issues, we hook into the predicates */ + data_t m_c; + bool m_pred_a(data_t a) + { + data_t b = CHAOS_PARAMETER(b); + m_c = (b - a) / (b + 1); + return true; + } + + bool m_pred_b(data_t b) + { + if (b == -1) + m_c = 0; + else + { + data_t a = CHAOS_PARAMETER(a); + m_c = (b - a) / (b + 1); + } + return true; + } + + CHAOS_SYSPAR_FUNCS_PRED(a, m_pred_a); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); CHAOS_SYSPAR_FUNCS(alpha); CHAOS_SYSPAR_FUNCS(beta); }; diff --git a/chaos/src/chua_search.cpp b/chaos/src/chua_search.cpp new file mode 100644 index 0000000..65e8719 --- /dev/null +++ b/chaos/src/chua_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "chua.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(chua, CHUA); diff --git a/chaos/src/circle_map_search.cpp b/chaos/src/circle_map_search.cpp new file mode 100644 index 0000000..a34bbf8 --- /dev/null +++ b/chaos/src/circle_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "circle_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(circle_map, CIRCLE_MAP); diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 7cc8602..d94ceee 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -22,7 +22,7 @@ // coupled_logistic map: x[n+1] = r * x[n] * (1 - x[n]) + e * (y[n] - x[n]) // y[n+1] = r * y[n] * (1 - y[n]) + e * (x[n] - y[n]) -// 1 <= r <= 4 +// 0 <= r <= 4 // taken from Willi-Hans Steeb: Chaos and Fractals class coupled_logistic: @@ -54,6 +54,7 @@ public: data_t r = CHAOS_PARAMETER(r); m_data[0] = r * x * (1.f - x) + e * (y - x); m_data[1] = r * y * (1.f - y) + e * (x - y); + m_verify(); } CHAOS_SYSPAR_FUNCS(e); @@ -76,9 +77,14 @@ public: data_t x = m_data[0]; data_t y = m_data[1]; if (!m_pred_xy(x)) - m_data[0] = 0.5; + m_data[0] = rand_range(0,0.08); if (!m_pred_xy(y)) - m_data[1] = 0.5; + m_data[1] = rand_range(0,0.08); + if (x == y) + { + m_data[0] += rand_range(0,0.2); + m_data[1] += -rand_range(0,0.2); + } } diff --git a/chaos/src/coupled_logistic_msg.cpp b/chaos/src/coupled_logistic_msg.cpp index 994a79d..15ef289 100644 --- a/chaos/src/coupled_logistic_msg.cpp +++ b/chaos/src/coupled_logistic_msg.cpp @@ -1,7 +1,7 @@ // // // chaos~ -// Copyright (C) 2004 Tim Blechmann +// Copyright (C) 2005 Tim Blechmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,14 +21,4 @@ #include "coupled_logistic.hpp" #include "chaos_msg.hpp" -class coupled_logistic_msg: - public chaos_msg -{ - CHAOS_MSG_INIT(coupled_logistic, COUPLED_LOGISTIC_ATTRIBUTES); - - COUPLED_LOGISTIC_CALLBACKS; -}; - - - -FLEXT_LIB_V("coupled_logistic", coupled_logistic_msg); +CHAOS_MSG_CLASS(coupled_logistic,COUPLED_LOGISTIC) diff --git a/chaos/src/coupled_logistic_search.cpp b/chaos/src/coupled_logistic_search.cpp new file mode 100644 index 0000000..f75938f --- /dev/null +++ b/chaos/src/coupled_logistic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "coupled_logistic.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(coupled_logistic, COUPLED_LOGISTIC); diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp new file mode 100644 index 0000000..c78785f --- /dev/null +++ b/chaos/src/delayed_logistic.hpp @@ -0,0 +1,92 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// delayed logistic map: x[n+1] = alpha * x[n] * (1 - x[n-1]) +// 0 < x[n] < 1 +// 0 <= alpha <= 4 +// taken from E. Atlee Jackson: Perspective of nonlinear dynamics (Vol. 2) + +class delayed_logistic: + public map_base +{ +public: + delayed_logistic() + { + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.5, 0); + + CHAOS_PAR_INIT(alpha, 3.8); + + CHAOS_POSTCONSTRUCTOR; + + m_delayed = get_x(); /* the initial state of the delay */ + } + + ~delayed_logistic() + { + + } + + virtual void m_step() + { + data_t x = m_data[0]; + data_t alpha = CHAOS_PARAMETER(alpha); + data_t delayed = m_delayed; + + m_delayed = x; + m_data[0] = alpha * x * (1.f - delayed); + + } + data_t m_delayed; + + CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); + bool m_pred_alpha(t_float f) + { + return (f > 0) && (f < 4); + } + + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) + { + return (f > 0) && (f < 1); + } + + virtual void m_verify() + { + data_t x = m_data[0]; + if (m_pred_x(x)) + return; + m_data[0] = 0.5; + } +}; + +#define DELAYED_LOGISTIC_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(x); + +#define DELAYED_LOGISTIC_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(x); + diff --git a/chaos/src/delayed_logistic__search.cpp b/chaos/src/delayed_logistic__search.cpp new file mode 100644 index 0000000..c082637 --- /dev/null +++ b/chaos/src/delayed_logistic__search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic_.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(delayed_logistic_, DELAYED_LOGISTIC_); diff --git a/chaos/src/delayed_logistic_dsp.cpp b/chaos/src/delayed_logistic_dsp.cpp new file mode 100644 index 0000000..1dec6d0 --- /dev/null +++ b/chaos/src/delayed_logistic_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(delayed_logistic,DELAYED_LOGISTIC); diff --git a/chaos/src/delayed_logistic_msg.cpp b/chaos/src/delayed_logistic_msg.cpp new file mode 100644 index 0000000..10c1b89 --- /dev/null +++ b/chaos/src/delayed_logistic_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(delayed_logistic,DELAYED_LOGISTIC); diff --git a/chaos/src/delayed_logistic_search.cpp b/chaos/src/delayed_logistic_search.cpp new file mode 100644 index 0000000..462e6bf --- /dev/null +++ b/chaos/src/delayed_logistic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "delayed_logistic.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(delayed_logistic, DELAYED_LOGISTIC); diff --git a/chaos/src/driven_anharmonic_search.cpp b/chaos/src/driven_anharmonic_search.cpp new file mode 100644 index 0000000..f05ff85 --- /dev/null +++ b/chaos/src/driven_anharmonic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_anharmonic.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(driven_anharmonic, DRIVEN_ANHARMONIC); diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 65290ee..6156eb0 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -37,7 +37,7 @@ public: { CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); CHAOS_SYS_INIT(u1,0.8, 0); @@ -68,9 +68,16 @@ public: deriv[2] = CHAOS_PARAMETER(Omega); } + virtual void m_verify() + { + /* make sure to stay in the range of 2 pi */ + if (m_data[2] > 2*M_PI) + m_data[2] = chaos_mod(m_data[2], 2*M_PI); + } + CHAOS_SYSVAR_FUNCS(u1, 0); CHAOS_SYSVAR_FUNCS(u2, 1); - CHAOS_SYSVAR_FUNCS(u3, 2); + CHAOS_SYSVAR_FUNCS(u3, 2); CHAOS_SYSPAR_FUNCS(a); CHAOS_SYSPAR_FUNCS(k); @@ -82,6 +89,7 @@ public: ODE_CALLBACKS; \ CHAOS_SYS_CALLBACKS(u1); \ CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(u3); \ CHAOS_SYS_CALLBACKS(a); \ CHAOS_SYS_CALLBACKS(k); \ CHAOS_SYS_CALLBACKS(Omega); @@ -90,6 +98,7 @@ CHAOS_SYS_CALLBACKS(Omega); ODE_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(u1); \ CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(u3); \ CHAOS_SYS_ATTRIBUTE(a); \ CHAOS_SYS_ATTRIBUTE(k); \ CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/driven_van_der_pol_search.cpp b/chaos/src/driven_van_der_pol_search.cpp new file mode 100644 index 0000000..63cc308 --- /dev/null +++ b/chaos/src/driven_van_der_pol_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "driven_van_der_pol.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(driven_van_der_pol, DRIVEN_VAN_DER_POL); diff --git a/chaos/src/duffing_map_search.cpp b/chaos/src/duffing_map_search.cpp new file mode 100644 index 0000000..d6d3168 --- /dev/null +++ b/chaos/src/duffing_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(duffing_map, DUFFING_MAP); diff --git a/chaos/src/gauss_map_search.cpp b/chaos/src/gauss_map_search.cpp new file mode 100644 index 0000000..db8206a --- /dev/null +++ b/chaos/src/gauss_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gauss_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(gauss_map, GAUSS_MAP); diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp new file mode 100644 index 0000000..5f5a4b1 --- /dev/null +++ b/chaos/src/gaussian_map.hpp @@ -0,0 +1,84 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + + +// gaussian map: x[n+1] = exp(-b * x[n] * x[n]) + c +// +// taken from Robert C. Hilborn: Chaos and Nonlinear Dynamics + +class gaussian_map: + public map_base +{ +public: + gaussian_map() + { + CHAOS_PRECONSTRUCTOR; + + CHAOS_SYS_INIT(x, 0.5, 0); + + CHAOS_PAR_INIT(b,7); + CHAOS_PAR_INIT(c,0.5); + + CHAOS_POSTCONSTRUCTOR; + } + + ~gaussian_map() + { + + } + + virtual void m_step() + { + data_t data = m_data[0]; + + if (data == 0) + m_data[0] = 0.001; + else + m_data[0] = exp(-CHAOS_PARAMETER(b) * data * data) + + CHAOS_PARAMETER(c); + } + + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) + { + return (f >= 0) && (f < 1); + } + + CHAOS_SYSPAR_FUNCS(b); + CHAOS_SYSPAR_FUNCS(c); + +}; + +#define GAUSSIAN_MAP_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(c); + +#define GAUSSIAN_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(c); + + + diff --git a/chaos/src/gaussian_map_dsp.cpp b/chaos/src/gaussian_map_dsp.cpp new file mode 100644 index 0000000..d548dc0 --- /dev/null +++ b/chaos/src/gaussian_map_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gaussian_map.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(gaussian_map,GAUSSIAN_MAP); diff --git a/chaos/src/gaussian_map_msg.cpp b/chaos/src/gaussian_map_msg.cpp new file mode 100644 index 0000000..e5aede1 --- /dev/null +++ b/chaos/src/gaussian_map_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gaussian_map.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(gaussian_map,GAUSSIAN_MAP); diff --git a/chaos/src/gaussian_map_search.cpp b/chaos/src/gaussian_map_search.cpp new file mode 100644 index 0000000..16efd8e --- /dev/null +++ b/chaos/src/gaussian_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "gaussian_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(gaussian_map, GAUSSIAN_MAP); diff --git a/chaos/src/henon_map_search.cpp b/chaos/src/henon_map_search.cpp new file mode 100644 index 0000000..d7f3712 --- /dev/null +++ b/chaos/src/henon_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "henon_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(henon, HENON); diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp new file mode 100644 index 0000000..886539c --- /dev/null +++ b/chaos/src/hydrogen.hpp @@ -0,0 +1,156 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +#include "ode_base.hpp" + +// hydrogen atom in a magnetic field + +class hydrogen + : public ode_base +{ + + +public: + hydrogen() + { + CHAOS_PRECONSTRUCTOR; + + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.01); + + CHAOS_SYS_INIT(mu,0.8, 0); + CHAOS_SYS_INIT(muv,0.6, 1); + CHAOS_SYS_INIT(nu,0.4, 2); + CHAOS_SYS_INIT(nuv,0.4, 3); + + CHAOS_PAR_INIT(etilde,-0.3); + + CHAOS_POSTCONSTRUCTOR; + ode_base_alloc(); + reset = 0; + } + + ~hydrogen() + { + ode_base_free(); + } + + virtual void m_system(data_t* deriv, data_t* data) + { + if (reset) + { + (this->*reset)(); + reset = 0; + } + + data_t mu = m_data[0], muv = m_data[1], nu = m_data[2], nuv = m_data[3]; + data_t E = CHAOS_PARAMETER(etilde); + + deriv[0] = muv; + deriv[1] = 2* E * mu - 0.25 * mu * nu * nu * (2*mu*mu+nu*nu); + deriv[2] = nuv; + deriv[3] = 2* E * nu - 0.25 * nu * mu * mu * (2*nu*nu+mu*mu); + } + + virtual void m_verify() + { + /* make sure to stay in the range of 2 pi */ + for (int i = 0; i != get_num_eq(); ++ i) + { + if (m_data[i] > 1) + m_data[i] = 1; + else if (m_data[i] < -1) + m_data[i] = -1; + } + } + + void reset_nuv() + { + data_t mu = m_data[0], muv = m_data[1], nu = m_data[2]; + data_t E = CHAOS_PARAMETER(etilde); + + m_data[1]= sqrt ( 2 * E * (mu*mu + nu*nu) - muv*muv - ( mu*mu * nu*nu * + ( mu*mu + nu*nu )) * 0.25); + +// if (fabs((data[3]))<1e-5) +// data[3]=0; + } + + void reset_muv() + { + data_t mu = m_data[0], nu = m_data[2], nuv = m_data[3]; + data_t E = CHAOS_PARAMETER(etilde); + + m_data[1]= sqrt ( 2 * E * (mu*mu + nu*nu) - nuv*nuv - ( mu*mu * nu*nu * + ( mu*mu + nu*nu )) * 0.25); + +// if (fabs((data[1]))<1e-5) +// data[1]=0; + } + + + /* hook into the predicate to reset the system */ + bool m_pred_pos(t_float f) + { + if (fabs(f) > 1) + return false; + reset = &hydrogen::reset_nuv; + return true; + } + + bool m_pred_nuv(t_float f) + { + reset = &hydrogen::reset_muv; + return true; + } + + bool m_pred_muv(t_float f) + { + reset = &hydrogen::reset_nuv; + return true; + } + + void (hydrogen::*reset)(void); + + CHAOS_SYSVAR_FUNCS_PRED(mu, 0, m_pred_pos); + CHAOS_SYSVAR_FUNCS_PRED(muv, 1, m_pred_nuv); + CHAOS_SYSVAR_FUNCS_PRED(nu, 2, m_pred_pos); + CHAOS_SYSVAR_FUNCS_PRED(nuv, 3, m_pred_muv); + + CHAOS_SYSPAR_FUNCS(etilde); +}; + + +#define HYDROGEN_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(mu); \ +CHAOS_SYS_CALLBACKS(muv); \ +CHAOS_SYS_CALLBACKS(nu); \ +CHAOS_SYS_CALLBACKS(nuv); \ +CHAOS_SYS_CALLBACKS(etilde); + +#define HYDROGEN_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(mu); \ +CHAOS_SYS_ATTRIBUTE(muv); \ +CHAOS_SYS_ATTRIBUTE(nu); \ +CHAOS_SYS_ATTRIBUTE(nuv); \ +CHAOS_SYS_ATTRIBUTE(etilde); diff --git a/chaos/src/hydrogen_dsp.cpp b/chaos/src/hydrogen_dsp.cpp new file mode 100644 index 0000000..118cbc4 --- /dev/null +++ b/chaos/src/hydrogen_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "hydrogen.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(hydrogen,HYDROGEN); diff --git a/chaos/src/hydrogen_msg.cpp b/chaos/src/hydrogen_msg.cpp new file mode 100644 index 0000000..b4da4b3 --- /dev/null +++ b/chaos/src/hydrogen_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "hydrogen.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(hydrogen,HYDROGEN); diff --git a/chaos/src/hydrogen_search.cpp b/chaos/src/hydrogen_search.cpp new file mode 100644 index 0000000..ab7e1c4 --- /dev/null +++ b/chaos/src/hydrogen_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "hydrogen.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(hydrogen, HYDROGEN); diff --git a/chaos/src/ikeda_laser_map_search.cpp b/chaos/src/ikeda_laser_map_search.cpp new file mode 100644 index 0000000..1370329 --- /dev/null +++ b/chaos/src/ikeda_laser_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ikeda_laser_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(ikeda_laser_map, IKEDA_LASER_MAP); diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 9884fd1..9bfba90 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -82,14 +82,10 @@ public: /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; -#endif - } - }; + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } }; diff --git a/chaos/src/latoocarfian_search.cpp b/chaos/src/latoocarfian_search.cpp new file mode 100644 index 0000000..c057301 --- /dev/null +++ b/chaos/src/latoocarfian_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoocarfian.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoocarfian, LATOOCARFIAN); diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ca99c12..ff0cf9f 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -62,19 +62,15 @@ public: tmp2 = sin(x2*c); m_data[1] = sin(x1*a) + tmp1*tmp1 + tmp2*tmp2*tmp2; } - + /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.5; -#endif - } - }; - + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutalpha_search.cpp b/chaos/src/latoomutalpha_search.cpp new file mode 100644 index 0000000..0dfecc3 --- /dev/null +++ b/chaos/src/latoomutalpha_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutalpha.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoomutalpha, LATOOMUTALPHA); diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index e27e5a2..a3562c8 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -60,18 +60,13 @@ public: m_data[1] = sin(x1*a) + tmp*tmp; } - /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; -#endif - } - }; + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutbeta_search.cpp b/chaos/src/latoomutbeta_search.cpp new file mode 100644 index 0000000..1fecfa5 --- /dev/null +++ b/chaos/src/latoomutbeta_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutbeta.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoomutbeta, LATOOMUTBETA); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index fcdf6a6..b9c8c08 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -64,15 +64,11 @@ public: /* function has a fix point for x1 == x2 == 0 */ virtual void m_verify() { - for (int i = 0; i != get_num_eq(); ++i) - { -#ifndef DOUBLE_PRECISION - if (PD_BIGORSMALL(m_data[i])) - m_data[i] = 0.01; -#endif - } - }; - + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(0,0.1); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/latoomutgamma_search.cpp b/chaos/src/latoomutgamma_search.cpp new file mode 100644 index 0000000..16e05c9 --- /dev/null +++ b/chaos/src/latoomutgamma_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "latoomutgamma.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(latoomutgamma, LATOOMUTGAMMA); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 16e824e..c01abcc 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -51,14 +51,14 @@ public: } CHAOS_SYSPAR_FUNCS_PRED(alpha, m_pred_alpha); - bool m_pred_alpha(t_float f) + bool m_pred_alpha(data_t f) { return (f > 0) && (f < 4); } CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); - bool m_pred_x(t_float f) + bool m_pred_x(data_t f) { return (f > 0) && (f < 1); } diff --git a/chaos/src/logistic_search.cpp b/chaos/src/logistic_search.cpp new file mode 100644 index 0000000..aaea340 --- /dev/null +++ b/chaos/src/logistic_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "logistic_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(logistic, LOGISTIC); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index ee4e516..e94f027 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -63,6 +63,16 @@ public: deriv[1] = - x1 * x3 + CHAOS_PARAMETER(r) * x1 - x2; deriv[2] = x1 * x2 - CHAOS_PARAMETER(b) * x3; } + + + /* function has a fix point for x1 == x2 == x3 == 0 */ + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + CHAOS_SYSVAR_FUNCS(x1, 0); CHAOS_SYSVAR_FUNCS(x2, 1); diff --git a/chaos/src/lorenz_search.cpp b/chaos/src/lorenz_search.cpp new file mode 100644 index 0000000..a7a9509 --- /dev/null +++ b/chaos/src/lorenz_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lorenz.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(lorenz, LORENZ); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 3358cf5..b30a95b 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -60,11 +60,6 @@ public: m_data[1] = CHAOS_PARAMETER(b) * x; } - virtual void m_verify() - { - if (PD_BIGORSMALL(m_data[0])) - m_data[0] = 1; - } CHAOS_SYSVAR_FUNCS(x, 0); CHAOS_SYSVAR_FUNCS(y, 1); diff --git a/chaos/src/lozi_map_search.cpp b/chaos/src/lozi_map_search.cpp new file mode 100644 index 0000000..02f2db5 --- /dev/null +++ b/chaos/src/lozi_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "lozi_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(lozi_map, LOZI_MAP); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index f781f7d..53bd62e 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -31,11 +31,14 @@ void chaos_library_setup() CHAOS_ADD(circle_map); CHAOS_ADD(coupled_logistic); CHAOS_ADD(chua); + CHAOS_ADD(delayed_logistic); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); CHAOS_ADD(duffing_map); CHAOS_ADD(gauss_map); + CHAOS_ADD(gaussian_map); CHAOS_ADD(henon); + CHAOS_ADD(hydrogen); CHAOS_ADD(ikeda_laser_map); CHAOS_ADD(latoocarfian); CHAOS_ADD(latoomutalpha); diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index a15dc08..b7139d2 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -68,7 +68,7 @@ public: void ode_base_alloc() { int dimension = get_num_eq(); - + for (int i = 0; i != 3; ++i) { m_k[i] = new data_t[dimension]; @@ -87,15 +87,14 @@ public: } protected: - void (ode_base::*m_routine)(); + void (ode_base::*m_routine)(void); + unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ data_t* m_k[3]; /* temporary arrays for runge kutta */ data_t* m_tmp; - virtual void m_system (data_t* deriv, data_t* data) - { - } + virtual void m_system (data_t* deriv, data_t* data) = 0; void rk1 (); void rk2 (); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index 3603a58..e2c55e0 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -34,11 +34,11 @@ public: CHAOS_PRECONSTRUCTOR; CHAOS_PAR_INIT(method,0); - CHAOS_PAR_INIT(dt,0.01); + CHAOS_PAR_INIT(dt,0.001); - CHAOS_SYS_INIT(x1,0,0); - CHAOS_SYS_INIT(x2,0,1); - CHAOS_SYS_INIT(x3,0,2); + CHAOS_SYS_INIT(x1,0.2,0); + CHAOS_SYS_INIT(x2,0.1,1); + CHAOS_SYS_INIT(x3,0.3,2); CHAOS_PAR_INIT(a,4); CHAOS_PAR_INIT(b,4); @@ -58,7 +58,7 @@ public: { data_t x1 = data[0], x2 = data[1], x3 = data[2]; - deriv[0] = - (x2 - x1); + deriv[0] = - (x2 + x3); deriv[1] = x1 + CHAOS_PARAMETER(a) * x2; deriv[2] = CHAOS_PARAMETER(b) + (x1 - CHAOS_PARAMETER(c)) * x3; } diff --git a/chaos/src/roessler_search.cpp b/chaos/src/roessler_search.cpp new file mode 100644 index 0000000..65596d0 --- /dev/null +++ b/chaos/src/roessler_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "roessler.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(roessler, ROESSLER); diff --git a/chaos/src/sine_map_search.cpp b/chaos/src/sine_map_search.cpp new file mode 100644 index 0000000..94fd2b9 --- /dev/null +++ b/chaos/src/sine_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "sine_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(sine_map, SINE_MAP); diff --git a/chaos/src/standard_map_search.cpp b/chaos/src/standard_map_search.cpp new file mode 100644 index 0000000..62bb535 --- /dev/null +++ b/chaos/src/standard_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "standard_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(standard_map, STANDARD_MAP); diff --git a/chaos/src/tent_map_search.cpp b/chaos/src/tent_map_search.cpp new file mode 100644 index 0000000..ac44587 --- /dev/null +++ b/chaos/src/tent_map_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "tent_map.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(tent_map, TENT_MAP); -- cgit v1.2.1 From 4d376dc11618b760ff2dac83f32d0a052250ab6c Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 16 Jun 2005 13:04:10 +0000 Subject: linux only scons script svn path=/trunk/externals/tb/; revision=3193 --- chaos/SConstruct | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 chaos/SConstruct diff --git a/chaos/SConstruct b/chaos/SConstruct new file mode 100644 index 0000000..3dcf513 --- /dev/null +++ b/chaos/SConstruct @@ -0,0 +1,43 @@ +systems = Split("""bernoulli + bungalow_tent + circle_map + coupled_logistic + chua + delayed_logistic + driven_anharmonic + driven_van_der_pol + duffing_map + gauss_map + gaussian_map + henon_map + hydrogen + ikeda_laser_map + latoocarfian + latoomutalpha + latoomutbeta + latoomutgamma + logistic + lorenz + lozi_map + roessler + sine_map + standard_map + tent_map""") + +sources = [] + +env = Environment(CCFLAGS = '-O3 -g -mtune=pentium-m -march=pentium-m -mmmx -msse -msse2 -mfpmath=sse -I~/pd/devel/pd/src/ -I/usr/local/include/flext -DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') + +for system in systems: + sources.append(system+"_dsp.cpp") + sources.append(system+"_msg.cpp") + sources.append(system+"_search.cpp") +sources += Split("main.cpp ode_base.cpp") + +sources = map(lambda x: "./src/"+x, sources) + +chaos = env.SharedLibrary('chaos', sources, LIBS = 'flext-pd_d', + SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +env.Install('/usr/local/lib/pd/extra',chaos) +env.Alias('install', '/usr/local/lib/pd/extra') -- cgit v1.2.1 From 49d037de7109de167d81dc1fb3cea7c781c20c99 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 21 Jun 2005 09:15:23 +0000 Subject: importing svn path=/trunk/externals/tb/; revision=3227 --- assert/assert.c | 51 +++++++++++++++++++++++++++++++ assert/makefile | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 assert/assert.c create mode 100644 assert/makefile diff --git a/assert/assert.c b/assert/assert.c new file mode 100644 index 0000000..d543510 --- /dev/null +++ b/assert/assert.c @@ -0,0 +1,51 @@ +/* + * + * + * Copyright (C) 2005 Tim Blechmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "m_pd.h" + +/* -------------------- assert ----------------------------- */ + +static t_class *assert_class; + +typedef struct _assert +{ + t_object x_obj; +} t_assert; + +static void *assert_new(t_symbol *s) +{ + t_assert *x = (t_assert *)pd_new(assert_class); + return (x); +} + +static void assert_anything(t_assert *x, t_int argc, t_atom* argv) +{ + pd_error(x, "Assertion failed"); +} + +void assert_setup(void) +{ + assert_class = class_new(gensym("assert"), (t_newmethod)assert_new, + 0, sizeof(t_assert), 0, A_DEFSYM, 0); + class_addanything(assert_class, assert_anything); +} + + diff --git a/assert/makefile b/assert/makefile new file mode 100644 index 0000000..3a00de1 --- /dev/null +++ b/assert/makefile @@ -0,0 +1,94 @@ +NAME=assert +CSYM=assert + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From 716c84be13ba425edf49a533ef5ffdfa5f6f4aaf Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 24 Jun 2005 19:39:18 +0000 Subject: importing source svn path=/trunk/externals/tb/; revision=3248 --- block_delay~/block_delay~.c | 99 +++++++++++++++++++++++++++++++++++++++++++++ block_delay~/makefile | 94 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 block_delay~/block_delay~.c create mode 100644 block_delay~/makefile diff --git a/block_delay~/block_delay~.c b/block_delay~/block_delay~.c new file mode 100644 index 0000000..f5cfa4c --- /dev/null +++ b/block_delay~/block_delay~.c @@ -0,0 +1,99 @@ +/* this external is based on nop~ which was part of zexy-1.x, see the copyright notice below: + + * ZEXY is published under the GNU GeneralPublicLicense, that must be shipped with ZEXY. + * if you are using Debian GNU/linux, the GNU-GPL can be found under /usr/share/common-licenses/GPL + * if you still haven't found a copy of the GNU-GPL, have a look at http://www.gnu.org + * + * "pure data" has it's own license, that comes shipped with "pure data". + * + * there are ABSOLUTELY NO WARRANTIES for anything + + it does absolutely the same as z~ 64, but since it uses simd instructions, it's faster. +*/ + + + +/* ------------------------ block_delay~ ----------------------------- */ +/* this will pass trough the signal unchanged except for a delay of 1 block */ + +#include "m_pd.h" + +static t_class *block_delay_tilde_class; + +typedef struct _block_delay +{ + t_object x_obj; + t_float *buf; + int n; + int toggle; +} t_block_delay; + + +static t_int *block_delay_tilde_perfsimd(t_int *w) +{ + t_float *in = (t_float *)w[1]; + t_float *out = (t_float *)w[2]; + t_block_delay *x = (t_block_delay *)w[3]; + int n = x->n; + t_float *rp = x->buf + n * x->toggle, *wp = x->buf + n * (x->toggle ^= 1); + + copyvec_simd(wp, in, n); + copyvec_simd(out, rp, n); + + return (w+4); +} + +static t_int *block_delay_tilde_perform(t_int *w) +{ + t_float *in = (t_float *)w[1]; + t_float *out = (t_float *)w[2]; + t_block_delay *x = (t_block_delay *)w[3]; + int n = x->n; + t_float *rp = x->buf + n * x->toggle, *wp = x->buf + n * (x->toggle ^= 1); + + while (n--) { + *wp++ = *in++; + *out++ = *rp++; + } + + return (w+4); +} + +static void block_delay_tilde_dsp(t_block_delay *x, t_signal **sp) +{ + if (x->n != sp[0]->s_n) + { + if (x->n) + freealignedbytes(x->buf, x->n * 2 * sizeof(t_float)); + x->buf = (t_float *)getalignedbytes(sizeof(t_float) * 2 * (x->n = sp[0]->s_n)); + } + if (simd_check2(sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec)) + dsp_add(block_delay_tilde_perfsimd, 3, sp[0]->s_vec, sp[1]->s_vec, x); + else + dsp_add(block_delay_tilde_perform, 3, sp[0]->s_vec, sp[1]->s_vec, x); +} + +static void block_delay_tilde_free(t_block_delay *x) +{ + if (x->buf) + freealignedbytes(x->buf, x->n * sizeof(t_float)); +} + + +static void *block_delay_tilde_new(void) +{ + t_block_delay *x = (t_block_delay *)pd_new(block_delay_tilde_class); + outlet_new(&x->x_obj, gensym("signal")); + x->toggle = 0; + x->n = 0; + + return (x); +} + +void block_delay_tilde_setup(void) +{ + block_delay_tilde_class = class_new(gensym("block_delay~"), (t_newmethod)block_delay_tilde_new, (t_method)block_delay_tilde_free, + sizeof(t_block_delay), 0, A_DEFFLOAT, 0); + class_addmethod(block_delay_tilde_class, nullfn, gensym("signal"), 0); + class_addmethod(block_delay_tilde_class, (t_method)block_delay_tilde_dsp, gensym("dsp"), 0); +} diff --git a/block_delay~/makefile b/block_delay~/makefile new file mode 100644 index 0000000..d2d0d21 --- /dev/null +++ b/block_delay~/makefile @@ -0,0 +1,94 @@ +NAME=block_delay~ +CSYM=block_delay~ + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From f1c4f4640db0f0446accfbf7013b7b7b53a86c55 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 Aug 2005 14:57:28 +0000 Subject: different range svn path=/trunk/externals/tb/; revision=3439 --- chaos/src/latoomutgamma.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index b9c8c08..daf3608 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -66,7 +66,7 @@ public: { if (m_data[0] == 0 && m_data[1] == 0) for (int i = 0; i != 2; ++i) - m_data[i] = rand_range(0,0.1); + m_data[i] = rand_range(-1,1); } CHAOS_SYSVAR_FUNCS(x1, 0); -- cgit v1.2.1 From 9b669448eb77874a0c99f240171743d6e1001788 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 23 Aug 2005 09:02:07 +0000 Subject: importing init_keyword external svn path=/trunk/externals/tb/; revision=3449 --- init_keyword/SConstruct | 55 ++++++ init_keyword/abs.pd | 12 ++ init_keyword/gpl.txt | 346 ++++++++++++++++++++++++++++++++++++++ init_keyword/init_keyword-help.pd | 5 + init_keyword/init_keyword.cpp | 123 ++++++++++++++ 5 files changed, 541 insertions(+) create mode 100644 init_keyword/SConstruct create mode 100644 init_keyword/abs.pd create mode 100644 init_keyword/gpl.txt create mode 100644 init_keyword/init_keyword-help.pd create mode 100644 init_keyword/init_keyword.cpp diff --git a/init_keyword/SConstruct b/init_keyword/SConstruct new file mode 100644 index 0000000..d78c84e --- /dev/null +++ b/init_keyword/SConstruct @@ -0,0 +1,55 @@ +sources = ['init_keyword.cpp'] + +env = Environment(CCFLAGS = '-DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') + +env.SConsignFile() +env.CacheDir('./obj') + +opt = Options(['options.cache', 'custom.py']) +opt.AddOptions( + BoolOption('debug', 'Build with debugging symbols', False), + ('optimize', 'Optimize for specific architecture', None), + BoolOption('simd', 'build with simd instructions', False), + BoolOption('icc', 'Use intel c compiler', False), + ('prefix', 'install prefix', '/usr/local'), + ('flext_path', 'flext path', None), + ('pd_path', 'pd path', None), + ) + +opt.Update(env) + +opt.Save('options.cache',env) +Help(opt.GenerateHelpText(env)) + + +if env.Dictionary().has_key('flext_path'): + env.Append(CPPPATH=[env['flext_path']]) + +if env.Dictionary().has_key('pd_path'): + env.Append(CPPPATH=[env['pd_path']]) + +if env.Dictionary().has_key('optimize'): + if env['optimize']: + env.Append(CCFLAGS=' -O3 '+env['optimize']) + +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + +if env.Dictionary().has_key('debug') and env['debug']: + env.Append(CCFLAGS=' -g') + env.Append(LIBS = 'flext-pd_d') +else: + env.Append(LIBS = 'flext-pd') + +if env.Dictionary().has_key('icc') and env['icc']: + env['CC']='icc' + env['CXX']='icc' + env['LD']='xild' + env.Append(CCFLAGS=' -ip ') + env.Append(LINKFLAGS=' -i-static '+env['CCFLAGS']) + + +ik = env.SharedLibrary('init_keyword', sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +env.Install('/usr/local/lib/pd/extra',ik) +env.Alias('install', '/usr/local/lib/pd/extra') diff --git a/init_keyword/abs.pd b/init_keyword/abs.pd new file mode 100644 index 0000000..d448d5c --- /dev/null +++ b/init_keyword/abs.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 47 141 init_keyword hello world 2 3; +#X obj 202 176 print world; +#X obj 44 168 print hello; +#X obj 48 118 inlet; +#X obj 174 204 print two; +#X obj 248 204 print dr3i; +#X connect 0 0 2 0; +#X connect 0 1 1 0; +#X connect 0 2 4 0; +#X connect 0 3 5 0; +#X connect 3 0 0 0; diff --git a/init_keyword/gpl.txt b/init_keyword/gpl.txt new file mode 100644 index 0000000..b403f69 --- /dev/null +++ b/init_keyword/gpl.txt @@ -0,0 +1,346 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + diff --git a/init_keyword/init_keyword-help.pd b/init_keyword/init_keyword-help.pd new file mode 100644 index 0000000..39f3416 --- /dev/null +++ b/init_keyword/init_keyword-help.pd @@ -0,0 +1,5 @@ +#N canvas 490 173 354 109 10; +#X obj 43 32 ./abs hello=world world=200 pi 200; +#X obj 42 7 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1 +; +#X connect 1 0 0 0; diff --git a/init_keyword/init_keyword.cpp b/init_keyword/init_keyword.cpp new file mode 100644 index 0000000..7d121db --- /dev/null +++ b/init_keyword/init_keyword.cpp @@ -0,0 +1,123 @@ +// +// +// init_keyword +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include +#include +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500) +#error update flext!!!!!! +#endif + +class init_keyword + : public flext_base +{ + FLEXT_HEADER(init_keyword,flext_base); + +public: + init_keyword(int argc,t_atom *argv) + { + getargs(argc, argv); + + AddInBang(); + + for (int i = 0; i != arguments.Count(); ++i) + { + AddOutAnything(); + } + FLEXT_ADDBANG(0,m_bang); + } + + void m_bang(void) + { + int i = arguments.Count(); + while (i--) + { + if (IsFloat(arguments[i])) + ToOutFloat(i, GetFloat(arguments[i])); + else if(IsSymbol(arguments[i])) + ToOutSymbol(i, GetSymbol(arguments[i])); + else + FLEXT_ASSERT(false); /* we should never get here */ + } + } + +protected: + +private: + void getargs(int& argc,t_atom* &argv) + { + AtomList keywords (argc, argv); + + AtomList canvasargs; + GetCanvasArgs(canvasargs); + + std::map argmap; + + for (int i = 0; i != canvasargs.Count(); ++i) + { + t_atom atom; + CopyAtom(&atom, &canvasargs[i]); + if (IsSymbol(atom)) + { + const char* symbol = GetString(atom); + char keyword[80]; + keyword[0] = 0; + + strncat(keyword, symbol, strcspn(symbol, "=")); + + char* value = strchr(symbol, '='); + + if (value) + { + /* try to convert to float */ + char * endptr; + float fvalue = strtof(value+1, &endptr); + t_atom value_atom; + + if (*endptr) + SetString(value_atom, value+1); + else + SetFloat(value_atom, fvalue); + + argmap[MakeSymbol(keyword)] = value_atom; + } + } + } + + for (int i = 0; i!= keywords.Count(); ++i) + { + if (IsSymbol(keywords[i])) + { + const t_symbol * keyword = GetSymbol(keywords[i]); + t_atom value = argmap[keyword]; + arguments.Append(value); + } + else if (IsFloat(keywords[i])) + arguments.Append(canvasargs[(int)i]); + + }; + } + + AtomList arguments; + FLEXT_CALLBACK(m_bang); +}; + +FLEXT_NEW_V("init_keyword", init_keyword) -- cgit v1.2.1 From 73f00bbeb4f65bc5624c0cfd2f285b3cc94b4686 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 31 Aug 2005 12:24:41 +0000 Subject: new external: Buzz~ svn path=/trunk/externals/tb/; revision=3467 --- Buzz~/Buzz~-help.pd | 12 ++++++ Buzz~/Buzz~.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++++ Buzz~/SConstruct | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Buzz~/package.txt | 2 + 4 files changed, 225 insertions(+) create mode 100644 Buzz~/Buzz~-help.pd create mode 100644 Buzz~/Buzz~.cpp create mode 100644 Buzz~/SConstruct create mode 100644 Buzz~/package.txt diff --git a/Buzz~/Buzz~-help.pd b/Buzz~/Buzz~-help.pd new file mode 100644 index 0000000..3d00d9c --- /dev/null +++ b/Buzz~/Buzz~-help.pd @@ -0,0 +1,12 @@ +#N canvas 0 0 450 300 10; +#X obj 249 210 dac~; +#X obj 253 160 *~ 0.01; +#X obj 119 179 print~; +#X obj 113 129 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 127 112 Buzz~ @frequency 10 @amp 1 @harm 100; +#X connect 1 0 0 0; +#X connect 1 0 0 1; +#X connect 3 0 2 0; +#X connect 4 0 1 0; +#X connect 4 0 2 0; diff --git a/Buzz~/Buzz~.cpp b/Buzz~/Buzz~.cpp new file mode 100644 index 0000000..cb949e7 --- /dev/null +++ b/Buzz~/Buzz~.cpp @@ -0,0 +1,101 @@ +// +// +// direct port of sndobj's Buzz +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + +#define FLEXT_ATTRIBUTES 1 + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500) +#error You need at least flext version 0.5 +#endif + + +class FlextBuzz: + public flext_sndobj +{ + FLEXT_HEADER(FlextBuzz,flext_sndobj); + +public: + FlextBuzz(int argc, t_atom* argv); + + virtual bool NewObjs(); + virtual void FreeObjs(); + virtual void ProcessObjs(); + + Buzz* buzz; + + float freq; + float amp; + int harm; + +private: + + FLEXT_ATTRVAR_F(amp); + FLEXT_ATTRVAR_F(freq); + FLEXT_ATTRVAR_I(harm); +}; + +FLEXT_LIB_DSP_V("Buzz~",FlextBuzz) + + +FlextBuzz::FlextBuzz(int argc, t_atom* argv) +{ + AtomList l(argc, argv); + + FLEXT_ADDATTR_VAR1("frequency", freq); + FLEXT_ADDATTR_VAR1("amp", amp); + FLEXT_ADDATTR_VAR1("harm", harm); + + AddOutSignal(1); +} + + +bool FlextBuzz::NewObjs() +{ + buzz = new Buzz(freq, amp, harm, 0, + 0, Blocksize(), Samplerate()); + + return true; +} + +void FlextBuzz::FreeObjs() +{ + delete buzz; +} + +void FlextBuzz::ProcessObjs() +{ + buzz->SetFreq(freq); + buzz->SetAmp(amp); + buzz->SetHarm(harm); + + buzz->DoProcess(); + + *buzz >> OutObj(0); +} + +static void setup() +{ + FLEXT_DSP_SETUP(FlextBuzz); +} + +FLEXT_LIB_SETUP(Buzz_tilde,setup) diff --git a/Buzz~/SConstruct b/Buzz~/SConstruct new file mode 100644 index 0000000..4782920 --- /dev/null +++ b/Buzz~/SConstruct @@ -0,0 +1,110 @@ +# scons script for flext build system +# Copyright (C) 2005 Tim Blechmann +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + + +env = Environment(CCFLAGS = '-DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') + +env.SConsignFile() +env.CacheDir('./obj') + +opt = Options(['options.cache', 'custom.py']) +opt.AddOptions( + BoolOption('debug', 'Build with debugging symbols', False), + ('optimize', 'Optimize for specific architecture', None), + BoolOption('simd', 'build with simd instructions', False), + ('prefix', 'install prefix', '/usr/local'), + ('flext_path', 'flext path', None), + ('pd_path', 'pd path', None), + ) + +opt.Update(env) + +opt.Save('options.cache',env) +Help(opt.GenerateHelpText(env)) + + +if env.Dictionary().has_key('flext_path'): + env.Append(CPPPATH=[env['flext_path']]) +else: + env.Append(CPPPATH=['../../grill/flext/source']) + + +if env.Dictionary().has_key('pd_path'): + env.Append(CPPPATH=[env['pd_path']]) + +if env.Dictionary().has_key('optimize'): + if env['optimize']: + env.Append(CCFLAGS=' -O3 '+env['optimize']) + +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + +if env.Dictionary().has_key('debug') and env['debug']: + env.Append(CCFLAGS=' -g') + env.Append(LIBS = 'flext-pd_d') +else: + env.Append(LIBS = 'flext-pd') + env.Append(CPPDEFINES="NDEBUG") + +###################################################################### +# +# read package.txt +# + +packagefile = open('./package.txt', 'r') + +desc = {} +line = packagefile.readline() +while line != "": + line = line.strip() + if len(line) > 0 and line[0] != '#' : + var, data = line.split('=') + + while data [-1] == '\\': + nextline = packagefile.readline() + nextline = nextline.strip() + data = data + " " + nextline + + data = data.replace("\\", "") + desc[var] = data + + + line = packagefile.readline() +packagefile.close() + + +name = desc["NAME"] +if not desc.has_key("SRCDIR"): + desc["SRCDIR"] = "." + +sources = map (lambda x: desc["SRCDIR"] + '/' + x, + desc["SRCS"].split()) + +if desc.has_key("INCPATH"): + env.Append(CPPPATH=desc["INCPATH"].strip().replace("-I", "").split()) + +###################################################################### +# +# build +# + +external = env.SharedLibrary(name, sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +prefix = env['prefix'] +env.Install(prefix+'/lib/pd/extra',external) +env.Alias('install', prefix+'/lib/pd/extra') diff --git a/Buzz~/package.txt b/Buzz~/package.txt new file mode 100644 index 0000000..996093d --- /dev/null +++ b/Buzz~/package.txt @@ -0,0 +1,2 @@ +NAME=Buzz~ +SRCS=Buzz~.cpp -- cgit v1.2.1 From f87c94fef5814fbc259280793e1acc4c65051517 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 31 Aug 2005 12:38:18 +0000 Subject: new external: StringFlt~ svn path=/trunk/externals/tb/; revision=3468 --- StringFlt~/SConstruct | 110 ++++++++++++++++++++++++++++++++++++++++++ StringFlt~/StringFlt~-help.pd | 19 ++++++++ StringFlt~/StringFlt~.cpp | 99 +++++++++++++++++++++++++++++++++++++ StringFlt~/package.txt | 2 + 4 files changed, 230 insertions(+) create mode 100644 StringFlt~/SConstruct create mode 100644 StringFlt~/StringFlt~-help.pd create mode 100644 StringFlt~/StringFlt~.cpp create mode 100644 StringFlt~/package.txt diff --git a/StringFlt~/SConstruct b/StringFlt~/SConstruct new file mode 100644 index 0000000..4782920 --- /dev/null +++ b/StringFlt~/SConstruct @@ -0,0 +1,110 @@ +# scons script for flext build system +# Copyright (C) 2005 Tim Blechmann +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + + +env = Environment(CCFLAGS = '-DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') + +env.SConsignFile() +env.CacheDir('./obj') + +opt = Options(['options.cache', 'custom.py']) +opt.AddOptions( + BoolOption('debug', 'Build with debugging symbols', False), + ('optimize', 'Optimize for specific architecture', None), + BoolOption('simd', 'build with simd instructions', False), + ('prefix', 'install prefix', '/usr/local'), + ('flext_path', 'flext path', None), + ('pd_path', 'pd path', None), + ) + +opt.Update(env) + +opt.Save('options.cache',env) +Help(opt.GenerateHelpText(env)) + + +if env.Dictionary().has_key('flext_path'): + env.Append(CPPPATH=[env['flext_path']]) +else: + env.Append(CPPPATH=['../../grill/flext/source']) + + +if env.Dictionary().has_key('pd_path'): + env.Append(CPPPATH=[env['pd_path']]) + +if env.Dictionary().has_key('optimize'): + if env['optimize']: + env.Append(CCFLAGS=' -O3 '+env['optimize']) + +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + +if env.Dictionary().has_key('debug') and env['debug']: + env.Append(CCFLAGS=' -g') + env.Append(LIBS = 'flext-pd_d') +else: + env.Append(LIBS = 'flext-pd') + env.Append(CPPDEFINES="NDEBUG") + +###################################################################### +# +# read package.txt +# + +packagefile = open('./package.txt', 'r') + +desc = {} +line = packagefile.readline() +while line != "": + line = line.strip() + if len(line) > 0 and line[0] != '#' : + var, data = line.split('=') + + while data [-1] == '\\': + nextline = packagefile.readline() + nextline = nextline.strip() + data = data + " " + nextline + + data = data.replace("\\", "") + desc[var] = data + + + line = packagefile.readline() +packagefile.close() + + +name = desc["NAME"] +if not desc.has_key("SRCDIR"): + desc["SRCDIR"] = "." + +sources = map (lambda x: desc["SRCDIR"] + '/' + x, + desc["SRCS"].split()) + +if desc.has_key("INCPATH"): + env.Append(CPPPATH=desc["INCPATH"].strip().replace("-I", "").split()) + +###################################################################### +# +# build +# + +external = env.SharedLibrary(name, sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +prefix = env['prefix'] +env.Install(prefix+'/lib/pd/extra',external) +env.Alias('install', prefix+'/lib/pd/extra') diff --git a/StringFlt~/StringFlt~-help.pd b/StringFlt~/StringFlt~-help.pd new file mode 100644 index 0000000..0cf163a --- /dev/null +++ b/StringFlt~/StringFlt~-help.pd @@ -0,0 +1,19 @@ +#N canvas 453 122 450 300 10; +#X obj 97 80 noise~; +#X obj 100 180 dac~; +#X obj 99 110 *~ 0.01; +#X floatatom 163 74 5 0 0 0 - - -; +#X obj 101 142 StringFlt~; +#X obj 195 204 env~; +#X floatatom 195 234 5 0 0 0 - - -; +#X obj 216 132 env~; +#X floatatom 216 162 5 0 0 0 - - -; +#X connect 0 0 2 0; +#X connect 2 0 4 0; +#X connect 2 0 7 0; +#X connect 3 0 2 1; +#X connect 4 0 1 0; +#X connect 4 0 1 1; +#X connect 4 0 5 0; +#X connect 5 0 6 0; +#X connect 7 0 8 0; diff --git a/StringFlt~/StringFlt~.cpp b/StringFlt~/StringFlt~.cpp new file mode 100644 index 0000000..74da6f7 --- /dev/null +++ b/StringFlt~/StringFlt~.cpp @@ -0,0 +1,99 @@ +// +// +// direct port of sndobj's StringFlt +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + +#define FLEXT_ATTRIBUTES 1 + +#include + +#if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 500) +#error You need at least flext version 0.5 +#endif + + +class FlextStringFlt: + public flext_sndobj +{ + FLEXT_HEADER(FlextStringFlt,flext_sndobj); + +public: + FlextStringFlt(int argc, t_atom* argv); + + virtual bool NewObjs(); + virtual void FreeObjs(); + virtual void ProcessObjs(); + + StringFlt* string; + + float fdbgain; + + float freq; + +private: + + FLEXT_ATTRVAR_F(fdbgain); + FLEXT_ATTRVAR_F(freq); +}; + +FLEXT_LIB_DSP_V("StringFlt~",FlextStringFlt) + + +FlextStringFlt::FlextStringFlt(int argc, t_atom* argv) +{ + AtomList l(argc, argv); + + FLEXT_ADDATTR_VAR1("fdbgain", fdbgain); + FLEXT_ADDATTR_VAR1("frequency", freq); + + AddInSignal(1); + AddOutSignal(1); +} + + +bool FlextStringFlt::NewObjs() +{ + string = new StringFlt(freq, fdbgain, &InObj(0), + 0, Blocksize(), Samplerate()); + + return true; +} + +void FlextStringFlt::FreeObjs() +{ + delete string; +} + +void FlextStringFlt::ProcessObjs() +{ + string->SetFreq(freq); + string->SetFdbgain(fdbgain); + + string->DoProcess(); + + *string >> OutObj(0); +} + +static void setup() +{ + FLEXT_DSP_SETUP(FlextStringFlt); +} + +FLEXT_LIB_SETUP(StringFlt_tilde,setup) diff --git a/StringFlt~/package.txt b/StringFlt~/package.txt new file mode 100644 index 0000000..745e3db --- /dev/null +++ b/StringFlt~/package.txt @@ -0,0 +1,2 @@ +NAME=StringFlt~ +SRCS=StringFlt~.cpp -- cgit v1.2.1 From 1e17420038c1737ee6aabd4f9cc7dc833bb776f0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 10 Sep 2005 15:47:23 +0000 Subject: libsndfile base soundfiler. - supports only read command - no resize / nframe flags svn path=/trunk/externals/tb/; revision=3521 --- sndfiler/makefile | 94 ++++++++++++++ sndfiler/sndfiler-help.pd | 10 ++ sndfiler/sndfiler.c | 321 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 425 insertions(+) create mode 100644 sndfiler/makefile create mode 100644 sndfiler/sndfiler-help.pd create mode 100644 sndfiler/sndfiler.c diff --git a/sndfiler/makefile b/sndfiler/makefile new file mode 100644 index 0000000..f44a8da --- /dev/null +++ b/sndfiler/makefile @@ -0,0 +1,94 @@ +NAME=sndfiler +CSYM=sndfiler + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I/home/tim/pd/devel_0_39/src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm -lsndfile +# $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations diff --git a/sndfiler/sndfiler-help.pd b/sndfiler/sndfiler-help.pd new file mode 100644 index 0000000..fe9de17 --- /dev/null +++ b/sndfiler/sndfiler-help.pd @@ -0,0 +1,10 @@ +#N canvas 0 0 450 300 10; +#X obj 36 103 sndfiler; +#X obj 294 87 table array; +#X msg 37 60 read \$1 array; +#X obj 38 33 openpanel; +#X obj 124 15 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 2 0 0 0; +#X connect 3 0 2 0; +#X connect 4 0 3 0; diff --git a/sndfiler/sndfiler.c b/sndfiler/sndfiler.c new file mode 100644 index 0000000..29c692a --- /dev/null +++ b/sndfiler/sndfiler.c @@ -0,0 +1,321 @@ +/* + * + * soundfiler based on libsndfile + * Copyright (C) 2005 Tim Blechmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + + +#include "stdlib.h" +#include "m_pd.h" +#include "g_canvas.h" +#include "m_fifo.h" +#include "pthread.h" /* for helper thread */ +#include "sched.h" /* for thread priority */ +#include "alloca.h" + +#include "sndfile.h" + +#if (_POSIX_MEMLOCK - 0) >= 200112L +#include +#endif /* _POSIX_MEMLOCK */ + +static t_class *sndfiler_class; + + +typedef struct _sndfiler +{ + t_object x_obj; + t_canvas *x_canvas; +} t_sndfiler; + +typedef struct _sfprocess +{ + void* padding; + void (* process) (t_sndfiler *, + int, t_atom *); /* callback function */ + t_sndfiler * x; /* soundfiler */ + int argc; + t_atom * argv; +} t_sfprocess; + + +/* this is the queue for all soundfiler objects */ +typedef struct _sfqueue +{ + t_fifo* x_jobs; + + pthread_mutex_t mutex; + pthread_cond_t cond; +} t_sfqueue; + + +typedef struct _syncdata +{ + t_garray** arrays; + t_float** helper_arrays; + int argc; + t_int frames; +} t_syncdata; + + +static t_sfqueue sndfiler_queue; +static pthread_t sf_thread_id; /* id of soundfiler thread */ + + +static t_sndfiler *sndfiler_new(void) +{ + t_sndfiler *x = (t_sndfiler *)pd_new(sndfiler_class); + x->x_canvas = canvas_getcurrent(); + outlet_new(&x->x_obj, &s_float); + return (x); +} + + +/* global soundfiler thread ... sleeping until signaled */ +static void sndfiler_thread(void) +{ + while (1) + { + t_sfprocess * me; + pthread_cond_wait(&sndfiler_queue.cond, &sndfiler_queue.mutex); + + while (me = (t_sfprocess *)fifo_get(sndfiler_queue.x_jobs)) + { + (me->process)(me->x, me->argc, me->argv); + + /* freeing the argument vector */ + freebytes(me->argv, sizeof(t_atom) * me->argc); + freebytes(me, sizeof(t_sfprocess)); + } + } +} + +static void sndfiler_start_thread(void) +{ + pthread_attr_t sf_attr; + struct sched_param sf_param; + int status; + + //initialize queue + sndfiler_queue.x_jobs = fifo_init(); + pthread_mutex_init (&sndfiler_queue.mutex,NULL); + pthread_cond_init (&sndfiler_queue.cond,NULL); + + // initialize thread + pthread_attr_init(&sf_attr); + + sf_param.sched_priority=sched_get_priority_min(SCHED_OTHER); + pthread_attr_setschedparam(&sf_attr,&sf_param); + +#ifdef UNIX + if (sys_hipriority == 1/* && getuid() == 0 */) + { + sf_param.sched_priority=sched_get_priority_min(SCHED_RR); + pthread_attr_setschedpolicy(&sf_attr,SCHED_RR); + } +#endif /* UNIX */ + + //start thread + status = pthread_create(&sf_thread_id, &sf_attr, + (void *) sndfiler_thread,NULL); + if (status != 0) + error("Couldn't create sndfiler thread: %d",status); + else + post("global sndfiler thread launched, priority: %d", + sf_param.sched_priority); +} + + +static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv); + + +/* syntax: + * read soundfile array0..n + * if the soundfile has less channels than arrays are given, these arrays are + * set to zero + * if there are too little arrays given, only the first n channels will be used + * */ + +static void sndfiler_read(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) +{ + t_sfprocess * process = getbytes(sizeof(t_sfprocess)); + + + process->process = &sndfiler_read_cb; + process->x = x; + process->argc = argc; + process->argv = (t_atom*) copybytes(argv, sizeof(t_atom) * argc); + + fifo_put(sndfiler_queue.x_jobs, process); + + pthread_cond_signal(&sndfiler_queue.cond); +} + +static t_int sndfiler_synchonize(t_int * w); + +static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) +{ + int resize = 0; + int frames = -1; + int i, j; + int counter=0; + int channel_count; + t_float** helper_arrays; + + t_symbol* file; + t_garray ** arrays; + + SNDFILE* sndfile; + SF_INFO info; + + if (argc < 2) + { + pd_error(x, "Invalid arguments"); + return; + } + + file = atom_getsymbolarg(0, argc, argv); + + channel_count = argc - 1; + helper_arrays = getbytes(channel_count * sizeof(t_float*)); + + arrays = getbytes(channel_count * sizeof(t_garray*)); + for (i = 0; i != channel_count; ++i) + { + t_garray * array = (t_garray *)pd_findbyclass(atom_getsymbolarg(i+1, argc, argv), garray_class); + + if (array) + arrays[i] = array; + else + { + pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, argc, argv)->s_name); + return; + } + } + + sndfile = sf_open(file->s_name, SFM_READ, &info); + + if (sndfile) + { + int minchannels = (channel_count < info.channels) ? + channel_count : info.channels; + + int maxchannels = (channel_count < info.channels) ? + channel_count : info.channels; + + t_float * item = alloca(maxchannels * sizeof(t_float)); + + t_int ** syncdata = getbytes(sizeof(t_int*) * 5); + +#if (_POSIX_MEMLOCK - 0) >= 200112L + munlockall(); +#endif + + for (i = 0; i != channel_count; ++i) + { + helper_arrays[i] = getalignedbytes(info.frames * sizeof(t_float)); + } + + + for (i = 0; i != info.frames; ++i) + { + sf_read_float(sndfile, item, 1); + + for (j = 0; j != channel_count; ++j) + { + if (j < minchannels) + helper_arrays[j][i] = item[j]; + else + helper_arrays[j][i] = 0; + } + } +#if (_POSIX_MEMLOCK - 0) >= 200112L + mlockall(MCL_FUTURE); +#endif + + sf_close(sndfile); + + syncdata[0] = (t_int*)arrays; + syncdata[1] = (t_int*)helper_arrays; + syncdata[2] = (t_int*)channel_count; + syncdata[3] = (t_int*)(long)info.frames; + syncdata[4] = (t_int*)x; + + sys_callback(sndfiler_synchonize, (t_int*)syncdata, 5); + } + else + { + pd_error(x, "Error opening file"); + } +} + + +static t_int sndfiler_synchonize(t_int * w) +{ + int i; + t_garray** arrays = (t_garray**) w[0]; + t_float** helper_arrays = (t_float**) w[1]; + t_int channel_count = (t_int)w[2]; + t_int frames = (t_int)w[3]; + t_sndfiler* x = (t_sndfiler*)w[4]; + + for (i = 0; i != channel_count; ++i) + { + t_garray * garray = arrays[i]; + t_array * array = garray->x_scalar->sc_vec[0].w_array; + t_glist * gl = garray->x_glist;; + + + freealignedbytes(array->a_vec, array->a_n); + array->a_vec = (char*)helper_arrays[i]; + array->a_n = frames; + + if (gl->gl_list == &garray->x_gobj && !garray->x_gobj.g_next) + { + vmess(&gl->gl_pd, gensym("bounds"), "ffff", + 0., gl->gl_y1, (double)(frames > 1 ? frames-1 : 1), gl->gl_y2); + /* close any dialogs that might have the wrong info now... */ + gfxstub_deleteforkey(gl); + } + else + garray_redraw(garray); + } + + free(arrays); + free(helper_arrays); + + canvas_update_dsp(); + + outlet_float(x->x_obj.ob_outlet, frames); + + return 0; +} + + +void sndfiler_setup(void) +{ + sndfiler_class = class_new(gensym("sndfiler"), (t_newmethod)sndfiler_new, + 0, sizeof(t_sndfiler), 0, 0); + class_addmethod(sndfiler_class, (t_method)sndfiler_read, + gensym("read"), A_GIMME, 0); + + sndfiler_start_thread(); +} + + -- cgit v1.2.1 From d79c9f0eeaac84d67504c9b439d9248919f3325f Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Fri, 7 Oct 2005 10:36:22 +0000 Subject: updated for added files svn path=/trunk/externals/tb/; revision=3675 --- chaos/package.txt | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/chaos/package.txt b/chaos/package.txt index cd87590..a32c803 100644 --- a/chaos/package.txt +++ b/chaos/package.txt @@ -1,6 +1,6 @@ NAME=chaos - SRCDIR=src +BUILDTYPE=multi #PRECOMPILE=chaos.hpp @@ -8,51 +8,83 @@ SRCS= \ main.cpp \ bernoulli_dsp.cpp \ bernoulli_msg.cpp \ +bernoulli_search.cpp \ bungalow_tent_dsp.cpp \ bungalow_tent_msg.cpp \ +bungalow_tent_search.cpp \ chaos_base.cpp \ chaos_dsp.cpp \ chua_dsp.cpp \ chua_msg.cpp \ +chua_search.cpp \ circle_map_dsp.cpp \ circle_map_msg.cpp \ +circle_map_search.cpp \ coupled_logistic_dsp.cpp \ coupled_logistic_msg.cpp \ +coupled_logistic_search.cpp \ +delayed_logistic_dsp.cpp \ +delayed_logistic_msg.cpp \ +delayed_logistic_search.cpp \ driven_anharmonic_dsp.cpp \ driven_anharmonic_msg.cpp \ +driven_anharmonic_search.cpp \ driven_van_der_pol_dsp.cpp \ driven_van_der_pol_msg.cpp \ +driven_van_der_pol_search.cpp \ duffing_map_dsp.cpp \ duffing_map_msg.cpp \ +duffing_map_search.cpp \ gauss_map_dsp.cpp \ gauss_map_msg.cpp \ +gauss_map_search.cpp \ +gaussian_map_dsp.cpp \ +gaussian_map_msg.cpp \ +gaussian_map_search.cpp \ henon_map_dsp.cpp \ henon_map_msg.cpp \ +henon_map_search.cpp \ +hydrogen_dsp.cpp \ +hydrogen_msg.cpp \ +hydrogen_search.cpp \ ikeda_laser_map_dsp.cpp \ ikeda_laser_map_msg.cpp \ +ikeda_laser_map_search.cpp \ latoocarfian_dsp.cpp \ latoocarfian_msg.cpp \ +latoocarfian_search.cpp \ latoomutalpha_dsp.cpp \ latoomutalpha_msg.cpp \ +latoomutalpha_search.cpp \ latoomutbeta_dsp.cpp \ latoomutbeta_msg.cpp \ +latoomutbeta_search.cpp \ latoomutgamma_dsp.cpp \ latoomutgamma_msg.cpp \ +latoomutgamma_search.cpp \ logistic_dsp.cpp \ logistic_msg.cpp \ +logistic_search.cpp \ lorenz_dsp.cpp \ lorenz_msg.cpp \ +lorenz_search.cpp \ lozi_map_dsp.cpp \ lozi_map_msg.cpp \ +lozi_map_search.cpp \ ode_base.cpp \ roessler_dsp.cpp \ roessler_msg.cpp \ +roessler_search.cpp \ sine_map_dsp.cpp \ sine_map_msg.cpp \ +sine_map_search.cpp \ standard_map_dsp.cpp \ standard_map_msg.cpp \ +standard_map_search.cpp \ tent_map_dsp.cpp \ tent_map_msg.cpp \ +tent_map_search.cpp \ + HDRS= \ bernoulli_map.hpp \ @@ -62,14 +94,18 @@ chaos_base.hpp \ chaos_defs.hpp \ chaos_dsp.hpp \ chaos_msg.hpp \ +chaos_search.hpp \ chua.hpp \ circle_map.hpp \ coupled_logistic.hpp \ +delayed_logistic.hpp \ driven_anharmonic.hpp \ driven_van_der_pol.hpp \ duffing_map.hpp \ gauss_map.hpp \ +gaussian_map.hpp \ henon_map.hpp \ +hydrogen.hpp \ ikeda_laser_map.hpp \ latoocarfian.hpp \ latoomutalpha.hpp \ -- cgit v1.2.1 From 94ab8a946255bda2bb28cb94c064e3b899774bc5 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 9 Oct 2005 09:55:24 +0000 Subject: more flext-like dsp callbacks svn path=/trunk/externals/tb/; revision=3686 --- chaos/src/chaos_dsp.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 16e2820..821b544 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -39,15 +39,16 @@ public: /* cubic interpolation */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); - virtual void m_signal(int n, t_sample *const *insigs,t_sample *const *outsigs) + virtual void CbSignal() { - (this->*m_routine)(n,insigs,outsigs); + (this->*m_routine)(Blocksize(),InSig(),OutSig()); } - virtual void m_dsp(int n, t_sample *const *insigs,t_sample *const *outsigs) + virtual bool CbDsp() { m_sr = Samplerate(); set_freq(m_freq); /* maybe we have to change the interpolation mode */ + return true; } void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); @@ -130,14 +131,14 @@ public: if (f < 0) /* we can't go back in time :-) */ f = -f; - if( f <= m_sr * 0.5 ) + if( f <= m_sr * 0.1 ) { if (m_freq >= m_sr * 0.5) set_imethod(m_imethod); m_freq = f; m_invfreq = 1.f / f; } - else if (f > m_sr * 0.5) + else if (f > m_sr * 0.1) { m_freq = f; m_invfreq = 1.f / f; -- cgit v1.2.1 From 95a84bbdd0149e0824310521066058c9f6f097a0 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 9 Oct 2005 10:21:36 +0000 Subject: cleaner behaviour for high frequency resampling svn path=/trunk/externals/tb/; revision=3687 --- chaos/src/chaos_dsp.hpp | 164 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 140 insertions(+), 24 deletions(-) diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 821b544..ddb8fe4 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -36,8 +36,12 @@ public: void m_signal_n_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); /* linear interpolation */ void m_signal_l(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* linear interpolation for high frequencies */ + void m_signal_l_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); /* cubic interpolation */ void m_signal_c(int n, t_sample *const *insigs,t_sample *const *outsigs); + /* cubic interpolation for high frequencies */ + void m_signal_c_hf(int n, t_sample *const *insigs,t_sample *const *outsigs); virtual void CbSignal() { @@ -66,8 +70,7 @@ public: /* local data for signal functions */ float m_freq; /* frequency of oscillations */ float m_invfreq; /* inverse frequency */ - int m_phase; /* phase counter */ - float m_fphase; /* phase for high frequency linear interpolation */ + float m_phase; /* phase */ float m_sr; /* sample rate */ int m_imethod; /* interpolation method */ @@ -118,7 +121,7 @@ public: m_nextmidpts[j] = m_values[j]; } } - + set_freq(m_freq); } void get_freq(float &f) @@ -133,20 +136,41 @@ public: if( f <= m_sr * 0.1 ) { - if (m_freq >= m_sr * 0.5) - set_imethod(m_imethod); - m_freq = f; - m_invfreq = 1.f / f; + switch(m_imethod) + { + case 0: + m_routine = &thisType::m_signal_n; + break; + case 1: + m_routine = &thisType::m_signal_l; + break; + case 2: + m_routine = &thisType::m_signal_c; + break; + default: + assert(false); + } } - else if (f > m_sr * 0.1) + else { - m_freq = f; - m_invfreq = 1.f / f; - - m_routine = &thisType::m_signal_n_hf; + switch(m_imethod) + { + case 0: + m_routine = &thisType::m_signal_n_hf; + break; + case 1: + m_routine = &thisType::m_signal_l_hf; + break; + case 2: + m_routine = &thisType::m_signal_c_hf; + break; + default: + assert(false); + } } - else - post("frequency out of range"); + + m_freq = f; + m_invfreq = 1.f / f; } FLEXT_CALLVAR_F(get_freq, set_freq); @@ -226,7 +250,7 @@ FLEXT_ATTRVAR_I(m_imethod); template void chaos_dsp::m_signal_(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); @@ -247,7 +271,7 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, { int outlets = m_system->get_num_eq(); - float phase = m_fphase; + float phase = m_phase; int offset = 0; while (n) @@ -267,17 +291,17 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, } offset += next; } - m_fphase = phase; + m_phase = phase; } template void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); - int phase = m_phase; + int phase = int(m_phase); int offset = 0; while (n) @@ -304,11 +328,11 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, /* linear and cubic interpolation adapted from supercollider by James McCartney */ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); - int phase = m_phase; + int phase = int(m_phase); int i = 0; @@ -341,13 +365,53 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, } + +template +void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + float phase = int(m_phase); + + int i = 0; + + while (n) + { + if (phase == 0) + { + m_system->m_perform(); + phase = int (m_sr * m_invfreq); + + for (int j = 0; j != outlets; ++j) + m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + } + + int next = (phase < n) ? int(ceilf (phase)) : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; +} + + template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, - t_sample *const *outsigs) + t_sample *const *outsigs) { int outlets = m_system->get_num_eq(); - int phase = m_phase; + int phase = int(m_phase); int i = 0; @@ -369,7 +433,7 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, float fseglen = (float)phase; m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - - fseglen * m_slopes[j]) + fseglen * m_slopes[j]) / (fseglen * fseglen + fseglen); } } @@ -391,3 +455,55 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, } m_phase = phase; } + + +template +void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, + t_sample *const *outsigs) +{ + int outlets = m_system->get_num_eq(); + + float phase = m_phase; + + int i = 0; + + while (n) + { + if (phase == 0) + { + m_system->m_perform(); + phase = int (m_sr * m_invfreq); + phase = (phase > 2) ? phase : 2; + + for (int j = 0; j != outlets; ++j) + { + t_sample value = m_nextvalues[j]; + m_nextvalues[j]= m_system->get_data(j); + + m_values[j] = m_nextmidpts[j]; + m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; + + float fseglen = (float)phase; + m_curves[j] = 2.f * (m_nextmidpts[j] - m_values[j] - + fseglen * m_slopes[j]) + / (fseglen * fseglen + fseglen); + } + } + + int next = (phase < n) ? int(ceilf (phase)) : n; + n -= next; + phase -=next; + + while (next--) + { + for (int j = 0; j != outlets; ++j) + { + outsigs[j][i] = m_values[j]; + m_slopes[j]+=m_curves[j]; + m_values[j]+=m_slopes[j]; + } + ++i; + } + } + m_phase = phase; +} -- cgit v1.2.1 From 8fb0d8ac8ed684a2084769cb0986effec439626f Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 9 Oct 2005 10:23:37 +0000 Subject: more tweaking svn path=/trunk/externals/tb/; revision=3688 --- chaos/src/chaos_dsp.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index ddb8fe4..78c4130 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -134,7 +134,7 @@ public: if (f < 0) /* we can't go back in time :-) */ f = -f; - if( f <= m_sr * 0.1 ) + if( f <= m_sr * 0.01 ) { switch(m_imethod) { -- cgit v1.2.1 From ef53e19b3d9019b1b1f3345390f55ae9229ce390 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 22 Oct 2005 15:11:45 +0000 Subject: cleanups and new system svn path=/trunk/externals/tb/; revision=3750 --- chaos/src/bernoulli_map.hpp | 7 +--- chaos/src/bungalow_tent_map.hpp | 7 +--- chaos/src/chaos.hpp | 1 + chaos/src/chaos_base.hpp | 24 +++++------- chaos/src/chaos_dsp.hpp | 10 ++--- chaos/src/chua.hpp | 10 +---- chaos/src/circle_map.hpp | 5 +-- chaos/src/coupled_logistic.hpp | 7 +--- chaos/src/delayed_logistic.hpp | 8 +--- chaos/src/driven_anharmonic.hpp | 9 +---- chaos/src/driven_van_der_pol.hpp | 10 +---- chaos/src/duffing_map.hpp | 7 +--- chaos/src/gauss_map.hpp | 7 +--- chaos/src/gaussian_map.hpp | 7 +--- chaos/src/henon_map.hpp | 7 +--- chaos/src/hydrogen.hpp | 8 +--- chaos/src/ikeda_laser_map.hpp | 8 +--- chaos/src/latoocarfian.hpp | 8 +--- chaos/src/latoomutalpha.hpp | 7 +--- chaos/src/latoomutbeta.hpp | 7 +--- chaos/src/latoomutgamma.hpp | 7 +--- chaos/src/linear_congruental.hpp | 68 +++++++++++++++++++++++++++++++++ chaos/src/linear_congruental_dsp.cpp | 23 +++++++++++ chaos/src/linear_congruental_msg.cpp | 23 +++++++++++ chaos/src/linear_congruental_search.cpp | 24 ++++++++++++ chaos/src/logistic_map.hpp | 8 +--- chaos/src/lorenz.hpp | 11 +----- chaos/src/lozi_map.hpp | 7 +--- chaos/src/main.cpp | 5 ++- chaos/src/map_base.hpp | 5 +++ chaos/src/ode_base.hpp | 41 ++++++++++---------- chaos/src/roessler.hpp | 10 +---- chaos/src/sine_map.hpp | 7 +--- chaos/src/standard_map.hpp | 7 +--- chaos/src/tent_map.hpp | 11 ++---- 35 files changed, 234 insertions(+), 187 deletions(-) create mode 100644 chaos/src/linear_congruental.hpp create mode 100644 chaos/src/linear_congruental_dsp.cpp create mode 100644 chaos/src/linear_congruental_msg.cpp create mode 100644 chaos/src/linear_congruental_search.cpp diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index 31db7f7..f084c67 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -29,13 +29,10 @@ class bernoulli: { public: - bernoulli() + bernoulli(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0.5,0); - - CHAOS_POSTCONSTRUCTOR; } ~bernoulli() diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 5da431d..4d4836b 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -36,14 +36,11 @@ class bungalow_tent: public map_base { public: - bungalow_tent() + bungalow_tent(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.6,0); CHAOS_PAR_INIT(r, 0.5); - - CHAOS_POSTCONSTRUCTOR; } ~bungalow_tent() diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 2e2eb8b..bb9971d 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -24,6 +24,7 @@ #define _USE_MATH_DEFINES /* tg says: define this before including cmath */ #include "flext.h" +#include "assert.h" #include "chaos_defs.hpp" #include diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 5e2a99f..5c87bed 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -27,14 +27,20 @@ class chaos_base { - public: + chaos_base(int n): + m_num_eq(n) + { + m_data = new data_t[n]; + } + + inline t_sample get_data(unsigned int i) { return (t_sample)m_data[i]; /* this is not save, but fast */ } - inline int get_num_eq() + inline int get_num_eq() const { return m_num_eq; } @@ -65,25 +71,15 @@ public: } }; - data_t m_data[MAXDIMENSION]; // state of the system + data_t * m_data; // state of the system protected: virtual void m_step() = 0; // iteration - int m_num_eq; // number of equations of the system + const int m_num_eq; // number of equations of the system flext::AtomList Parameter; // parameter flext::AtomList System; // system }; -#define CHAOS_PRECONSTRUCTOR \ - /* dummy */ - -#define CHAOS_POSTCONSTRUCTOR \ -m_num_eq = System.Count(); - -#define CHAOS_DESTRUCTOR \ - - - #define CHAOS_CALLBACKS \ public: \ void get_dimension(int &i) \ diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 78c4130..e86fc30 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -236,11 +236,11 @@ SYSTEM##_dsp(int argc, t_atom* argv ) \ ~SYSTEM##_dsp() \ { \ delete m_system; \ - delete m_values; \ - delete m_slopes; \ - delete m_nextvalues; \ - delete m_nextmidpts; \ - delete m_curves; \ + delete[] m_values; \ + delete[] m_slopes; \ + delete[] m_nextvalues; \ + delete[] m_nextmidpts; \ + delete[] m_curves; \ } \ \ FLEXT_ATTRVAR_F(m_freq); \ diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index 3d44708..997116c 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -34,10 +34,9 @@ class chua: public ode_base { public: - chua() + chua(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.05); @@ -49,15 +48,10 @@ public: CHAOS_PAR_INIT(b,30); CHAOS_PAR_INIT(alpha,30); CHAOS_PAR_INIT(beta,30); - - CHAOS_POSTCONSTRUCTOR; - - ode_base_alloc(); } ~chua() { - ode_base_free(); } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index b6442a8..0a52993 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -31,15 +31,12 @@ class circle_map: { public: circle_map() + : map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.4,0); CHAOS_PAR_INIT(omega, 0.1); CHAOS_PAR_INIT(r, 3); - - CHAOS_POSTCONSTRUCTOR; } ~circle_map() diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index d94ceee..2e4b160 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -29,17 +29,14 @@ class coupled_logistic: public map_base { public: - coupled_logistic() + coupled_logistic(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(e, 0.06); CHAOS_PAR_INIT(r, 3.7); CHAOS_SYS_INIT(x, 0.1,0); CHAOS_SYS_INIT(y, 0.2,1); - - CHAOS_POSTCONSTRUCTOR; } ~coupled_logistic() diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index c78785f..47360e7 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -29,16 +29,12 @@ class delayed_logistic: public map_base { public: - delayed_logistic() + delayed_logistic(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.5, 0); - CHAOS_PAR_INIT(alpha, 3.8); - CHAOS_POSTCONSTRUCTOR; - m_delayed = get_x(); /* the initial state of the delay */ } diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 16e053b..2d72071 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -32,10 +32,9 @@ class driven_anharmonic : public ode_base { public: - driven_anharmonic() + driven_anharmonic(): + ode_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -49,15 +48,11 @@ public: CHAOS_PAR_INIT(k1,0.01); CHAOS_PAR_INIT(k2,1); - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); m_t = 0; } ~driven_anharmonic() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 6156eb0..e538185 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -33,10 +33,9 @@ class driven_van_der_pol : public ode_base { public: - driven_van_der_pol() + driven_van_der_pol(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -47,15 +46,10 @@ public: CHAOS_PAR_INIT(a,5); CHAOS_PAR_INIT(Omega,2.466); CHAOS_PAR_INIT(k,5); - - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); } ~driven_van_der_pol() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index 5110873..f0e3001 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -29,16 +29,13 @@ class duffing_map: public map_base { public: - duffing_map() + duffing_map(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1, 0.5, 0); CHAOS_SYS_INIT(x2, 0.5, 1); CHAOS_PAR_INIT(a, 0.5); CHAOS_PAR_INIT(b, 0.5); - - CHAOS_POSTCONSTRUCTOR; } ~duffing_map() diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 1e023d2..641b93a 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -31,13 +31,10 @@ class gauss_map: public map_base { public: - gauss_map() + gauss_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0.5, 0); - - CHAOS_POSTCONSTRUCTOR; } ~gauss_map() diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index 5f5a4b1..9b2b8ca 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -29,16 +29,13 @@ class gaussian_map: public map_base { public: - gaussian_map() + gaussian_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.5, 0); CHAOS_PAR_INIT(b,7); CHAOS_PAR_INIT(c,0.5); - - CHAOS_POSTCONSTRUCTOR; } ~gaussian_map() diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 73aed66..bb1c6c7 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -29,17 +29,14 @@ class henon: public map_base { public: - henon() + henon(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); CHAOS_PAR_INIT(a,1.4); CHAOS_PAR_INIT(b,0.3); - - CHAOS_POSTCONSTRUCTOR; } ~henon() diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp index 886539c..6df6088 100644 --- a/chaos/src/hydrogen.hpp +++ b/chaos/src/hydrogen.hpp @@ -29,10 +29,9 @@ class hydrogen public: - hydrogen() + hydrogen(): + ode_base(4) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -43,14 +42,11 @@ public: CHAOS_PAR_INIT(etilde,-0.3); - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); reset = 0; } ~hydrogen() { - ode_base_free(); } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index ece0b9f..3c4d587 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -35,10 +35,9 @@ class ikeda_laser_map: public map_base { public: - ikeda_laser_map() + ikeda_laser_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(c1,0.4); CHAOS_PAR_INIT(c2,0.9); CHAOS_PAR_INIT(c3,9); @@ -46,13 +45,10 @@ public: CHAOS_SYS_INIT(x,0.5,0); CHAOS_SYS_INIT(y,0.5,1); - - CHAOS_POSTCONSTRUCTOR; } ~ikeda_laser_map() { - } virtual void m_step() diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 9bfba90..eec6116 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -31,10 +31,9 @@ class latoocarfian : public map_base { public: - latoocarfian() + latoocarfian(): + map_base(2) { - CHAOS_PRECONSTRUCTOR - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0,1); @@ -42,13 +41,10 @@ public: CHAOS_PAR_INIT(b,2.879879); CHAOS_PAR_INIT(c,0.765145); CHAOS_PAR_INIT(d,0.744728); - - CHAOS_POSTCONSTRUCTOR; } ~latoocarfian() { - } virtual void m_step() diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ff0cf9f..ac4f28d 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -30,18 +30,15 @@ class latoomutalpha : public map_base { public: - latoomutalpha() + latoomutalpha(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.2,1); CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); CHAOS_PAR_INIT(c,0.765145); - - CHAOS_POSTCONSTRUCTOR; } ~latoomutalpha() diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index a3562c8..3a048cd 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -30,17 +30,14 @@ class latoomutbeta : public map_base { public: - latoomutbeta() + latoomutbeta(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); - - CHAOS_POSTCONSTRUCTOR; } ~latoomutbeta() diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index daf3608..5e55225 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -30,17 +30,14 @@ class latoomutgamma : public map_base { public: - latoomutgamma() + latoomutgamma(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); - - CHAOS_POSTCONSTRUCTOR; } ~latoomutgamma() diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp new file mode 100644 index 0000000..bc3536a --- /dev/null +++ b/chaos/src/linear_congruental.hpp @@ -0,0 +1,68 @@ +// +// +// chaos~ +// Copyright (C) 2004 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "map_base.hpp" + +// tent map: x[n+1] = A*x[n] + B mod C +// +// taken from Julien C. Sprott, Chaos and Time-Series Analysis + +class linear_congruental: + public map_base +{ +public: + linear_congruental(): + map_base(1) + { + CHAOS_SYS_INIT(x, 0, 0); + + CHAOS_PAR_INIT(A, 1741); + CHAOS_PAR_INIT(B, 54773); + CHAOS_PAR_INIT(C, 259200); + } + + virtual void m_step() + { + data_t x = m_data[0]; + + m_data[0] = chaos_mod( CHAOS_PARAMETER(A) * x + CHAOS_PARAMETER(B), CHAOS_PARAMETER(C)); + } + + CHAOS_SYSVAR_FUNCS(x,0); + + CHAOS_SYSPAR_FUNCS(A); + CHAOS_SYSPAR_FUNCS(B); + CHAOS_SYSPAR_FUNCS(C); +}; + +#define LINEAR_CONGRUENTAL_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(A); \ +CHAOS_SYS_CALLBACKS(B); \ +CHAOS_SYS_CALLBACKS(C); \ +CHAOS_SYS_CALLBACKS(x); + +#define LINEAR_CONGRUENTAL_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(A); \ +CHAOS_SYS_ATTRIBUTE(B); \ +CHAOS_SYS_ATTRIBUTE(C); \ +CHAOS_SYS_ATTRIBUTE(x); + diff --git a/chaos/src/linear_congruental_dsp.cpp b/chaos/src/linear_congruental_dsp.cpp new file mode 100644 index 0000000..df36059 --- /dev/null +++ b/chaos/src/linear_congruental_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "linear_congruental.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(linear_congruental,LINEAR_CONGRUENTAL); diff --git a/chaos/src/linear_congruental_msg.cpp b/chaos/src/linear_congruental_msg.cpp new file mode 100644 index 0000000..5b15d99 --- /dev/null +++ b/chaos/src/linear_congruental_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "linear_congruental.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(linear_congruental,LINEAR_CONGRUENTAL); diff --git a/chaos/src/linear_congruental_search.cpp b/chaos/src/linear_congruental_search.cpp new file mode 100644 index 0000000..f3a09a2 --- /dev/null +++ b/chaos/src/linear_congruental_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "linear_congruental.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(linear_congruental, LINEAR_CONGRUENTAL); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index c01abcc..3e0ef24 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -28,19 +28,15 @@ class logistic: public map_base { public: - logistic() + logistic(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5,0); - - CHAOS_POSTCONSTRUCTOR; } ~logistic() { - delete m_data; } virtual void m_step() diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index e94f027..b27f954 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -29,10 +29,9 @@ class lorenz : public ode_base { public: - lorenz() + lorenz(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -43,16 +42,10 @@ public: CHAOS_PAR_INIT(sigma,16); CHAOS_PAR_INIT(b,4); CHAOS_PAR_INIT(r,40); - - CHAOS_POSTCONSTRUCTOR; - - ode_base_alloc(); } ~lorenz() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index b30a95b..dee6b0d 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -29,17 +29,14 @@ class lozi_map: public map_base { public: - lozi_map() + lozi_map(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); CHAOS_PAR_INIT(a,1.4); CHAOS_PAR_INIT(b,0.3); - - CHAOS_POSTCONSTRUCTOR; } ~lozi_map() diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 53bd62e..0126f32 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,8 @@ void chaos_library_setup() { - post("chaos~ version 0.01, compiled on "__DATE__" \n"); + post("chaos~ version 0.01, compiled on "__DATE__); + post("(C)2005 Tim Blechmann, www.mokabar.tk\n\n"); CHAOS_ADD(bernoulli); @@ -34,6 +35,7 @@ void chaos_library_setup() CHAOS_ADD(delayed_logistic); CHAOS_ADD(driven_anharmonic); CHAOS_ADD(driven_van_der_pol); + CHAOS_ADD(duffing); CHAOS_ADD(duffing_map); CHAOS_ADD(gauss_map); CHAOS_ADD(gaussian_map); @@ -44,6 +46,7 @@ void chaos_library_setup() CHAOS_ADD(latoomutalpha); CHAOS_ADD(latoomutbeta); CHAOS_ADD(latoomutgamma); + CHAOS_ADD(linear_congruental); CHAOS_ADD(logistic); CHAOS_ADD(lorenz); CHAOS_ADD(lozi_map); diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index e71fe61..1395bb8 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -27,6 +27,11 @@ class map_base : public chaos_base { protected: + map_base(int n): + chaos_base(n) + { + } + virtual void m_step() { } diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index b7139d2..11811f7 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -27,6 +27,26 @@ class ode_base : public chaos_base { public: + ode_base(int n): + chaos_base (n) + { + for (int i = 0; i != 3; ++i) + { + m_k[i] = new data_t[n]; + } + m_tmp = new data_t[n]; + + } + + ~ode_base() + { + for (int i = 0; i != 3; ++i) + { + delete[] m_k[i]; + } + delete[] m_tmp; + } + void set_method(int i) { if (i >=0 && i <4) @@ -65,27 +85,6 @@ public: (this->*m_routine)(); } - void ode_base_alloc() - { - int dimension = get_num_eq(); - - for (int i = 0; i != 3; ++i) - { - m_k[i] = new data_t[dimension]; - } - - m_tmp = new data_t[dimension]; - } - - void ode_base_free() - { - for (int i = 0; i != 3; ++i) - { - delete m_k[i]; - } - delete m_tmp; - } - protected: void (ode_base::*m_routine)(void); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index e2c55e0..fd65d4e 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -29,10 +29,9 @@ class roessler : public ode_base { public: - roessler() + roessler(): + ode_base(3) { - CHAOS_PRECONSTRUCTOR; - CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.001); @@ -43,15 +42,10 @@ public: CHAOS_PAR_INIT(a,4); CHAOS_PAR_INIT(b,4); CHAOS_PAR_INIT(c,4); - - CHAOS_POSTCONSTRUCTOR; - ode_base_alloc(); } ~roessler() { - ode_base_free(); - } virtual void m_system(data_t* deriv, data_t* data) diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 21c7e39..3d69065 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -30,13 +30,10 @@ class sine_map: { public: - sine_map() + sine_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x,0,0); - - CHAOS_POSTCONSTRUCTOR; } ~sine_map() diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 663280a..4df1eb9 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -30,16 +30,13 @@ class standard_map: public map_base { public: - standard_map() + standard_map(): + map_base(2) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(I,0.1,0); CHAOS_SYS_INIT(theta,0.2,1); CHAOS_PAR_INIT(k, 0.8); - - CHAOS_POSTCONSTRUCTOR; } ~standard_map() diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index e23fb73..9bd8e62 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -29,15 +29,12 @@ class tent_map: public map_base { public: - tent_map() + tent_map(): + map_base(1) { - CHAOS_PRECONSTRUCTOR; - CHAOS_SYS_INIT(x, 0.6,0); - - CHAOS_POSTCONSTRUCTOR; } - + ~tent_map() { @@ -49,7 +46,7 @@ public: m_data[0] = 1 - 2*CHAOS_ABS(data); } - + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); bool m_pred_x(t_float f) { -- cgit v1.2.1 From 9290c9a11f4aea63431c62b3f21b9d59d015bff9 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 23 Oct 2005 22:04:51 +0000 Subject: multichannel fix svn path=/trunk/externals/tb/; revision=3761 --- sndfiler/sndfiler.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sndfiler/sndfiler.c b/sndfiler/sndfiler.c index 29c692a..c9e0fb4 100644 --- a/sndfiler/sndfiler.c +++ b/sndfiler/sndfiler.c @@ -221,6 +221,7 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) t_float * item = alloca(maxchannels * sizeof(t_float)); + t_int ** syncdata = getbytes(sizeof(t_int*) * 5); #if (_POSIX_MEMLOCK - 0) >= 200112L @@ -235,14 +236,14 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) for (i = 0; i != info.frames; ++i) { - sf_read_float(sndfile, item, 1); + sf_read_float(sndfile, item, info.channels); - for (j = 0; j != channel_count; ++j) + for (j = 0; j != info.channels; ++j) { - if (j < minchannels) + if (j < channel_count) + { helper_arrays[j][i] = item[j]; - else - helper_arrays[j][i] = 0; + } } } #if (_POSIX_MEMLOCK - 0) >= 200112L -- cgit v1.2.1 From d981b7feb7183a325d44f22ece4c963366658cef Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 1 Nov 2005 21:24:31 +0000 Subject: updated build system svn path=/trunk/externals/tb/; revision=3810 --- chaos/SConstruct | 196 ++++++++++++++++++++++++++++++++++++++++++------------ chaos/package.txt | 6 ++ 2 files changed, 159 insertions(+), 43 deletions(-) diff --git a/chaos/SConstruct b/chaos/SConstruct index 3dcf513..499e76a 100644 --- a/chaos/SConstruct +++ b/chaos/SConstruct @@ -1,43 +1,153 @@ -systems = Split("""bernoulli - bungalow_tent - circle_map - coupled_logistic - chua - delayed_logistic - driven_anharmonic - driven_van_der_pol - duffing_map - gauss_map - gaussian_map - henon_map - hydrogen - ikeda_laser_map - latoocarfian - latoomutalpha - latoomutbeta - latoomutgamma - logistic - lorenz - lozi_map - roessler - sine_map - standard_map - tent_map""") - -sources = [] - -env = Environment(CCFLAGS = '-O3 -g -mtune=pentium-m -march=pentium-m -mmmx -msse -msse2 -mfpmath=sse -I~/pd/devel/pd/src/ -I/usr/local/include/flext -DFLEXT_SYS_PD -DFLEXT_THREADS -DFLEXT_SHARED') - -for system in systems: - sources.append(system+"_dsp.cpp") - sources.append(system+"_msg.cpp") - sources.append(system+"_search.cpp") -sources += Split("main.cpp ode_base.cpp") - -sources = map(lambda x: "./src/"+x, sources) - -chaos = env.SharedLibrary('chaos', sources, LIBS = 'flext-pd_d', - SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') - -env.Install('/usr/local/lib/pd/extra',chaos) -env.Alias('install', '/usr/local/lib/pd/extra') +# scons script for flext build system +# Copyright (C) 2005 Tim Blechmann +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import sys + +env = Environment(CCFLAGS = '-DFLEXT_SYS_PD -DFLEXT_THREADS') + +env.SConsignFile() +env.CacheDir('./obj') + +opt = Options(['options.cache']) +opt.AddOptions( + BoolOption('debug', 'Build with debugging symbols', False), + ('optimize', 'Optimize for specific architecture', None), + ('icc', 'Build with intel c compiler', False), + BoolOption('simd', 'build with simd instructions', False), + ('prefix', 'install prefix', '/usr/local'), + ('flext_path', 'flext path', None), + ('pd_path', 'pd path', None), + ) + +opt.Update(env) + +opt.Save('options.cache',env) +Help(opt.GenerateHelpText(env)) + + +if env.Dictionary().has_key('icc') and env['icc']: + env.Replace(CC="icc", + SHCC="icc", + CXX="icc", + LINK="icc", + SHCXX="icc", + SHLINK="icc", + ) + env.Append(LINKFLAGS="-static-libcxa") + + env.Append(CCFLAGS=' -ip') + env.Append(LINKFLAGS='-ip') + print "Using intel c compiler" + + +if env.Dictionary().has_key('flext_path'): + env.Append(CPPPATH=[env['flext_path']]) +else: + env.Append(CPPPATH=['../../grill/flext/source']) + + +if env.Dictionary().has_key('pd_path'): + env.Append(CPPPATH=[env['pd_path']]) + +if env.Dictionary().has_key('optimize'): + if env['optimize']: + env.Append(CCFLAGS=' -O3 '+env['optimize']) + env.Append(LINKFLAGS=' -O3 '+env['optimize']) + +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + +if env.Dictionary().has_key('debug') and env['debug']: + env.Append(CCFLAGS=' -g ') + env.Append(CPPDEFINES=['_DEBUG']) + env.Append(LIBS = 'flext-pd') + env.Append(LINKFLAGS=' -g') +else: + env.Append(CPPDEFINES=['FLEXT_SHARED']) + env.Append(LIBS = 'flext-pd') + env.Append(CPPDEFINES="NDEBUG") + +###################################################################### +# +# read package.txt +# + +packagefile = open('./package.txt', 'r') + +desc = {} +line = packagefile.readline() +while line != "": + line = line.strip() + if len(line) > 0 and line[0] != '#' : + var, data = line.split('=') + + if len(data) == 0: + line = packagefile.readline() + continue + + while data [-1] == '\\': + nextline = packagefile.readline() + nextline = nextline.strip() + data = data + " " + nextline + + data = data.replace("\\", "") + desc[var] = data + + + line = packagefile.readline() +packagefile.close() + + +name = desc["NAME"] +if not desc.has_key("SRCDIR"): + desc["SRCDIR"] = "." + +sources = map (lambda x: desc["SRCDIR"] + '/' + x, + desc["SRCS"].split()) + +if desc.has_key("INCPATH"): + env.Append(CPPPATH=desc["INCPATH"].strip().replace("-I", "").split()) + + + +###################################################################### +# +# run custom.py +# +try: + sys.path.append("./build/") + import custom + try: + env, sources, headers = custom.custom(env,desc,sources) + except: + env, sources = custom.custom(env,desc,sources) +except: + pass + + + +###################################################################### +# +# build +# + +external = env.SharedLibrary(name, sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') + +prefix = env['prefix'] +env.Install(prefix+'/lib/pd/extra',external) +env.Alias('install', prefix+'/lib/pd/extra') diff --git a/chaos/package.txt b/chaos/package.txt index a32c803..c132783 100644 --- a/chaos/package.txt +++ b/chaos/package.txt @@ -32,6 +32,9 @@ driven_anharmonic_search.cpp \ driven_van_der_pol_dsp.cpp \ driven_van_der_pol_msg.cpp \ driven_van_der_pol_search.cpp \ +duffing_dsp.cpp \ +duffing_msg.cpp \ +duffing_search.cpp \ duffing_map_dsp.cpp \ duffing_map_msg.cpp \ duffing_map_search.cpp \ @@ -62,6 +65,9 @@ latoomutbeta_search.cpp \ latoomutgamma_dsp.cpp \ latoomutgamma_msg.cpp \ latoomutgamma_search.cpp \ +linear_congruental_dsp.cpp \ +linear_congruental_msg.cpp \ +linear_congruental_search.cpp \ logistic_dsp.cpp \ logistic_msg.cpp \ logistic_search.cpp \ -- cgit v1.2.1 From f29a18911ce09a638646d90d1f72838313419380 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 1 Nov 2005 21:28:21 +0000 Subject: added new system svn path=/trunk/externals/tb/; revision=3811 --- chaos/src/chaos_msg.hpp | 12 +++--- chaos/src/duffing.hpp | 98 ++++++++++++++++++++++++++++++++++++++++++++ chaos/src/duffing_dsp.cpp | 23 +++++++++++ chaos/src/duffing_msg.cpp | 23 +++++++++++ chaos/src/duffing_search.cpp | 24 +++++++++++ chaos/src/main.cpp | 2 +- 6 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 chaos/src/duffing.hpp create mode 100644 chaos/src/duffing_dsp.cpp create mode 100644 chaos/src/duffing_msg.cpp create mode 100644 chaos/src/duffing_search.cpp diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 3f80101..357ff6a 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -25,6 +25,11 @@ template class chaos_msg { FLEXT_HEADER(chaos_msg, flext_base); + ~chaos_msg() + { + delete m_system; + } + public: /* local data for system, output and interpolation */ @@ -59,10 +64,5 @@ SYSTEM##_msg(int argc, t_atom* argv ) \ AddOutFloat(); \ \ ATTRIBUTES; \ - FLEXT_ADDBANG(0, m_bang); \ -} \ - \ -~SYSTEM##_msg() \ -{ \ - delete m_system; \ + FLEXT_ADDBANG(0, m_bang); \ } diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp new file mode 100644 index 0000000..6cdafd6 --- /dev/null +++ b/chaos/src/duffing.hpp @@ -0,0 +1,98 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "ode_base.hpp" + +// duffing equation: dx/dt = y +// dy/dt = x * (1 - x^2) + R*cos(omega * t) - gamma * y +// + + +class duffing: + public ode_base +{ +public: + duffing(): + ode_base(2) + { + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + + CHAOS_SYS_INIT(x, 0.5, 0); + CHAOS_SYS_INIT(y, 0.5, 1); + + CHAOS_PAR_INIT(R, 0.4); + CHAOS_PAR_INIT(omega, 1); + CHAOS_PAR_INIT(gamma, 0.25); + + t = 0; + } + + ~duffing() + { + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x = data[0], y = data[1]; + + deriv[0] = y; + deriv[1] = x * (1 - x*x) + + CHAOS_PARAMETER(R) * cos( CHAOS_PARAMETER(omega) * t) - + CHAOS_PARAMETER(gamma) * y; + t += CHAOS_PARAMETER(dt); + t = chaos_mod(t, M_PI); + } + + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + + + CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSVAR_FUNCS(y,1); + + CHAOS_SYSPAR_FUNCS(R); + CHAOS_SYSPAR_FUNCS(omega); + CHAOS_SYSPAR_FUNCS(gamma); + +private: + data_t t; +}; + +#define DUFFING_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); \ +CHAOS_SYS_CALLBACKS(R); \ +CHAOS_SYS_CALLBACKS(gamma); \ +CHAOS_SYS_CALLBACKS(omega); + +#define DUFFING_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); \ +CHAOS_SYS_ATTRIBUTE(R); \ +CHAOS_SYS_ATTRIBUTE(gamma); \ +CHAOS_SYS_ATTRIBUTE(omega); + diff --git a/chaos/src/duffing_dsp.cpp b/chaos/src/duffing_dsp.cpp new file mode 100644 index 0000000..c2c89c1 --- /dev/null +++ b/chaos/src/duffing_dsp.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing.hpp" +#include "chaos_dsp.hpp" +CHAOS_DSP_CLASS(duffing,DUFFING); diff --git a/chaos/src/duffing_msg.cpp b/chaos/src/duffing_msg.cpp new file mode 100644 index 0000000..08f4109 --- /dev/null +++ b/chaos/src/duffing_msg.cpp @@ -0,0 +1,23 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing.hpp" +#include "chaos_msg.hpp" +CHAOS_MSG_CLASS(duffing,DUFFING); diff --git a/chaos/src/duffing_search.cpp b/chaos/src/duffing_search.cpp new file mode 100644 index 0000000..13d5cdd --- /dev/null +++ b/chaos/src/duffing_search.cpp @@ -0,0 +1,24 @@ +// +// +// chaos~ +// Copyright (C) 2005 Tim Blechmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; see the file COPYING. If not, write to +// the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + +#include "duffing.hpp" +#include "chaos_search.hpp" + +CHAOS_SEARCH_CLASS(duffing, DUFFING); diff --git a/chaos/src/main.cpp b/chaos/src/main.cpp index 0126f32..354f68a 100644 --- a/chaos/src/main.cpp +++ b/chaos/src/main.cpp @@ -23,7 +23,7 @@ void chaos_library_setup() { - post("chaos~ version 0.01, compiled on "__DATE__); + post("\nchaos~ version 0.01, compiled on "__DATE__); post("(C)2005 Tim Blechmann, www.mokabar.tk\n\n"); -- cgit v1.2.1 From 449a8062d986c8f59c2ffeef9241b52a159651aa Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Tue, 1 Nov 2005 21:56:23 +0000 Subject: small build fix svn path=/trunk/externals/tb/; revision=3812 --- chaos/SConstruct | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chaos/SConstruct b/chaos/SConstruct index 499e76a..2c682b8 100644 --- a/chaos/SConstruct +++ b/chaos/SConstruct @@ -64,14 +64,14 @@ else: if env.Dictionary().has_key('pd_path'): env.Append(CPPPATH=[env['pd_path']]) +if env.Dictionary().has_key('simd') and env['simd']: + env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') + if env.Dictionary().has_key('optimize'): if env['optimize']: env.Append(CCFLAGS=' -O3 '+env['optimize']) env.Append(LINKFLAGS=' -O3 '+env['optimize']) -if env.Dictionary().has_key('simd') and env['simd']: - env.Append(CCFLAGS=' -mfpmath=sse -msse -mmmx -msse2') - if env.Dictionary().has_key('debug') and env['debug']: env.Append(CCFLAGS=' -g ') env.Append(CPPDEFINES=['_DEBUG']) -- cgit v1.2.1 From 40be3959a23e385aea503ad862565f057e61035d Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Sun, 20 Nov 2005 21:51:26 +0000 Subject: new directory structure svn path=/trunk/externals/tb/; revision=3990 --- sndfiler/makefile | 94 -------------- sndfiler/sndfiler-help.pd | 10 -- sndfiler/sndfiler.c | 322 ---------------------------------------------- 3 files changed, 426 deletions(-) delete mode 100644 sndfiler/makefile delete mode 100644 sndfiler/sndfiler-help.pd delete mode 100644 sndfiler/sndfiler.c diff --git a/sndfiler/makefile b/sndfiler/makefile deleted file mode 100644 index f44a8da..0000000 --- a/sndfiler/makefile +++ /dev/null @@ -1,94 +0,0 @@ -NAME=sndfiler -CSYM=sndfiler - -current: pd_linux - -# ----------------------- NT ----------------------- - -pd_nt: $(NAME).dll - -.SUFFIXES: .dll - -PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo -VC="C:\Program Files\Microsoft Visual Studio\Vc98" - -PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include - -PDNTLDIR = $(VC)\lib -PDNTLIB = $(PDNTLDIR)\libc.lib \ - $(PDNTLDIR)\oldnames.lib \ - $(PDNTLDIR)\kernel32.lib \ - ..\..\bin\pd.lib - -.c.dll: - cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c - link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) - -# ----------------------- IRIX 5.x ----------------------- - -pd_irix5: $(NAME).pd_irix5 - -.SUFFIXES: .pd_irix5 - -SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 - -SGIINCLUDE = -I../../src - -.c.pd_irix5: - $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c - ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o - rm $*.o - -# ----------------------- IRIX 6.x ----------------------- - -pd_irix6: $(NAME).pd_irix6 - -.SUFFIXES: .pd_irix6 - -SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ - -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ - -Ofast=ip32 - -.c.pd_irix6: - $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c - ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o - rm $*.o - -# ----------------------- LINUX i386 ----------------------- - -pd_linux: $(NAME).pd_linux - -.SUFFIXES: .pd_linux - -LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ - -Wall -W -Wshadow -Wstrict-prototypes -Werror \ - -Wno-unused -Wno-parentheses -Wno-switch - -LINUXINCLUDE = -I/home/tim/pd/devel_0_39/src - -LSTRIP = strip --strip-unneeded -R .note -R .comment - -.c.pd_linux: - cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm -lsndfile -# $(LSTRIP) $*.pd_linux - rm -f $*.o - -# ----------------------- Mac OSX ----------------------- - -pd_darwin: $(NAME).pd_darwin - -.SUFFIXES: .pd_darwin - -DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ - -Wno-unused -Wno-parentheses -Wno-switch - -.c.pd_darwin: - $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o - rm -f $*.o - -# ---------------------------------------------------------- - -clean: - rm -f *.o *.pd_* so_locations diff --git a/sndfiler/sndfiler-help.pd b/sndfiler/sndfiler-help.pd deleted file mode 100644 index fe9de17..0000000 --- a/sndfiler/sndfiler-help.pd +++ /dev/null @@ -1,10 +0,0 @@ -#N canvas 0 0 450 300 10; -#X obj 36 103 sndfiler; -#X obj 294 87 table array; -#X msg 37 60 read \$1 array; -#X obj 38 33 openpanel; -#X obj 124 15 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --1; -#X connect 2 0 0 0; -#X connect 3 0 2 0; -#X connect 4 0 3 0; diff --git a/sndfiler/sndfiler.c b/sndfiler/sndfiler.c deleted file mode 100644 index c9e0fb4..0000000 --- a/sndfiler/sndfiler.c +++ /dev/null @@ -1,322 +0,0 @@ -/* - * - * soundfiler based on libsndfile - * Copyright (C) 2005 Tim Blechmann - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - - -#include "stdlib.h" -#include "m_pd.h" -#include "g_canvas.h" -#include "m_fifo.h" -#include "pthread.h" /* for helper thread */ -#include "sched.h" /* for thread priority */ -#include "alloca.h" - -#include "sndfile.h" - -#if (_POSIX_MEMLOCK - 0) >= 200112L -#include -#endif /* _POSIX_MEMLOCK */ - -static t_class *sndfiler_class; - - -typedef struct _sndfiler -{ - t_object x_obj; - t_canvas *x_canvas; -} t_sndfiler; - -typedef struct _sfprocess -{ - void* padding; - void (* process) (t_sndfiler *, - int, t_atom *); /* callback function */ - t_sndfiler * x; /* soundfiler */ - int argc; - t_atom * argv; -} t_sfprocess; - - -/* this is the queue for all soundfiler objects */ -typedef struct _sfqueue -{ - t_fifo* x_jobs; - - pthread_mutex_t mutex; - pthread_cond_t cond; -} t_sfqueue; - - -typedef struct _syncdata -{ - t_garray** arrays; - t_float** helper_arrays; - int argc; - t_int frames; -} t_syncdata; - - -static t_sfqueue sndfiler_queue; -static pthread_t sf_thread_id; /* id of soundfiler thread */ - - -static t_sndfiler *sndfiler_new(void) -{ - t_sndfiler *x = (t_sndfiler *)pd_new(sndfiler_class); - x->x_canvas = canvas_getcurrent(); - outlet_new(&x->x_obj, &s_float); - return (x); -} - - -/* global soundfiler thread ... sleeping until signaled */ -static void sndfiler_thread(void) -{ - while (1) - { - t_sfprocess * me; - pthread_cond_wait(&sndfiler_queue.cond, &sndfiler_queue.mutex); - - while (me = (t_sfprocess *)fifo_get(sndfiler_queue.x_jobs)) - { - (me->process)(me->x, me->argc, me->argv); - - /* freeing the argument vector */ - freebytes(me->argv, sizeof(t_atom) * me->argc); - freebytes(me, sizeof(t_sfprocess)); - } - } -} - -static void sndfiler_start_thread(void) -{ - pthread_attr_t sf_attr; - struct sched_param sf_param; - int status; - - //initialize queue - sndfiler_queue.x_jobs = fifo_init(); - pthread_mutex_init (&sndfiler_queue.mutex,NULL); - pthread_cond_init (&sndfiler_queue.cond,NULL); - - // initialize thread - pthread_attr_init(&sf_attr); - - sf_param.sched_priority=sched_get_priority_min(SCHED_OTHER); - pthread_attr_setschedparam(&sf_attr,&sf_param); - -#ifdef UNIX - if (sys_hipriority == 1/* && getuid() == 0 */) - { - sf_param.sched_priority=sched_get_priority_min(SCHED_RR); - pthread_attr_setschedpolicy(&sf_attr,SCHED_RR); - } -#endif /* UNIX */ - - //start thread - status = pthread_create(&sf_thread_id, &sf_attr, - (void *) sndfiler_thread,NULL); - if (status != 0) - error("Couldn't create sndfiler thread: %d",status); - else - post("global sndfiler thread launched, priority: %d", - sf_param.sched_priority); -} - - -static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv); - - -/* syntax: - * read soundfile array0..n - * if the soundfile has less channels than arrays are given, these arrays are - * set to zero - * if there are too little arrays given, only the first n channels will be used - * */ - -static void sndfiler_read(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) -{ - t_sfprocess * process = getbytes(sizeof(t_sfprocess)); - - - process->process = &sndfiler_read_cb; - process->x = x; - process->argc = argc; - process->argv = (t_atom*) copybytes(argv, sizeof(t_atom) * argc); - - fifo_put(sndfiler_queue.x_jobs, process); - - pthread_cond_signal(&sndfiler_queue.cond); -} - -static t_int sndfiler_synchonize(t_int * w); - -static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) -{ - int resize = 0; - int frames = -1; - int i, j; - int counter=0; - int channel_count; - t_float** helper_arrays; - - t_symbol* file; - t_garray ** arrays; - - SNDFILE* sndfile; - SF_INFO info; - - if (argc < 2) - { - pd_error(x, "Invalid arguments"); - return; - } - - file = atom_getsymbolarg(0, argc, argv); - - channel_count = argc - 1; - helper_arrays = getbytes(channel_count * sizeof(t_float*)); - - arrays = getbytes(channel_count * sizeof(t_garray*)); - for (i = 0; i != channel_count; ++i) - { - t_garray * array = (t_garray *)pd_findbyclass(atom_getsymbolarg(i+1, argc, argv), garray_class); - - if (array) - arrays[i] = array; - else - { - pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, argc, argv)->s_name); - return; - } - } - - sndfile = sf_open(file->s_name, SFM_READ, &info); - - if (sndfile) - { - int minchannels = (channel_count < info.channels) ? - channel_count : info.channels; - - int maxchannels = (channel_count < info.channels) ? - channel_count : info.channels; - - t_float * item = alloca(maxchannels * sizeof(t_float)); - - - t_int ** syncdata = getbytes(sizeof(t_int*) * 5); - -#if (_POSIX_MEMLOCK - 0) >= 200112L - munlockall(); -#endif - - for (i = 0; i != channel_count; ++i) - { - helper_arrays[i] = getalignedbytes(info.frames * sizeof(t_float)); - } - - - for (i = 0; i != info.frames; ++i) - { - sf_read_float(sndfile, item, info.channels); - - for (j = 0; j != info.channels; ++j) - { - if (j < channel_count) - { - helper_arrays[j][i] = item[j]; - } - } - } -#if (_POSIX_MEMLOCK - 0) >= 200112L - mlockall(MCL_FUTURE); -#endif - - sf_close(sndfile); - - syncdata[0] = (t_int*)arrays; - syncdata[1] = (t_int*)helper_arrays; - syncdata[2] = (t_int*)channel_count; - syncdata[3] = (t_int*)(long)info.frames; - syncdata[4] = (t_int*)x; - - sys_callback(sndfiler_synchonize, (t_int*)syncdata, 5); - } - else - { - pd_error(x, "Error opening file"); - } -} - - -static t_int sndfiler_synchonize(t_int * w) -{ - int i; - t_garray** arrays = (t_garray**) w[0]; - t_float** helper_arrays = (t_float**) w[1]; - t_int channel_count = (t_int)w[2]; - t_int frames = (t_int)w[3]; - t_sndfiler* x = (t_sndfiler*)w[4]; - - for (i = 0; i != channel_count; ++i) - { - t_garray * garray = arrays[i]; - t_array * array = garray->x_scalar->sc_vec[0].w_array; - t_glist * gl = garray->x_glist;; - - - freealignedbytes(array->a_vec, array->a_n); - array->a_vec = (char*)helper_arrays[i]; - array->a_n = frames; - - if (gl->gl_list == &garray->x_gobj && !garray->x_gobj.g_next) - { - vmess(&gl->gl_pd, gensym("bounds"), "ffff", - 0., gl->gl_y1, (double)(frames > 1 ? frames-1 : 1), gl->gl_y2); - /* close any dialogs that might have the wrong info now... */ - gfxstub_deleteforkey(gl); - } - else - garray_redraw(garray); - } - - free(arrays); - free(helper_arrays); - - canvas_update_dsp(); - - outlet_float(x->x_obj.ob_outlet, frames); - - return 0; -} - - -void sndfiler_setup(void) -{ - sndfiler_class = class_new(gensym("sndfiler"), (t_newmethod)sndfiler_new, - 0, sizeof(t_sndfiler), 0, 0); - class_addmethod(sndfiler_class, (t_method)sndfiler_read, - gensym("read"), A_GIMME, 0); - - sndfiler_start_thread(); -} - - -- cgit v1.2.1 From 7a3b2297e6f784e608d2013c910657334ee3019e Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Sun, 20 Nov 2005 21:54:41 +0000 Subject: also works with pd_main now - additional threaded resize method svn path=/trunk/externals/tb/; revision=3991 --- sndfiler/GnuGPL.txt | 290 ++++++++++++++++++++++++ sndfiler/INSTALL | 55 +++++ sndfiler/README | 24 ++ sndfiler/doc/sndfiler-help.pd | 48 ++++ sndfiler/src/Makefile | 95 ++++++++ sndfiler/src/Makefile.pd_main | 116 ++++++++++ sndfiler/src/sndfiler.c | 504 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1132 insertions(+) create mode 100755 sndfiler/GnuGPL.txt create mode 100755 sndfiler/INSTALL create mode 100755 sndfiler/README create mode 100755 sndfiler/doc/sndfiler-help.pd create mode 100755 sndfiler/src/Makefile create mode 100755 sndfiler/src/Makefile.pd_main create mode 100755 sndfiler/src/sndfiler.c diff --git a/sndfiler/GnuGPL.txt b/sndfiler/GnuGPL.txt new file mode 100755 index 0000000..fa0bef4 --- /dev/null +++ b/sndfiler/GnuGPL.txt @@ -0,0 +1,290 @@ +GNU GENERAL PUBLIC LICENSE + +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom +to share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This General +Public License applies to most of the Free Software Foundation's +software and to any other program whose authors commit to using it. +(Some other Free Software Foundation software is covered by the +GNU Library General Public License instead.) You can apply it to your +programs, too. + +When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new free +programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone +to deny you these rights or to ask you to surrender the rights. These +restrictions translate to certain responsibilities for you if you distribute +copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis +or for a fee, you must give the recipients all the rights that you have. You +must make sure that they, too, receive or can get the source code. And +you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, +we want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + +Finally, any free program is threatened constantly by software patents. +We wish to avoid the danger that redistributors of a free program will +individually obtain patent licenses, in effect making the program +proprietary. To prevent this, we have made it clear that any patent must +be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and +modification follow. + +TERMS AND CONDITIONS FOR +COPYING, DISTRIBUTION AND +MODIFICATION + +0. This License applies to any program or other work which contains a +notice placed by the copyright holder saying it may be distributed under +the terms of this General Public License. The "Program", below, refers +to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, either +verbatim or with modifications and/or translated into another language. +(Hereinafter, translation is included without limitation in the term +"modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of running +the Program is not restricted, and the output from the Program is +covered only if its contents constitute a work based on the Program +(independent of having been made by running the Program). Whether +that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the notices +that refer to this License and to the absence of any warranty; and give +any other recipients of the Program a copy of this License along with the +Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide a + warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but does + not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, and +can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based on +the Program, the distribution of the whole must be on the terms of this +License, whose permissions for other licensees extend to the entire +whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your +rights to work written entirely by you; rather, the intent is to exercise the +right to control the distribution of derivative or collective works based +on the Program. + +In addition, mere aggregation of another work not based on the +Program with the Program (or with a work based on the Program) on a +volume of a storage or distribution medium does not bring the other +work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding + machine-readable source code, which must be distributed under + the terms of Sections 1 and 2 above on a medium customarily + used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your cost + of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a + medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with + such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to control +compilation and installation of the executable. However, as a special +exception, the source code distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies the +executable. + +If distribution of executable or object code is made by offering access to +copy from a designated place, then offering equivalent access to copy +the source code from the same place counts as distribution of the source +code, even though third parties are not compelled to copy the source +along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt otherwise +to copy, modify, sublicense or distribute the Program is void, and will +automatically terminate your rights under this License. However, parties +who have received copies, or rights, from you under this License will not +have their licenses terminated so long as such parties remain in full +compliance. + +5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and all +its terms and conditions for copying, distributing or modifying the +Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these terms +and conditions. You may not impose any further restrictions on the +recipients' exercise of the rights granted herein. You are not responsible +for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot distribute +so as to satisfy simultaneously your obligations under this License and +any other pertinent obligations, then as a consequence you may not +distribute the Program at all. For example, if a patent license would not +permit royalty-free redistribution of the Program by all those who +receive copies directly or indirectly through you, then the only way you +could satisfy both it and this License would be to refrain entirely from +distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents +or other property right claims or to contest validity of any such claims; +this section has the sole purpose of protecting the integrity of the free +software distribution system, which is implemented by public license +practices. Many people have made generous contributions to the wide +range of software distributed through that system in reliance on +consistent application of that system; it is up to the author/donor to +decide if he or she is willing to distribute software through any other +system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be +a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain +countries either by patents or by copyrighted interfaces, the original +copyright holder who places the Program under this License may add an +explicit geographical distribution limitation excluding those countries, so +that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new +versions of the General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may differ in +detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number +of this License, you may choose any version ever published by the Free +Software Foundation. + +10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we +sometimes make exceptions for this. Our decision will be guided by the +two goals of preserving the free status of all derivatives of our free +software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF +CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, +TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT +WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE +PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD +THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE +COST OF ALL NECESSARY SERVICING, REPAIR OR +CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW +OR AGREED TO IN WRITING WILL ANY COPYRIGHT +HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED +ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING +ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR +INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT +LIMITED TO LOSS OF DATA OR DATA BEING RENDERED +INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR +OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY +OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS diff --git a/sndfiler/INSTALL b/sndfiler/INSTALL new file mode 100755 index 0000000..8aa5e6a --- /dev/null +++ b/sndfiler/INSTALL @@ -0,0 +1,55 @@ + +[sndfiler] installation instructions: + +------------------------------------------------------- + MAIN PD +------------------------------------------------------- + +- INSTALLATION: + +1) first install threadlib, get it from + http://grh.mur.at/software/threadlib.html + +2) download binaries for your platform at + http://grh.mur.at/software/sndfiler.html + +3) WIN: copy sndfiler.dll to path\to\pd\extra + copy libsndfile.dll to windows\system + + LINUX: copy sndfiler.pd_linux to path/to/pd/extra + install libsndfile (via apt-get or something + similar) + + MAC: copy sndfiler.pd_darwin to path/to/pd/extra + install libsndfile + +4) copy helpfile to path/to/pd/doc/5.reference + +- COMPILATION: + +1) install libsndfile on your platform + +2) adapt the pathes in src/Makefile.pd_main to fit into + your system + +3) make -f Makefile.pd_main pd_linux/pd_darwin/pd_win + (windows: you will need MinGW !) + +4) make -f Makefile.pd_main install + +------------------------------------------------------- + PD DEVEL +------------------------------------------------------- + +- COMPILATION: + +1) install libsndfile on your platform + +2) adapt src/Makefile to fit into your system + +3) make pd_linux/pd_darwin/pd_nt + +------------------------------------------------------- + +in case of problems: +grh@mur.at diff --git a/sndfiler/README b/sndfiler/README new file mode 100755 index 0000000..15995b3 --- /dev/null +++ b/sndfiler/README @@ -0,0 +1,24 @@ + +[sndfiler] + +a threaded soundfiler for PD using libsndfile + + +REQUIREMENTS: + - pd >= 0.39 + - libsndfile + - for main PD you will also need threadlib: + http://grh.mur.at/software/threadlib.html + +FEATURES: + - threaded reading of multichannel soundfiles into arrays + - threaded resize of arrays + + +For more information look at the help patch ! + +See the file INSTALL for installation instructions. + + +(C) 2005, Tim Blechmann , + Georg Holzmann diff --git a/sndfiler/doc/sndfiler-help.pd b/sndfiler/doc/sndfiler-help.pd new file mode 100755 index 0000000..c05142e --- /dev/null +++ b/sndfiler/doc/sndfiler-help.pd @@ -0,0 +1,48 @@ +#N canvas 225 0 465 689 10; +#X obj 29 23 cnv 15 404 54 empty empty empty 22 25 0 18 -1 -66577 0 +; +#X obj 31 25 cnv 15 400 50 empty empty sndfiler 22 25 0 18 -228992 +-66577 0; +#X obj 72 637 print THREADED_SF; +#X obj 72 592 r \$0-tsf; +#X obj 68 394 openpanel; +#X obj 68 438 s \$0-tsf; +#X obj 68 374 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X obj 258 615 table array1; +#X text 89 373 <- read; +#X obj 256 536 s \$0-tsf; +#X msg 256 510 resize array1 4410; +#X text 39 276 read a file: read filename array1 array2 ...; +#X text 40 292 NOTE: this will also resize the array to the filesize +!; +#X text 66 340 for mono files:; +#X msg 68 416 read \$1 array1; +#X obj 239 396 openpanel; +#X obj 239 440 s \$0-tsf; +#X obj 239 376 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X text 260 375 <- read; +#X text 235 340 for multichannel specify; +#X text 237 353 more arrays:; +#X msg 239 418 read \$1 array1 array2; +#X obj 258 637 table array2; +#X obj 72 615 sndfiler; +#X text 288 34 threaded soundfiler; +#X text 308 51 using libsndfile; +#X text 161 113 ::: SNDFILER :::; +#X text 65 152 A threaded soundfiler for PD using libsndfile.; +#X text 65 182 REQUIREMENTS:; +#X text 118 199 - pd >= 0.39; +#X text 118 215 - libsndfile; +#X text 118 231 - threadlib (for main pd); +#X text 65 509 threaded resize of arrays:; +#X connect 3 0 23 0; +#X connect 4 0 14 0; +#X connect 6 0 4 0; +#X connect 10 0 9 0; +#X connect 14 0 5 0; +#X connect 15 0 21 0; +#X connect 17 0 15 0; +#X connect 21 0 16 0; +#X connect 23 0 2 0; diff --git a/sndfiler/src/Makefile b/sndfiler/src/Makefile new file mode 100755 index 0000000..2b17d1c --- /dev/null +++ b/sndfiler/src/Makefile @@ -0,0 +1,95 @@ + +NAME=sndfiler +CSYM=sndfiler + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I/home/tim/pd/devel_0_39/src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm -lsndfile +# $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_darwin *.pd_linux *.dll so_locations diff --git a/sndfiler/src/Makefile.pd_main b/sndfiler/src/Makefile.pd_main new file mode 100755 index 0000000..1b4c5ca --- /dev/null +++ b/sndfiler/src/Makefile.pd_main @@ -0,0 +1,116 @@ +# ---------------------------------------------------------- + +# adjust the next pathes to your system: + +# this should point to the directory which contains +# m_pd.h and g_canvas.h +PD_SCR = /home/holzi/pd-0.39-1/src +#PD_SCR = c:/pd/src + +# this is the pd directory, usually /usr/lib/pd +# or c:/pd etc. +PD_PATH = /usr/lib/pd +#PD_PATH = c:/pd + +# path of sndfile.h from libsndfile, usually it's in +# /usr/include and so detected automatically +SNDFILE_SRC = /usr/include + +# the directory, where libsndfile is located +# (in linux it' normally not necessary, in windows it's +# normally in c:/windwos/system or so) +SNDFILE_PATH = c:/windows/system + +# path to threadlib.h +THREADLIB_SRC = /home/Georg/pd-cvs/externals/grh/threadlib/src +#THREADLIB_SRC = c:/Georg/pd-cvs/externals/grh/threadlib/src + +# path to threadlib.pd_linux/dll/pd_darwin +# (usually path/to/pd/extra) +THREADLIB_PATH = $(PD_PATH)/extra + +# ---------------------------------------------------------- + +NAME=sndfiler + +CC = gcc +LD = gcc +INCLUDE= -I. -I$(PD_SCR) -I$(SNDFILE_SRC) -I$(THREADLIB_SRC) +CC_FLAGS = -DPD -DUSE_PD_MAIN -O3 -funroll-loops \ + -Wall -W -Wshadow -Wno-parentheses -Wno-switch \ + -Wno-unused -fomit-frame-pointer +LD_FLAGS = --export-dynamic -shared -o + +current: + @echo ---------------------------- + @echo USAGE: + @echo linux: make pd_linux + @echo windows: make pd_win + @echo darwin: make pd_darwin + @echo ---------------------------- + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +CC_UNIX = -DUNIX -fPIC -pthread +LIB_UNIX = -lc -lm -lsndfile $(THREADLIB_PATH)/threadlib.pd_linux + +.c.pd_linux: + $(CC) $(CC_UNIX) $(CC_FLAGS) $(INCLUDE) -o $*.o -c $*.c + $(LD) $(LD_FLAGS) $*.pd_linux $*.o $(LIB_UNIX) + strip --strip-unneeded $*.pd_linux + chmod 755 $*.pd_linux + @test -d ../bin || mkdir -p ../bin + cp $*.pd_linux ../bin + rm -f $*.o + +# ------------------------ WIN MinGW ----------------------- + +pd_win: $(NAME).dll + +.SUFFIXES: .dll + +CC_WIN = -DMSW -mms-bitfields +LIB_WIN = $(PD_PATH)/bin/pd.dll \ + $(SNDFILE_PATH)/pthreadGC.dll \ + $(SNDFILE_PATH)/libsndfile.dll \ + $(THREADLIB_PATH)/threadlib.dll + +.c.dll: + $(CC) $(CC_WIN) $(CC_FLAGS) $(INCLUDE) -o $*.o -c $*.c + $(LD) $(LD_FLAGS) $*.dll $*.o $(LIB_WIN) + strip --strip-unneeded $*.dll + chmod 755 $*.dll + @test -d ../bin || mkdir -p ../bin + cp $*.dll ../bin + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +CC_DARWIN = -pthread +LD_DARWIN = -bundle -undefined suppress -flat_namespace \ + -bundle_loader $(PD_PATH)/bin/pd --export-dynamic + +.c.pd_darwin: + $(CC) $(CC_FLAGS) $(CC_DARWIN) $(INCLUDE) -o $*.o -c $*.c + $(LD) $(LD_DARWIN) $*.pd_linux $*.o $(LIB) + chmod 755 $*.pd_darwin + @test -d ../bin || mkdir -p ../bin + cp $*.pd_darwin ../bin + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_darwin *.pd_linux *.dll + +install: + install ../bin/$(NAME).* $(PD_PATH)/extra + install ../doc/*.pd $(PD_PATH)/doc/5.reference diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c new file mode 100755 index 0000000..c1579ee --- /dev/null +++ b/sndfiler/src/sndfiler.c @@ -0,0 +1,504 @@ +/* + * + * threaded soundfiler based on libsndfile + * Copyright (C) 2005, Tim Blechmann + * (C) 2005, Georg Holzmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* to be compatible with main pd */ +#ifdef USE_PD_MAIN + +#define getalignedbytes(a) getbytes(a) +#define freealignedbytes(a,b) freebytes(a,b) +#include "threadlib.h" + +/* forward declaration */ +struct _garray +{ + t_gobj x_gobj; + t_scalar *x_scalar; /* scalar "containing" the array */ + t_glist *x_glist; /* containing glist */ + t_symbol *x_name; /* unexpanded name (possibly with leading '$') */ + t_symbol *x_realname; /* expanded name (symbol we're bound to) */ + char x_usedindsp; /* true if some DSP routine is using this */ + char x_saveit; /* true if we should save this with parent */ + char x_listviewing; /* true if list view window is open */ +}; + +#else /* now for pd_devel */ + +#include "m_pd.h" +#include "m_fifo.h" +#include "pthread.h" + +#endif /* USE_PD_MAIN */ + + +#include "g_canvas.h" +#include "sndfile.h" + +#include "stdlib.h" +#include "sched.h" /* for thread priority */ +#include + +/* for alloca */ +#ifdef MSW +#include +#else +#include "alloca.h" +#endif + +#if (_POSIX_MEMLOCK - 0) >= 200112L +#include +#endif /* _POSIX_MEMLOCK */ + + +/************ forward declarations **************/ + +#ifdef UNIX +/* real-time flag, true if priority boosted */ +extern int sys_hipriority; +#endif + +/* get a garray's "array" structure. */ +t_array *h_garray_getarray(t_garray *x) +{ + int zonset, ztype; + t_symbol *zarraytype; + t_scalar *sc = x->x_scalar; + t_symbol *templatesym = sc->sc_template; + t_template *_template = template_findbyname(templatesym); + if (!_template) + { + error("array: couldn't find template %s", templatesym->s_name); + return (0); + } + if (!template_find_field(_template, gensym("z"), + &zonset, &ztype, &zarraytype)) + { + error("array: template %s has no 'z' field", templatesym->s_name); + return (0); + } + if (ztype != DT_ARRAY) + { + error("array: template %s, 'z' field is not an array", + templatesym->s_name); + return (0); + } + return (sc->sc_vec[zonset].w_array); +} + + +/************ sndfiler **************/ + +static t_class *sndfiler_class; + +typedef struct _sndfiler +{ + t_object x_obj; + t_canvas *x_canvas; +} t_sndfiler; + +typedef struct _sfprocess +{ + void* padding; + /* callback function */ + void (* process) (t_sndfiler *, int, t_atom *); + t_sndfiler * x; /* soundfiler */ + int argc; + t_atom * argv; +} t_sfprocess; + +/* this is the queue for all soundfiler objects */ +typedef struct _sfqueue +{ + t_fifo* x_jobs; + + pthread_mutex_t mutex; + pthread_cond_t cond; +} t_sfqueue; + +typedef struct _syncdata +{ + t_garray** arrays; + t_float** helper_arrays; + int argc; + t_int frames; +} t_syncdata; + +static t_sfqueue sndfiler_queue; +static pthread_t sf_thread_id; /* id of soundfiler thread */ + +static t_sndfiler *sndfiler_new(void) +{ + t_sndfiler *x = (t_sndfiler *)pd_new(sndfiler_class); + x->x_canvas = canvas_getcurrent(); + outlet_new(&x->x_obj, &s_float); + return (x); +} + +/* global soundfiler thread ... sleeping until signaled */ +static void sndfiler_thread(void) +{ + while (1) + { + t_sfprocess * me; + pthread_cond_wait(&sndfiler_queue.cond, &sndfiler_queue.mutex); + + while (me = (t_sfprocess *)fifo_get(sndfiler_queue.x_jobs)) + { + (me->process)(me->x, me->argc, me->argv); + + /* freeing the argument vector */ + freebytes(me->argv, sizeof(t_atom) * me->argc); + freebytes(me, sizeof(t_sfprocess)); + } + } +} + +static void sndfiler_start_thread(void) +{ + pthread_attr_t sf_attr; + struct sched_param sf_param; + int status; + + //initialize queue + sndfiler_queue.x_jobs = fifo_init(); + pthread_mutex_init (&sndfiler_queue.mutex,NULL); + pthread_cond_init (&sndfiler_queue.cond,NULL); + + // initialize thread + pthread_attr_init(&sf_attr); + + sf_param.sched_priority=sched_get_priority_min(SCHED_OTHER); + pthread_attr_setschedparam(&sf_attr,&sf_param); + +#ifdef UNIX + if (sys_hipriority == 1/* && getuid() == 0 */) + { + sf_param.sched_priority=sched_get_priority_min(SCHED_RR); + pthread_attr_setschedpolicy(&sf_attr,SCHED_RR); + } +#endif /* UNIX */ + + //start thread + status = pthread_create(&sf_thread_id, &sf_attr, + (void *) sndfiler_thread,NULL); + + if (status != 0) + error("Couldn't create sndfiler thread: %d",status); + else + post("Global sndfiler thread launched, priority: %d", + sf_param.sched_priority); +} + +static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv); + +/* syntax: + * read soundfile array0..n + * if the soundfile has less channels than arrays are given, these arrays are + * set to zero + * if there are too little arrays given, only the first n channels will be used + * */ +static void sndfiler_read(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) +{ + t_sfprocess * process = getbytes(sizeof(t_sfprocess)); + + process->process = &sndfiler_read_cb; + process->x = x; + process->argc = argc; + process->argv = (t_atom*) copybytes(argv, sizeof(t_atom) * argc); + + fifo_put(sndfiler_queue.x_jobs, process); + + pthread_cond_signal(&sndfiler_queue.cond); +} + +static t_int sndfiler_synchonize(t_int * w); + +static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) +{ + int i, j; + int channel_count; + t_float** helper_arrays; + + t_symbol* file; + t_garray ** arrays; + + SNDFILE* sndfile; + SF_INFO info; + + if (argc < 2) + { + pd_error(x, "usage: read soundfile array1 array2 ..."); + return; + } + + file = atom_getsymbolarg(0, argc, argv); + + channel_count = argc - 1; + helper_arrays = getbytes(channel_count * sizeof(t_float*)); + + arrays = getbytes(channel_count * sizeof(t_garray*)); + for (i = 0; i != channel_count; ++i) + { + t_garray * array = (t_garray *)pd_findbyclass(atom_getsymbolarg(i+1, + argc, argv), garray_class); + + if (array) + arrays[i] = array; + else + { + pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, argc, argv)->s_name); + return; + } + } + + post("sndfiler: loading file ..."); + + sndfile = sf_open(file->s_name, SFM_READ, &info); + + if (sndfile) + { + int maxchannels = (channel_count < info.channels) ? + channel_count : info.channels; + + t_float * item = alloca(maxchannels * sizeof(t_float)); + + t_int ** syncdata = getbytes(sizeof(t_int*) * 5); + +#if (_POSIX_MEMLOCK - 0) >= 200112L + munlockall(); +#endif + + for (i = 0; i != channel_count; ++i) + { + helper_arrays[i] = getalignedbytes(info.frames * sizeof(t_float)); + } + + for (i = 0; i != info.frames; ++i) + { + sf_read_float(sndfile, item, info.channels); + + for (j = 0; j != info.channels; ++j) + { + if (j < channel_count) + { + helper_arrays[j][i] = item[j]; + } + } + } + +#if (_POSIX_MEMLOCK - 0) >= 200112L + mlockall(MCL_FUTURE); +#endif + + sf_close(sndfile); + + syncdata[0] = (t_int*)arrays; + syncdata[1] = (t_int*)helper_arrays; + syncdata[2] = (t_int*)channel_count; + syncdata[3] = (t_int*)(long)info.frames; + syncdata[4] = (t_int*)x; + + sys_callback(sndfiler_synchonize, (t_int*)syncdata, 5); + } + else + pd_error(x, "Error opening file"); +} + +static t_int sndfiler_synchonize(t_int * w) +{ + int i; + t_garray** arrays = (t_garray**) w[0]; + t_float** helper_arrays = (t_float**) w[1]; + t_int channel_count = (t_int)w[2]; + t_int frames = (t_int)w[3]; + t_sndfiler* x = (t_sndfiler*)w[4]; + + for (i = 0; i != channel_count; ++i) + { + t_garray * garray = arrays[i]; + t_array * array = h_garray_getarray(garray); + t_glist * gl = garray->x_glist;; + + freealignedbytes(array->a_vec, array->a_n); + array->a_vec = (char*)helper_arrays[i]; + array->a_n = frames; + + if (gl->gl_list == &garray->x_gobj && !garray->x_gobj.g_next) + { + vmess(&gl->gl_pd, gensym("bounds"), "ffff", 0., gl->gl_y1, + (double)(frames > 1 ? frames-1 : 1), gl->gl_y2); + + /* close any dialogs that might have the wrong info now... */ + gfxstub_deleteforkey(gl); + } + else + garray_redraw(garray); + } + + free(arrays); + free(helper_arrays); + + canvas_update_dsp(); + + outlet_float(x->x_obj.ob_outlet, frames); + + return 0; +} + +static void sndfiler_t_resize(t_sndfiler * y, int argc, t_atom* argv); + +/* syntax: + * resize table size + * */ +static void sndfiler_resize(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) +{ + t_sfprocess * process = getbytes(sizeof(t_sfprocess)); + + process->process = &sndfiler_t_resize; + process->x = x; + process->argc = argc; + process->argv = (t_atom*) copybytes(argv, sizeof(t_atom) * argc); + + fifo_put(sndfiler_queue.x_jobs, process); + + pthread_cond_signal(&sndfiler_queue.cond); +} + +static void sndfiler_t_resize(t_sndfiler *y, int argc, t_atom *argv) +{ + int was, elemsize; /* array contains was elements of size elemsize */ + t_float * vec; /* old array */ + t_glist *gl; + int n; /* resize of n elements */ + char *nvec; /* new array */ + + t_garray * x = (t_garray *)pd_findbyclass(argv[0].a_w.w_symbol, garray_class); + t_array *data = h_garray_getarray(x); + + if (!(x)) + { + pd_error(y, "%s: no such table", argv[0].a_w.w_symbol->s_name); + goto usage; + } + + vec = (t_float*) data->a_vec; + was = data->a_n; + + if ((argv+1)->a_type == A_FLOAT) + n = (int) (argv+1)->a_w.w_float; + else + goto usage; + + if (n == was) return; + + if (n < 1) n = 1; + elemsize = template_findbyname(data->a_templatesym)->t_n * sizeof(t_word); + +#if (_POSIX_MEMLOCK - 0) >= 200112L + munlockall(); +#endif + + if (was > n) + nvec = (char*)copybytes(data->a_vec, was * elemsize); + else + { + nvec = getbytes(n * elemsize); + memcpy (nvec, data->a_vec, was * elemsize); + + /* LATER should check t_resizebytes result */ + memset(nvec + was*elemsize, 0, (n - was) * elemsize); + } + + if (!nvec) + { + pd_error(x, "array resize failed: out of memory"); + +#if (_POSIX_MEMLOCK - 0) >= 200112L + mlockall(MCL_FUTURE); +#endif + + return; + } + + /* TB: we'll have to be sure that no one is accessing the array */ + sys_lock(); + +#ifdef GARRAY_THREAD_LOCK + garray_lock(x); +#endif + + data->a_vec = nvec; + data->a_n = n; + +#ifdef GARRAY_THREAD_LOCK + garray_unlock(x); +#endif + + if (x->x_usedindsp) canvas_update_dsp(); + sys_unlock(); + + /* if this is the only array in the graph, + reset the graph's coordinates */ + gl = x->x_glist; + if (gl->gl_list == &x->x_gobj && !x->x_gobj.g_next) + { + vmess(&gl->gl_pd, gensym("bounds"), "ffff", + 0., gl->gl_y1, (double)(n > 1 ? n-1 : 1), gl->gl_y2); + /* close any dialogs that might have the wrong info now... */ + gfxstub_deleteforkey(gl); + } + else garray_redraw(x); + + freebytes (vec, was * elemsize); + +#if (_POSIX_MEMLOCK - 0) >= 200112L + mlockall(MCL_FUTURE); +#endif + + sys_lock(); + outlet_float(y->x_obj.ob_outlet, (float)atom_getintarg(1,argc,argv)); + sys_unlock(); + + return; + + usage: + pd_error(x, "usage: resize tablename size"); +} + +void sndfiler_setup(void) +{ + sndfiler_class = class_new(gensym("sndfiler"), + (t_newmethod)sndfiler_new, 0, + sizeof(t_sndfiler), 0, 0); + + class_addmethod(sndfiler_class, (t_method)sndfiler_read, + gensym("read"), A_GIMME, 0); + class_addmethod(sndfiler_class, (t_method)sndfiler_resize, + gensym("resize"), A_GIMME, 0); + +#ifdef USE_PD_MAIN + // needed to start thread callback system + threadlib_setup(); +#endif + + // starts helper thread + sndfiler_start_thread(); +} -- cgit v1.2.1 From dfebc6aa91cc76e8e4ee7b28f159c61dc03d9c60 Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Mon, 21 Nov 2005 09:29:14 +0000 Subject: osx makefile fix svn path=/trunk/externals/tb/; revision=3996 --- sndfiler/src/Makefile.pd_main | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sndfiler/src/Makefile.pd_main b/sndfiler/src/Makefile.pd_main index 1b4c5ca..195d396 100755 --- a/sndfiler/src/Makefile.pd_main +++ b/sndfiler/src/Makefile.pd_main @@ -96,11 +96,13 @@ pd_darwin: $(NAME).pd_darwin CC_DARWIN = -pthread LD_DARWIN = -bundle -undefined suppress -flat_namespace \ - -bundle_loader $(PD_PATH)/bin/pd --export-dynamic + -bundle_loader $(PD_PATH)/bin/pd --export-dynamic \ + -L/sw/lib -L/opt/local/lib -lsndfile \ + $(THREADLIB_PATH)/threadlib.pd_darwin .c.pd_darwin: $(CC) $(CC_FLAGS) $(CC_DARWIN) $(INCLUDE) -o $*.o -c $*.c - $(LD) $(LD_DARWIN) $*.pd_linux $*.o $(LIB) + $(LD) $(LD_DARWIN) -o $*.pd_linux $*.o $(LIB) chmod 755 $*.pd_darwin @test -d ../bin || mkdir -p ../bin cp $*.pd_darwin ../bin -- cgit v1.2.1 From 04f24a3a63d8e1f49f966b586b42134269553c66 Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Mon, 21 Nov 2005 17:04:05 +0000 Subject: now the osx version should work :) svn path=/trunk/externals/tb/; revision=4008 --- sndfiler/src/Makefile.pd_main | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sndfiler/src/Makefile.pd_main b/sndfiler/src/Makefile.pd_main index 195d396..b56b4b3 100755 --- a/sndfiler/src/Makefile.pd_main +++ b/sndfiler/src/Makefile.pd_main @@ -102,7 +102,7 @@ LD_DARWIN = -bundle -undefined suppress -flat_namespace \ .c.pd_darwin: $(CC) $(CC_FLAGS) $(CC_DARWIN) $(INCLUDE) -o $*.o -c $*.c - $(LD) $(LD_DARWIN) -o $*.pd_linux $*.o $(LIB) + $(LD) $(LD_DARWIN) -o $*.pd_darwin $*.o $(LIB) chmod 755 $*.pd_darwin @test -d ../bin || mkdir -p ../bin cp $*.pd_darwin ../bin -- cgit v1.2.1 From bc96a98d953afbee541b5e5b5bbcfc99f86842bb Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Mon, 28 Nov 2005 22:27:20 +0000 Subject: new flags: -resize and -skip svn path=/trunk/externals/tb/; revision=4073 --- sndfiler/doc/sndfiler-help.pd | 71 +++++++++++++----------- sndfiler/src/sndfiler.c | 124 +++++++++++++++++++++++++++++++++++------- 2 files changed, 142 insertions(+), 53 deletions(-) diff --git a/sndfiler/doc/sndfiler-help.pd b/sndfiler/doc/sndfiler-help.pd index c05142e..fb402f7 100755 --- a/sndfiler/doc/sndfiler-help.pd +++ b/sndfiler/doc/sndfiler-help.pd @@ -1,48 +1,53 @@ -#N canvas 225 0 465 689 10; +#N canvas 135 0 465 772 10; #X obj 29 23 cnv 15 404 54 empty empty empty 22 25 0 18 -1 -66577 0 ; #X obj 31 25 cnv 15 400 50 empty empty sndfiler 22 25 0 18 -228992 -66577 0; -#X obj 72 637 print THREADED_SF; -#X obj 72 592 r \$0-tsf; -#X obj 68 394 openpanel; -#X obj 68 438 s \$0-tsf; -#X obj 68 374 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +#X obj 55 667 print THREADED_SF; +#X obj 55 622 r \$0-tsf; +#X obj 48 440 openpanel; +#X obj 48 484 s \$0-tsf; +#X obj 48 420 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X obj 258 615 table array1; -#X text 89 373 <- read; -#X obj 256 536 s \$0-tsf; -#X msg 256 510 resize array1 4410; -#X text 39 276 read a file: read filename array1 array2 ...; -#X text 40 292 NOTE: this will also resize the array to the filesize -!; -#X text 66 340 for mono files:; -#X msg 68 416 read \$1 array1; -#X obj 239 396 openpanel; -#X obj 239 440 s \$0-tsf; -#X obj 239 376 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +#X obj 241 645 table array1; +#X text 69 419 <- read; +#X obj 239 566 s \$0-tsf; +#X msg 239 540 resize array1 4410; +#X text 46 386 for mono files:; +#X obj 239 442 openpanel; +#X obj 239 486 s \$0-tsf; +#X obj 239 422 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X text 260 375 <- read; -#X text 235 340 for multichannel specify; -#X text 237 353 more arrays:; -#X msg 239 418 read \$1 array1 array2; -#X obj 258 637 table array2; -#X obj 72 615 sndfiler; +#X text 260 421 <- read; +#X text 235 386 for multichannel specify; +#X text 237 399 more arrays:; +#X msg 239 464 read \$1 array1 array2; +#X obj 241 667 table array2; +#X obj 55 645 sndfiler; #X text 288 34 threaded soundfiler; #X text 308 51 using libsndfile; #X text 161 113 ::: SNDFILER :::; -#X text 65 152 A threaded soundfiler for PD using libsndfile.; +#X text 63 152 A threaded soundfiler for PD using libsndfile.; #X text 65 182 REQUIREMENTS:; #X text 118 199 - pd >= 0.39; #X text 118 215 - libsndfile; #X text 118 231 - threadlib (for main pd); -#X text 65 509 threaded resize of arrays:; -#X connect 3 0 23 0; -#X connect 4 0 14 0; +#X text 48 539 threaded resize of arrays:; +#X text 33 267 read a file: read [flags] filename array1 array2 ... +; +#X msg 48 462 read -resize \$1 array1; +#X text 32 287 FLAGS:; +#X text 32 305 -resize: resize the array(s) to the size of the soundfile +; +#X text 33 324 -skip : skip nr. of samples in soundfile \, +if negative \, it will be counted from the end of the file !; +#X text 82 722 (c) 2005 \, Tim Blechmann \, Georg Holzmann; +#X connect 3 0 20 0; +#X connect 4 0 31 0; #X connect 6 0 4 0; #X connect 10 0 9 0; -#X connect 14 0 5 0; -#X connect 15 0 21 0; -#X connect 17 0 15 0; -#X connect 21 0 16 0; -#X connect 23 0 2 0; +#X connect 12 0 18 0; +#X connect 14 0 12 0; +#X connect 18 0 13 0; +#X connect 20 0 2 0; +#X connect 31 0 5 0; diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index c1579ee..80df1c9 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -236,18 +236,37 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) int i, j; int channel_count; t_float** helper_arrays; + int resize = 0; + int seek = 0, arraysize = 0, writesize; t_symbol* file; t_garray ** arrays; SNDFILE* sndfile; SF_INFO info; - - if (argc < 2) + + // parse flags + while (argc > 0 && argv->a_type == A_SYMBOL && + *argv->a_w.w_symbol->s_name == '-') { - pd_error(x, "usage: read soundfile array1 array2 ..."); - return; + char *flag = argv->a_w.w_symbol->s_name + 1; + if (!strcmp(flag, "resize")) + { + resize = 1; + argc -= 1; argv += 1; + } + else if (!strcmp(flag, "skip")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((seek = argv[1].a_w.w_float) == 0)) + goto usage; + argc -= 2; argv += 2; + } + else goto usage; } + + if (argc < 2) + goto usage; file = atom_getsymbolarg(0, argc, argv); @@ -257,41 +276,83 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) arrays = getbytes(channel_count * sizeof(t_garray*)); for (i = 0; i != channel_count; ++i) { - t_garray * array = (t_garray *)pd_findbyclass(atom_getsymbolarg(i+1, - argc, argv), garray_class); - - if (array) - arrays[i] = array; - else - { - pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, argc, argv)->s_name); - return; - } + t_float *dummy; + int size; + t_garray *array; + + if(!(array = (t_garray *)pd_findbyclass( + atom_getsymbolarg(i+1, argc, argv), garray_class))) + { + pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, + argc, argv)->s_name); + return; + } + + if(garray_getfloatarray(array, &size, &dummy)) + arrays[i] = array; + else + { + pd_error(x, "%s: bad template for sndfiler", atom_getsymbolarg(i+1, + argc, argv)->s_name); + return; + } + + // in multichannel mode: check if arrays have different length + if (arraysize && arraysize != size && !resize) + { + post("sndfiler: arrays have different lengths, resizing to last one ..."); + } + arraysize = size; } - post("sndfiler: loading file ..."); - sndfile = sf_open(file->s_name, SFM_READ, &info); if (sndfile) { + int pos = 0; int maxchannels = (channel_count < info.channels) ? channel_count : info.channels; t_float * item = alloca(maxchannels * sizeof(t_float)); t_int ** syncdata = getbytes(sizeof(t_int*) * 5); - + + // negative seek: offset from the end of the file + if(seek<0) + { + pos = sf_seek(sndfile, seek, SEEK_END); + } + if(seek>0) + { + pos = sf_seek(sndfile, seek, SEEK_SET); + } + if(pos == -1) + { + pd_error(x, "invalid seek in soundfile"); + return; + } + + if(resize) + { + writesize = (info.frames-pos); + arraysize = writesize; + } + else + writesize = (arraysize>(info.frames-pos)) ? + info.frames-pos : arraysize; + + post("sndfiler: loading file ..."); + #if (_POSIX_MEMLOCK - 0) >= 200112L munlockall(); #endif for (i = 0; i != channel_count; ++i) { - helper_arrays[i] = getalignedbytes(info.frames * sizeof(t_float)); + helper_arrays[i] = getalignedbytes(arraysize * sizeof(t_float)); } - for (i = 0; i != info.frames; ++i) + for (i = 0; i != writesize; ++i) { sf_read_float(sndfile, item, info.channels); @@ -303,6 +364,21 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) } } } + + // fill remaining elements with zero + if(!resize && (arraysize>(info.frames-pos))) + { + for (i = writesize; i != arraysize; ++i) + { + for (j = 0; j != info.channels; ++j) + { + if (j < channel_count) + { + helper_arrays[j][i] = 0; + } + } + } + } #if (_POSIX_MEMLOCK - 0) >= 200112L mlockall(MCL_FUTURE); @@ -313,13 +389,21 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) syncdata[0] = (t_int*)arrays; syncdata[1] = (t_int*)helper_arrays; syncdata[2] = (t_int*)channel_count; - syncdata[3] = (t_int*)(long)info.frames; + syncdata[3] = (t_int*)arraysize; syncdata[4] = (t_int*)x; sys_callback(sndfiler_synchonize, (t_int*)syncdata, 5); + return; } else + { pd_error(x, "Error opening file"); + return; + } + + usage: + pd_error(x, "usage: read [flags] filename array1 array2 ..."); + post("flags: -skip -resize "); } static t_int sndfiler_synchonize(t_int * w) -- cgit v1.2.1 From 5f7d939d6e3a11830d63afe259d31d3ff3a9f8bb Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Tue, 29 Nov 2005 18:34:32 +0000 Subject: removed annoying debug post svn path=/trunk/externals/tb/; revision=4082 --- sndfiler/src/sndfiler.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 80df1c9..227a261 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -341,8 +341,6 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) writesize = (arraysize>(info.frames-pos)) ? info.frames-pos : arraysize; - post("sndfiler: loading file ..."); - #if (_POSIX_MEMLOCK - 0) >= 200112L munlockall(); #endif -- cgit v1.2.1 From 153d5c53085f3c4d5f89af9f4db04fb97d80ba93 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 16 Dec 2005 08:34:10 +0000 Subject: using a semaphore instead of a condion variable for synchronization svn path=/trunk/externals/tb/; revision=4235 --- sndfiler/src/sndfiler.c | 192 ++++++++++++++++++++++++------------------------ 1 file changed, 95 insertions(+), 97 deletions(-) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 227a261..38ebfa8 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -45,6 +45,7 @@ struct _garray #include "m_pd.h" #include "m_fifo.h" #include "pthread.h" +#include "semaphore.h" #endif /* USE_PD_MAIN */ @@ -89,7 +90,7 @@ t_array *h_garray_getarray(t_garray *x) return (0); } if (!template_find_field(_template, gensym("z"), - &zonset, &ztype, &zarraytype)) + &zonset, &ztype, &zarraytype)) { error("array: template %s has no 'z' field", templatesym->s_name); return (0); @@ -97,7 +98,7 @@ t_array *h_garray_getarray(t_garray *x) if (ztype != DT_ARRAY) { error("array: template %s, 'z' field is not an array", - templatesym->s_name); + templatesym->s_name); return (0); } return (sc->sc_vec[zonset].w_array); @@ -128,9 +129,7 @@ typedef struct _sfprocess typedef struct _sfqueue { t_fifo* x_jobs; - - pthread_mutex_t mutex; - pthread_cond_t cond; + sem_t sem; } t_sfqueue; typedef struct _syncdata @@ -158,8 +157,8 @@ static void sndfiler_thread(void) while (1) { t_sfprocess * me; - pthread_cond_wait(&sndfiler_queue.cond, &sndfiler_queue.mutex); - + sem_wait(&sndfiler_queue.sem); + while (me = (t_sfprocess *)fifo_get(sndfiler_queue.x_jobs)) { (me->process)(me->x, me->argc, me->argv); @@ -179,9 +178,8 @@ static void sndfiler_start_thread(void) //initialize queue sndfiler_queue.x_jobs = fifo_init(); - pthread_mutex_init (&sndfiler_queue.mutex,NULL); - pthread_cond_init (&sndfiler_queue.cond,NULL); - + sem_init (&sndfiler_queue.sem,0,0); + // initialize thread pthread_attr_init(&sf_attr); @@ -198,13 +196,13 @@ static void sndfiler_start_thread(void) //start thread status = pthread_create(&sf_thread_id, &sf_attr, - (void *) sndfiler_thread,NULL); + (void *) sndfiler_thread,NULL); if (status != 0) error("Couldn't create sndfiler thread: %d",status); else post("Global sndfiler thread launched, priority: %d", - sf_param.sched_priority); + sf_param.sched_priority); } static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv); @@ -226,7 +224,7 @@ static void sndfiler_read(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) fifo_put(sndfiler_queue.x_jobs, process); - pthread_cond_signal(&sndfiler_queue.cond); + sem_post(&sndfiler_queue.sem); } static t_int sndfiler_synchonize(t_int * w); @@ -247,22 +245,22 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) // parse flags while (argc > 0 && argv->a_type == A_SYMBOL && - *argv->a_w.w_symbol->s_name == '-') + *argv->a_w.w_symbol->s_name == '-') { char *flag = argv->a_w.w_symbol->s_name + 1; - if (!strcmp(flag, "resize")) - { - resize = 1; - argc -= 1; argv += 1; - } - else if (!strcmp(flag, "skip")) - { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((seek = argv[1].a_w.w_float) == 0)) - goto usage; - argc -= 2; argv += 2; - } - else goto usage; + if (!strcmp(flag, "resize")) + { + resize = 1; + argc -= 1; argv += 1; + } + else if (!strcmp(flag, "skip")) + { + if (argc < 2 || argv[1].a_type != A_FLOAT || + ((seek = argv[1].a_w.w_float) == 0)) + goto usage; + argc -= 2; argv += 2; + } + else goto usage; } if (argc < 2) @@ -277,32 +275,32 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) for (i = 0; i != channel_count; ++i) { t_float *dummy; - int size; + int size; t_garray *array; if(!(array = (t_garray *)pd_findbyclass( - atom_getsymbolarg(i+1, argc, argv), garray_class))) - { - pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, - argc, argv)->s_name); - return; - } + atom_getsymbolarg(i+1, argc, argv), garray_class))) + { + pd_error(x, "%s: no such array", atom_getsymbolarg(i+1, + argc, argv)->s_name); + return; + } - if(garray_getfloatarray(array, &size, &dummy)) - arrays[i] = array; - else - { - pd_error(x, "%s: bad template for sndfiler", atom_getsymbolarg(i+1, - argc, argv)->s_name); - return; - } + if(garray_getfloatarray(array, &size, &dummy)) + arrays[i] = array; + else + { + pd_error(x, "%s: bad template for sndfiler", atom_getsymbolarg(i+1, + argc, argv)->s_name); + return; + } - // in multichannel mode: check if arrays have different length - if (arraysize && arraysize != size && !resize) - { - post("sndfiler: arrays have different lengths, resizing to last one ..."); - } - arraysize = size; + // in multichannel mode: check if arrays have different length + if (arraysize && arraysize != size && !resize) + { + post("sndfiler: arrays have different lengths, resizing to last one ..."); + } + arraysize = size; } sndfile = sf_open(file->s_name, SFM_READ, &info); @@ -311,35 +309,35 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) { int pos = 0; int maxchannels = (channel_count < info.channels) ? - channel_count : info.channels; + channel_count : info.channels; t_float * item = alloca(maxchannels * sizeof(t_float)); t_int ** syncdata = getbytes(sizeof(t_int*) * 5); - // negative seek: offset from the end of the file - if(seek<0) - { - pos = sf_seek(sndfile, seek, SEEK_END); - } - if(seek>0) - { - pos = sf_seek(sndfile, seek, SEEK_SET); - } - if(pos == -1) - { - pd_error(x, "invalid seek in soundfile"); - return; - } + // negative seek: offset from the end of the file + if(seek<0) + { + pos = sf_seek(sndfile, seek, SEEK_END); + } + if(seek>0) + { + pos = sf_seek(sndfile, seek, SEEK_SET); + } + if(pos == -1) + { + pd_error(x, "invalid seek in soundfile"); + return; + } - if(resize) - { - writesize = (info.frames-pos); - arraysize = writesize; - } - else - writesize = (arraysize>(info.frames-pos)) ? - info.frames-pos : arraysize; + if(resize) + { + writesize = (info.frames-pos); + arraysize = writesize; + } + else + writesize = (arraysize>(info.frames-pos)) ? + info.frames-pos : arraysize; #if (_POSIX_MEMLOCK - 0) >= 200112L munlockall(); @@ -363,20 +361,20 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) } } - // fill remaining elements with zero - if(!resize && (arraysize>(info.frames-pos))) - { - for (i = writesize; i != arraysize; ++i) - { - for (j = 0; j != info.channels; ++j) - { - if (j < channel_count) - { - helper_arrays[j][i] = 0; - } - } - } - } + // fill remaining elements with zero + if(!resize && (arraysize>(info.frames-pos))) + { + for (i = writesize; i != arraysize; ++i) + { + for (j = 0; j != info.channels; ++j) + { + if (j < channel_count) + { + helper_arrays[j][i] = 0; + } + } + } + } #if (_POSIX_MEMLOCK - 0) >= 200112L mlockall(MCL_FUTURE); @@ -391,17 +389,17 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) syncdata[4] = (t_int*)x; sys_callback(sndfiler_synchonize, (t_int*)syncdata, 5); - return; + return; } else { pd_error(x, "Error opening file"); - return; + return; } - usage: + usage: pd_error(x, "usage: read [flags] filename array1 array2 ..."); - post("flags: -skip -resize "); + post("flags: -skip -resize "); } static t_int sndfiler_synchonize(t_int * w) @@ -426,7 +424,7 @@ static t_int sndfiler_synchonize(t_int * w) if (gl->gl_list == &garray->x_gobj && !garray->x_gobj.g_next) { vmess(&gl->gl_pd, gensym("bounds"), "ffff", 0., gl->gl_y1, - (double)(frames > 1 ? frames-1 : 1), gl->gl_y2); + (double)(frames > 1 ? frames-1 : 1), gl->gl_y2); /* close any dialogs that might have the wrong info now... */ gfxstub_deleteforkey(gl); @@ -461,7 +459,7 @@ static void sndfiler_resize(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) fifo_put(sndfiler_queue.x_jobs, process); - pthread_cond_signal(&sndfiler_queue.cond); + sem_post(&sndfiler_queue.sem); } static void sndfiler_t_resize(t_sndfiler *y, int argc, t_atom *argv) @@ -561,20 +559,20 @@ static void sndfiler_t_resize(t_sndfiler *y, int argc, t_atom *argv) return; - usage: - pd_error(x, "usage: resize tablename size"); + usage: + pd_error(x, "usage: resize tablename size"); } void sndfiler_setup(void) { sndfiler_class = class_new(gensym("sndfiler"), - (t_newmethod)sndfiler_new, 0, - sizeof(t_sndfiler), 0, 0); + (t_newmethod)sndfiler_new, 0, + sizeof(t_sndfiler), 0, 0); class_addmethod(sndfiler_class, (t_method)sndfiler_read, - gensym("read"), A_GIMME, 0); + gensym("read"), A_GIMME, 0); class_addmethod(sndfiler_class, (t_method)sndfiler_resize, - gensym("resize"), A_GIMME, 0); + gensym("resize"), A_GIMME, 0); #ifdef USE_PD_MAIN // needed to start thread callback system -- cgit v1.2.1 From f35587d21c1b141c847e8660403941ea53963447 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Thu, 22 Dec 2005 23:45:20 +0000 Subject: export sndfiler_setup function for Windows svn path=/trunk/externals/tb/; revision=4287 --- sndfiler/src/sndfiler.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 38ebfa8..005b75f 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -563,6 +563,9 @@ static void sndfiler_t_resize(t_sndfiler *y, int argc, t_atom *argv) pd_error(x, "usage: resize tablename size"); } +#ifdef _MSC_VER +__declspec(dllexport) +#endif void sndfiler_setup(void) { sndfiler_class = class_new(gensym("sndfiler"), -- cgit v1.2.1 From 9c5b12f513dc7631af9d8c4bdee302c25aa4382d Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Thu, 22 Dec 2005 23:46:17 +0000 Subject: add config files for the flext build system svn path=/trunk/externals/tb/; revision=4288 --- sndfiler/build/config-lnx.def | 1 + sndfiler/build/config-mac.def | 1 + sndfiler/build/config-win.def | 5 +++++ sndfiler/build/gnumake-lnx-gcc.inc | 1 + sndfiler/build/gnumake-mac-gcc.inc | 1 + sndfiler/build/gnumake-win-cygwin.inc | 3 +++ sndfiler/build/gnumake-win-mingw.inc | 3 +++ sndfiler/build/nmake-win-msvc.inc | 3 +++ sndfiler/package.txt | 4 ++++ 9 files changed, 22 insertions(+) create mode 100644 sndfiler/build/config-lnx.def create mode 100644 sndfiler/build/config-mac.def create mode 100644 sndfiler/build/config-win.def create mode 100644 sndfiler/build/gnumake-lnx-gcc.inc create mode 100644 sndfiler/build/gnumake-mac-gcc.inc create mode 100644 sndfiler/build/gnumake-win-cygwin.inc create mode 100644 sndfiler/build/gnumake-win-mingw.inc create mode 100644 sndfiler/build/nmake-win-msvc.inc create mode 100644 sndfiler/package.txt diff --git a/sndfiler/build/config-lnx.def b/sndfiler/build/config-lnx.def new file mode 100644 index 0000000..fc37b7e --- /dev/null +++ b/sndfiler/build/config-lnx.def @@ -0,0 +1 @@ +# nothing to set diff --git a/sndfiler/build/config-mac.def b/sndfiler/build/config-mac.def new file mode 100644 index 0000000..fc37b7e --- /dev/null +++ b/sndfiler/build/config-mac.def @@ -0,0 +1 @@ +# nothing to set diff --git a/sndfiler/build/config-win.def b/sndfiler/build/config-win.def new file mode 100644 index 0000000..bd7bf72 --- /dev/null +++ b/sndfiler/build/config-win.def @@ -0,0 +1,5 @@ +# where is the libsndfile installation? +SNDFILEPATH=%programfiles%\libsndfile + +SNDFILEINC=$(SNDFILEPATH)\src +SNDFILELIB=$(SNDFILEPATH) diff --git a/sndfiler/build/gnumake-lnx-gcc.inc b/sndfiler/build/gnumake-lnx-gcc.inc new file mode 100644 index 0000000..3314475 --- /dev/null +++ b/sndfiler/build/gnumake-lnx-gcc.inc @@ -0,0 +1 @@ +LIBS += -lsndfile diff --git a/sndfiler/build/gnumake-mac-gcc.inc b/sndfiler/build/gnumake-mac-gcc.inc new file mode 100644 index 0000000..3314475 --- /dev/null +++ b/sndfiler/build/gnumake-mac-gcc.inc @@ -0,0 +1 @@ +LIBS += -lsndfile diff --git a/sndfiler/build/gnumake-win-cygwin.inc b/sndfiler/build/gnumake-win-cygwin.inc new file mode 100644 index 0000000..3b7c000 --- /dev/null +++ b/sndfiler/build/gnumake-win-cygwin.inc @@ -0,0 +1,3 @@ +INCPATH += -I$(SNDFILEINC) +LIBPATH += -L$(SNDFILELIB) +LIBS += -lsndfile diff --git a/sndfiler/build/gnumake-win-mingw.inc b/sndfiler/build/gnumake-win-mingw.inc new file mode 100644 index 0000000..3b7c000 --- /dev/null +++ b/sndfiler/build/gnumake-win-mingw.inc @@ -0,0 +1,3 @@ +INCPATH += -I$(SNDFILEINC) +LIBPATH += -L$(SNDFILELIB) +LIBS += -lsndfile diff --git a/sndfiler/build/nmake-win-msvc.inc b/sndfiler/build/nmake-win-msvc.inc new file mode 100644 index 0000000..9b832cc --- /dev/null +++ b/sndfiler/build/nmake-win-msvc.inc @@ -0,0 +1,3 @@ +INCPATH=$(INCPATH) /I$(SNDFILEINC) +LIBPATH=$(LIBPATH) /LIBPATH:$(SNDFILELIB) +LIBS=$(LIBS) libsndfile.lib diff --git a/sndfiler/package.txt b/sndfiler/package.txt new file mode 100644 index 0000000..8f4281e --- /dev/null +++ b/sndfiler/package.txt @@ -0,0 +1,4 @@ +NAME=sndfiler +SRCDIR=src +SRCS=sndfiler.c +BUILDDIR=build -- cgit v1.2.1 From 2b41ff8d01772ca760721894fd53b76d5818655d Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 1 Jan 2006 18:39:19 +0000 Subject: adding error function svn path=/trunk/externals/tb/; revision=4345 --- erf~/erf~.c | 64 ++++++++++++++++++++++++++++++++++++++++ erf~/makefile | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 erf~/erf~.c create mode 100644 erf~/makefile diff --git a/erf~/erf~.c b/erf~/erf~.c new file mode 100644 index 0000000..2f59212 --- /dev/null +++ b/erf~/erf~.c @@ -0,0 +1,64 @@ +/* + * + * Error function for pd + * Copyright (C) 2006 Tim Blechmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "m_pd.h" +#include "math.h" + +static t_class *erf_class; + +typedef struct _erf +{ + t_object x_obj; + float x_f; +} t_erf; + +static void *erf_new(void) +{ + t_erf *x = (t_erf *)pd_new(erf_class); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); +} + +static t_int *erf_perform(t_int *w) +{ + t_float *in = (t_float *)(w[1]); + t_float *out = (t_float *)(w[2]); + int n = (int)(w[3]); + + while (n--) + *out++ = erff(*in++); + + return w+4; +} + +static void erf_dsp(t_erf *x, t_signal **sp) +{ + dsp_add(erf_perform, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +void erf_tilde_setup(void) +{ + erf_class = class_new(gensym("erf~"), (t_newmethod)erf_new, 0, + sizeof(t_erf), 0, A_DEFFLOAT, 0); + CLASS_MAINSIGNALIN(erf_class, t_erf, x_f); + class_addmethod(erf_class, (t_method)erf_dsp, gensym("dsp"), 0); +} diff --git a/erf~/makefile b/erf~/makefile new file mode 100644 index 0000000..a4c8ed4 --- /dev/null +++ b/erf~/makefile @@ -0,0 +1,94 @@ +NAME=erf~ +CSYM=erf~ + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From f6342b53b06b3b9551d0e9752d33703ec59c1810 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Jan 2006 12:13:07 +0000 Subject: oops ... forgot to commit the files for the complementary error function svn path=/trunk/externals/tb/; revision=4372 --- erfc~/erfc~.c | 64 +++++++++++++++++++++++++++++++++++++++ erfc~/makefile | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 erfc~/erfc~.c create mode 100644 erfc~/makefile diff --git a/erfc~/erfc~.c b/erfc~/erfc~.c new file mode 100644 index 0000000..d7b4737 --- /dev/null +++ b/erfc~/erfc~.c @@ -0,0 +1,64 @@ +/* + * + * Complementary error function for pd + * Copyright (C) 2006 Tim Blechmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "m_pd.h" +#include "math.h" + +static t_class *erfc_class; + +typedef struct _erfc +{ + t_object x_obj; + float x_f; +} t_erfc; + +static void *erfc_new(void) +{ + t_erfc *x = (t_erfc *)pd_new(erfc_class); + outlet_new(&x->x_obj, gensym("signal")); + x->x_f = 0; + return (x); +} + +static t_int *erfc_perfcorm(t_int *w) +{ + t_float *in = (t_float *)(w[1]); + t_float *out = (t_float *)(w[2]); + int n = (int)(w[3]); + + while (n--) + *out++ = erfcf(*in++); + + return w+4; +} + +static void erfc_dsp(t_erfc *x, t_signal **sp) +{ + dsp_add(erfc_perfcorm, 3, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n); +} + +void erfc_tilde_setup(void) +{ + erfc_class = class_new(gensym("erfc~"), (t_newmethod)erfc_new, 0, + sizeof(t_erfc), 0, A_DEFFLOAT, 0); + CLASS_MAINSIGNALIN(erfc_class, t_erfc, x_f); + class_addmethod(erfc_class, (t_method)erfc_dsp, gensym("dsp"), 0); +} diff --git a/erfc~/makefile b/erfc~/makefile new file mode 100644 index 0000000..a874c3c --- /dev/null +++ b/erfc~/makefile @@ -0,0 +1,94 @@ +NAME=erfc~ +CSYM=erfc~ + +current: pd_linux + +# ----------------------- NT ----------------------- + +pd_nt: $(NAME).dll + +.SUFFIXES: .dll + +PDNTCFLAGS = /W3 /WX /DNT /DPD /nologo +VC="C:\Program Files\Microsoft Visual Studio\Vc98" + +PDNTINCLUDE = /I. /I..\..\src /I$(VC)\include + +PDNTLDIR = $(VC)\lib +PDNTLIB = $(PDNTLDIR)\libc.lib \ + $(PDNTLDIR)\oldnames.lib \ + $(PDNTLDIR)\kernel32.lib \ + ..\..\bin\pd.lib + +.c.dll: + cl $(PDNTCFLAGS) $(PDNTINCLUDE) /c $*.c + link /dll /export:$(CSYM)_setup $*.obj $(PDNTLIB) + +# ----------------------- IRIX 5.x ----------------------- + +pd_irix5: $(NAME).pd_irix5 + +.SUFFIXES: .pd_irix5 + +SGICFLAGS5 = -o32 -DPD -DUNIX -DIRIX -O2 + +SGIINCLUDE = -I../../src + +.c.pd_irix5: + $(CC) $(SGICFLAGS5) $(SGIINCLUDE) -o $*.o -c $*.c + ld -elf -shared -rdata_shared -o $*.pd_irix5 $*.o + rm $*.o + +# ----------------------- IRIX 6.x ----------------------- + +pd_irix6: $(NAME).pd_irix6 + +.SUFFIXES: .pd_irix6 + +SGICFLAGS6 = -n32 -DPD -DUNIX -DIRIX -DN32 -woff 1080,1064,1185 \ + -OPT:roundoff=3 -OPT:IEEE_arithmetic=3 -OPT:cray_ivdep=true \ + -Ofast=ip32 + +.c.pd_irix6: + $(CC) $(SGICFLAGS6) $(SGIINCLUDE) -o $*.o -c $*.c + ld -n32 -IPA -shared -rdata_shared -o $*.pd_irix6 $*.o + rm $*.o + +# ----------------------- LINUX i386 ----------------------- + +pd_linux: $(NAME).pd_linux + +.SUFFIXES: .pd_linux + +LINUXCFLAGS = -DPD -O2 -fPIC -funroll-loops -fomit-frame-pointer \ + -Wall -W -Wshadow -Wstrict-prototypes -Werror \ + -Wno-unused -Wno-parentheses -Wno-switch + +LINUXINCLUDE = -I../../src + +LSTRIP = strip --strip-unneeded -R .note -R .comment + +.c.pd_linux: + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + $(LSTRIP) $*.pd_linux + rm -f $*.o + +# ----------------------- Mac OSX ----------------------- + +pd_darwin: $(NAME).pd_darwin + +.SUFFIXES: .pd_darwin + +DARWINCFLAGS = -DPD -O2 -Wall -W -Wshadow -Wstrict-prototypes \ + -Wno-unused -Wno-parentheses -Wno-switch + +.c.pd_darwin: + $(CC) $(DARWINCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c + $(CC) -bundle -undefined suppress -flat_namespace -o $*.pd_darwin $*.o + rm -f $*.o + +# ---------------------------------------------------------- + +clean: + rm -f *.o *.pd_* so_locations -- cgit v1.2.1 From b5e8ffd7605b53f368c81ddae06dd997f57a4ca3 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 7 Jan 2006 20:48:29 +0000 Subject: fixed bug svn path=/trunk/externals/tb/; revision=4378 --- chaos/src/chaos_dsp.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index e86fc30..786bee3 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -372,16 +372,16 @@ void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, { int outlets = m_system->get_num_eq(); - float phase = int(m_phase); + float phase = m_phase; int i = 0; while (n) { - if (phase == 0) + if (phase <= 0) { m_system->m_perform(); - phase = int (m_sr * m_invfreq); + phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; -- cgit v1.2.1 From e97a3414a2d0609a15d7323ce53faa4b1eaad18b Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sat, 14 Jan 2006 22:06:38 +0000 Subject: removing autobuild system ... updating scons build system svn path=/trunk/externals/tb/; revision=4403 --- chaos/AUTHORS | 3 -- chaos/ChangeLog | 0 chaos/Makefile.am | 2 - chaos/NEWS | 0 chaos/README | 0 chaos/SConstruct | 19 ++++--- chaos/bootstrap.sh | 5 -- chaos/configure.ac | 145 -------------------------------------------------- chaos/src/Makefile.am | 66 ----------------------- 9 files changed, 12 insertions(+), 228 deletions(-) delete mode 100644 chaos/AUTHORS delete mode 100644 chaos/ChangeLog delete mode 100644 chaos/Makefile.am delete mode 100644 chaos/NEWS delete mode 100644 chaos/README delete mode 100755 chaos/bootstrap.sh delete mode 100644 chaos/configure.ac delete mode 100644 chaos/src/Makefile.am diff --git a/chaos/AUTHORS b/chaos/AUTHORS deleted file mode 100644 index 022e6c0..0000000 --- a/chaos/AUTHORS +++ /dev/null @@ -1,3 +0,0 @@ -Tim Blechmann -Mike McGonagle -B. Bogart \ No newline at end of file diff --git a/chaos/ChangeLog b/chaos/ChangeLog deleted file mode 100644 index e69de29..0000000 diff --git a/chaos/Makefile.am b/chaos/Makefile.am deleted file mode 100644 index 5db2166..0000000 --- a/chaos/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -SUBDIRS = src -EXTRA_DIST = src \ No newline at end of file diff --git a/chaos/NEWS b/chaos/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/chaos/README b/chaos/README deleted file mode 100644 index e69de29..0000000 diff --git a/chaos/SConstruct b/chaos/SConstruct index 2c682b8..e02934e 100644 --- a/chaos/SConstruct +++ b/chaos/SConstruct @@ -27,8 +27,9 @@ opt = Options(['options.cache']) opt.AddOptions( BoolOption('debug', 'Build with debugging symbols', False), ('optimize', 'Optimize for specific architecture', None), - ('icc', 'Build with intel c compiler', False), + BoolOption('icc', 'Build with intel c compiler', False), BoolOption('simd', 'build with simd instructions', False), + BoolOption('cmem', 'build with normal memory allocation', True), ('prefix', 'install prefix', '/usr/local'), ('flext_path', 'flext path', None), ('pd_path', 'pd path', None), @@ -39,8 +40,7 @@ opt.Update(env) opt.Save('options.cache',env) Help(opt.GenerateHelpText(env)) - -if env.Dictionary().has_key('icc') and env['icc']: +if env['icc']: env.Replace(CC="icc", SHCC="icc", CXX="icc", @@ -55,6 +55,10 @@ if env.Dictionary().has_key('icc') and env['icc']: print "Using intel c compiler" +if env['cmem']: + env.Append(CPPDEFINES=['FLEXT_USE_CMEM']) + + if env.Dictionary().has_key('flext_path'): env.Append(CPPPATH=[env['flext_path']]) else: @@ -75,13 +79,14 @@ if env.Dictionary().has_key('optimize'): if env.Dictionary().has_key('debug') and env['debug']: env.Append(CCFLAGS=' -g ') env.Append(CPPDEFINES=['_DEBUG']) - env.Append(LIBS = 'flext-pd') + env.Append(LIBS = 'flext-pd_d') env.Append(LINKFLAGS=' -g') else: - env.Append(CPPDEFINES=['FLEXT_SHARED']) env.Append(LIBS = 'flext-pd') env.Append(CPPDEFINES="NDEBUG") +env.Append(CPPDEFINES=['FLEXT_SHARED']) + ###################################################################### # # read package.txt @@ -149,5 +154,5 @@ except: external = env.SharedLibrary(name, sources, SHLIBPREFIX='', SHLIBSUFFIX='.pd_linux') prefix = env['prefix'] -env.Install(prefix+'/lib/pd/extra',external) -env.Alias('install', prefix+'/lib/pd/extra') +install = env.Install(prefix+'/lib/pd/extra',external) +env.Alias('install', install) diff --git a/chaos/bootstrap.sh b/chaos/bootstrap.sh deleted file mode 100755 index 695f2bd..0000000 --- a/chaos/bootstrap.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/sh - -aclocal \ -&& automake-1.8 --gnu --add-missing \ -&& autoconf \ No newline at end of file diff --git a/chaos/configure.ac b/chaos/configure.ac deleted file mode 100644 index 67bf056..0000000 --- a/chaos/configure.ac +++ /dev/null @@ -1,145 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. -AC_INIT(chaos~, 0.01, TimBlechmann@gmx.de, chaos~) -AM_INIT_AUTOMAKE - -dnl Checks for programs. -AC_PROG_MAKE_SET -AC_PROG_CC -AC_PROG_CXX - -dnl Checks for libraries. -AC_CHECK_LIB(m, sin) - -dnl Checks for header files. -AC_HEADER_STDC - -dnl Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE -AC_TYPE_SIZE_T -AC_HEADER_TIME - - -dnl Checks for command line arguments -AC_ARG_WITH(flextdir, - [ --with-flextdir path to flext headers], - [ - flextdir=$withval - INCLUDEDIR="-I$withval $INCLUDEDIR" - ], - [echo "path to flext headers required" && exit 1]) - -AC_CHECK_FILE("$flextdir/flext.h",, - [echo "$flextdir/flext.h not found" && exit 1]) - - -AC_ARG_ENABLE(system, - [ --enable-system system (default: pd)], - [ - if test "enableval" == "max"; then - AC_DEFINE(FLEXT_SYS,1) - else - AC_DEFINE(FLEXT_SYS,2) - fi - system = $enabeval - ], - AC_DEFINE(FLEXT_SYS,2) - ) - - -AC_ARG_WITH(sysdir, - [ --with-sysdir path pd / max installation], - [ - SYSDIR=$withval - INCLUDEDIR="-I$withval $INCLUDEDIR" - ], - [echo "path to pd / max installation required" && exit 1]) - - -AC_ARG_ENABLE(static, - [ --enable-static static linking with libflext], - LDFLAGS="-Bstatic $LDFLAGS" - , - [ - AC_DEFINE(FLEXT_SHARED) - AC_DEFINE(FLEXT_THREADS) - LDFLAGS="-Bdynamic $LDFLAGS" - ] - ) - -AC_ARG_ENABLE(debug, - [ --enable-debug link with libflext_d library for debugging], - [ - LDFLAGS="-lflext_d $LDFLAGS" - CXXFLAGS="-g" - ], - [ - LDFLAGS="-lflext $LDFLAGS" - CXXFLAGS="-O3" - ]) - -dnl mtune will break gcc 3.3.x -AC_ARG_ENABLE(optimize, [ --enable-optimize enables optimized builds for: pentium4, pentium3, G4, G5], - [ - case $enableval in - pentium3 | pentium3m) - OPT_FLAGS = "-mtune=$enableval -march=$enableval -mmmx -msse -mfpmath=sse";; - pentium2 | athlon | pentium-mmx) - OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx";; - pentium) - OPT_FLAGS="-mtune=$enableval -march=$enableval";; - pentium4 | pentium4m | pentium-m | prescott | nocona | athlon-xp | athlon-mp | athlon64 | opteron) - OPT_FLAGS="-mtune=$enableval -march=$enableval -mmmx -msse -msse2 -mfpmath=sse";; - G5 | G4) - OPT_FLAGS="-mtune=$enableval -march=$enableval -maltivec -faltivec -malign-natural";; - G3) - OPT_FLAGS="-mtune=$enableval -march=$enableval -malign-natural";; - *) - ;; - esac - ]) - -dnl select build -if test `uname -s` == "Linux"; then - dnl no max/msp for linux - OBJEXT=o - EXTENSION=pd_linux -fi - -if test `uname -s` == "Darwin"; then - dnl just a guess - if test "$system" = "max"; then - echo "build system doesn't support max, yet" && exit 1; - else - LDFLAGS="-bundle -bundle_loader $LDFLAGS" - FRAMEWORKS= - EXTENSION=pd_darwin - LIBS="gcc $LIBS" - fi - OBJEXT=o -fi - -if test `uname -s` == "Cygwin"; then - dnl just a guess - if test "$system" = "max"; then - echo "build system doesn't support max, yet" && exit 1; - else - EXTENSION=dll - LIBS="gcc $LIBS bin/pd bin/pthreadVC.dll" - LDFLAGS="-L$SYSDIR" - fi -fi - - -AC_SUBST(EXTENSION) -AC_SUBST(INCLUDEDIR) -AC_SUBST(CXXFLAGS) -AC_SUBST(OPT_FLAGS) -AC_SUBST(LDFLAGS) -AC_SUBST(DEFS) -AC_SUBST(LIBS) -AC_SUBST(OBJEXT) -AC_SUBST(FRAMEWORKS) -AC_SUBST(SYSDIR) -AC_OUTPUT([Makefile - src/Makefile]) diff --git a/chaos/src/Makefile.am b/chaos/src/Makefile.am deleted file mode 100644 index e85310c..0000000 --- a/chaos/src/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -NAME = chaos - -BUILT_SOURCES = main.cpp ode_base.cpp chaos_dsp.cpp \ - bernoulli_dsp.cpp bernoulli_msg.cpp \ - bungalow_tent_dsp.cpp bungalow_tent_msg.cpp \ - circle_map_dsp.cpp circle_map_msg.cpp \ - coupled_logistic_dsp.cpp coupled_logistic_msg.cpp \ - chua_dsp.cpp chua_msg.cpp \ - driven_anharmonic_dsp.cpp driven_anharmonic_msg.cpp \ - driven_van_der_pol_dsp.cpp driven_van_der_pol_msg.cpp \ - duffing_map_dsp.cpp duffing_map_msg.cpp \ - gauss_map_dsp.cpp gauss_map_msg.cpp \ - henon_map_dsp.cpp henon_map_msg.cpp \ - ikeda_laser_map_dsp.cpp ikeda_laser_map_msg.cpp \ - latoocarfian_dsp.cpp latoocarfian_msg.cpp \ - latoomutalpha_dsp.cpp latoomutalpha_msg.cpp \ - latoomutbeta_dsp.cpp latoomutbeta_msg.cpp \ - latoomutgamma_dsp.cpp latoomutgamma_msg.cpp \ - logistic_dsp.cpp logistic_msg.cpp logistic_search.cpp\ - lorenz_dsp.cpp lorenz_msg.cpp \ - lozi_map_dsp.cpp lozi_map_msg.cpp \ - roessler_dsp.cpp roessler_msg.cpp \ - sine_map_dsp.cpp sine_map_msg.cpp \ - standard_map_dsp.cpp standard_map_msg.cpp \ - tent_map_dsp.cpp tent_map_msg.cpp - -CXXFLAGS = @CXXFLAGS@ \ - @OPT_FLAGS@ \ - @INCLUDEDIR@ \ - $(DEFS) - -LDFLAGS = @LDFLAGS@ \ - $(patsubst %,-framework %,$(FRAMEWORKS)) - -LIBS = @LIBS@ - -FRAMEWORKS = @FRAMEWORKS@ - -TARGET =$(NAME).@EXTENSION@ - -OBJECTS = $(patsubst %.cpp,%.@OBJEXT@,$(BUILT_SOURCES)) - -SYSDIR = @SYSDIR@ - - -# ----------------------------- targets -------------------------------- - - -all-local: $(OBJECTS) - $(CXX) $(LDFLAGS) -shared $^ $(LIBS) -o ../$(TARGET) - strip --strip-unneeded ../$(TARGET) - -%.@OBJEXT@ : %.cpp - $(CXX) -c $(CXXFLAGS) $< -o $@ - -dist-hook: - rm -f ./*~ - rm -f ./*.@OBJEXT@ - rm ./Makefile - -clean-local: - rm -f ../$(TARGET) - rm -f ./*.@OBJEXT@ - -install-exec-local: - install ../$(TARGET) $(SYSDIR)extra \ No newline at end of file -- cgit v1.2.1 From b65ae6220a420b3a0b1ed23d8ef0934379cebbb6 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Thu, 19 Jan 2006 21:02:12 +0000 Subject: fixes for OSX (doesn't have a sem_init function) svn path=/trunk/externals/tb/; revision=4447 --- sndfiler/src/sndfiler.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 005b75f..6d1e4c6 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -129,7 +129,7 @@ typedef struct _sfprocess typedef struct _sfqueue { t_fifo* x_jobs; - sem_t sem; + sem_t* sem; } t_sfqueue; typedef struct _syncdata @@ -154,11 +154,11 @@ static t_sndfiler *sndfiler_new(void) /* global soundfiler thread ... sleeping until signaled */ static void sndfiler_thread(void) { - while (1) + for(;;) { t_sfprocess * me; - sem_wait(&sndfiler_queue.sem); - + sem_wait(sndfiler_queue.sem); + while (me = (t_sfprocess *)fifo_get(sndfiler_queue.x_jobs)) { (me->process)(me->x, me->argc, me->argv); @@ -178,8 +178,17 @@ static void sndfiler_start_thread(void) //initialize queue sndfiler_queue.x_jobs = fifo_init(); - sem_init (&sndfiler_queue.sem,0,0); - +#ifdef __APPLE__ + sndfiler_queue.sem = sem_open("sndfilerthread",O_CREAT|O_EXCL,0,0); + if(sndfiler_queue.sem == SEM_FAILED) + error("Couldn't create sndfiler semaphore: %i",errno); +#else + sndfiler_queue.sem = (sem_t *)getbytes(sizeof(sem_t)); + status = sem_init(sndfiler_queue.sem,0,0); + if(status != 0) + error("Couldn't create sndfiler semaphore: %i",status); +#endif + // initialize thread pthread_attr_init(&sf_attr); @@ -224,7 +233,7 @@ static void sndfiler_read(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) fifo_put(sndfiler_queue.x_jobs, process); - sem_post(&sndfiler_queue.sem); + sem_post(sndfiler_queue.sem); } static t_int sndfiler_synchonize(t_int * w); @@ -459,7 +468,7 @@ static void sndfiler_resize(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) fifo_put(sndfiler_queue.x_jobs, process); - sem_post(&sndfiler_queue.sem); + sem_post(sndfiler_queue.sem); } static void sndfiler_t_resize(t_sndfiler *y, int argc, t_atom *argv) -- cgit v1.2.1 From a556c60dc72ddf3bd7b4e1cfc3c85f999ccb6e51 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Thu, 19 Jan 2006 22:21:01 +0000 Subject: better fixes for OSX (use kernel functions) svn path=/trunk/externals/tb/; revision=4448 --- sndfiler/src/sndfiler.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 6d1e4c6..aa6d8d2 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -44,6 +44,7 @@ struct _garray #include "m_pd.h" #include "m_fifo.h" + #include "pthread.h" #include "semaphore.h" @@ -68,6 +69,18 @@ struct _garray #include #endif /* _POSIX_MEMLOCK */ +#ifdef __APPLE__ +#include +#define SEM_T semaphore_t +#define SEM_INIT(s) (semaphore_create(mach_task_self(),&s,SYNC_POLICY_FIFO,0) == 0) +#define SEM_SIGNAL(s) semaphore_signal(s) +#define SEM_WAIT(s) semaphore_wait(s) +#else +#define SEM_T sem_t +#define SEM_INIT(s) (sem_init(&s,0,0) == 0) +#define SEM_SIGNAL(s) sem_post(&s) +#define SEM_WAIT(s) sem_wait(&s) +#endif /************ forward declarations **************/ @@ -129,7 +142,7 @@ typedef struct _sfprocess typedef struct _sfqueue { t_fifo* x_jobs; - sem_t* sem; + SEM_T sem; } t_sfqueue; typedef struct _syncdata @@ -157,7 +170,7 @@ static void sndfiler_thread(void) for(;;) { t_sfprocess * me; - sem_wait(sndfiler_queue.sem); + SEM_WAIT(sndfiler_queue.sem); while (me = (t_sfprocess *)fifo_get(sndfiler_queue.x_jobs)) { @@ -178,16 +191,10 @@ static void sndfiler_start_thread(void) //initialize queue sndfiler_queue.x_jobs = fifo_init(); -#ifdef __APPLE__ - sndfiler_queue.sem = sem_open("sndfilerthread",O_CREAT|O_EXCL,0,0); - if(sndfiler_queue.sem == SEM_FAILED) - error("Couldn't create sndfiler semaphore: %i",errno); -#else - sndfiler_queue.sem = (sem_t *)getbytes(sizeof(sem_t)); - status = sem_init(sndfiler_queue.sem,0,0); - if(status != 0) + + status = SEM_INIT(sndfiler_queue.sem); + if(!status) error("Couldn't create sndfiler semaphore: %i",status); -#endif // initialize thread pthread_attr_init(&sf_attr); @@ -233,7 +240,7 @@ static void sndfiler_read(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) fifo_put(sndfiler_queue.x_jobs, process); - sem_post(sndfiler_queue.sem); + SEM_SIGNAL(sndfiler_queue.sem); } static t_int sndfiler_synchonize(t_int * w); @@ -468,7 +475,7 @@ static void sndfiler_resize(t_sndfiler * x, t_symbol *s, int argc, t_atom* argv) fifo_put(sndfiler_queue.x_jobs, process); - sem_post(sndfiler_queue.sem); + SEM_SIGNAL(sndfiler_queue.sem); } static void sndfiler_t_resize(t_sndfiler *y, int argc, t_atom *argv) -- cgit v1.2.1 From c9f622385bb18ecfe16e7810507d5ddc1330e468 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Fri, 20 Jan 2006 07:39:13 +0000 Subject: Included more Mach headers for function prototypes svn path=/trunk/externals/tb/; revision=4450 --- sndfiler/src/sndfiler.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index aa6d8d2..8c4dbe5 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -70,6 +70,8 @@ struct _garray #endif /* _POSIX_MEMLOCK */ #ifdef __APPLE__ +#include +#include #include #define SEM_T semaphore_t #define SEM_INIT(s) (semaphore_create(mach_task_self(),&s,SYNC_POLICY_FIFO,0) == 0) -- cgit v1.2.1 From 60fee223a0a27439814547aee438bb5c53e44437 Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Sun, 29 Jan 2006 19:29:29 +0000 Subject: fixed compilation for main pd svn path=/trunk/externals/tb/; revision=4517 --- sndfiler/src/Makefile.pd_main | 6 +++--- sndfiler/src/sndfiler.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sndfiler/src/Makefile.pd_main b/sndfiler/src/Makefile.pd_main index b56b4b3..f5a70e5 100755 --- a/sndfiler/src/Makefile.pd_main +++ b/sndfiler/src/Makefile.pd_main @@ -4,7 +4,7 @@ # this should point to the directory which contains # m_pd.h and g_canvas.h -PD_SCR = /home/holzi/pd-0.39-1/src +PD_SCR = /usr/local/src/pd/src #PD_SCR = c:/pd/src # this is the pd directory, usually /usr/lib/pd @@ -19,10 +19,10 @@ SNDFILE_SRC = /usr/include # the directory, where libsndfile is located # (in linux it' normally not necessary, in windows it's # normally in c:/windwos/system or so) -SNDFILE_PATH = c:/windows/system +#SNDFILE_PATH = c:/windows/system # path to threadlib.h -THREADLIB_SRC = /home/Georg/pd-cvs/externals/grh/threadlib/src +THREADLIB_SRC = /home/holzi/pd-cvs/externals/grh/threadlib/src #THREADLIB_SRC = c:/Georg/pd-cvs/externals/grh/threadlib/src # path to threadlib.pd_linux/dll/pd_darwin diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 8c4dbe5..507510a 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -46,7 +46,6 @@ struct _garray #include "m_fifo.h" #include "pthread.h" -#include "semaphore.h" #endif /* USE_PD_MAIN */ @@ -57,6 +56,7 @@ struct _garray #include "stdlib.h" #include "sched.h" /* for thread priority */ #include +#include "semaphore.h" /* for alloca */ #ifdef MSW -- cgit v1.2.1 From 682501946dd0637cfe9fc2477bc3a6e78c032349 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 29 Jan 2006 22:13:49 +0000 Subject: limit stacksize of helper thread to 1mb ... should be more than enough ... svn path=/trunk/externals/tb/; revision=4518 --- sndfiler/src/sndfiler.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 507510a..9bf6b65 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -203,7 +203,10 @@ static void sndfiler_start_thread(void) sf_param.sched_priority=sched_get_priority_min(SCHED_OTHER); pthread_attr_setschedparam(&sf_attr,&sf_param); - + + /* 1mb of stack should be enough */ + pthread_attr_setstacksize(&sf_attr,1048576); + #ifdef UNIX if (sys_hipriority == 1/* && getuid() == 0 */) { -- cgit v1.2.1 From 10dee9a91925645cd9e3bb14e5ef31e8a338949e Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Wed, 1 Feb 2006 09:01:28 +0000 Subject: now possible to read ogg file (using libvorbisfile) svn path=/trunk/externals/tb/; revision=4531 --- sndfiler/src/Makefile | 9 +- sndfiler/src/Makefile.pd_main | 14 ++- sndfiler/src/file_input.c | 253 ++++++++++++++++++++++++++++++++++++++++++ sndfiler/src/file_input.h | 66 +++++++++++ sndfiler/src/sndfiler.c | 170 +++++----------------------- sndfiler/src/sndfiler.h | 87 +++++++++++++++ 6 files changed, 451 insertions(+), 148 deletions(-) create mode 100644 sndfiler/src/file_input.c create mode 100644 sndfiler/src/file_input.h create mode 100755 sndfiler/src/sndfiler.h diff --git a/sndfiler/src/Makefile b/sndfiler/src/Makefile index 2b17d1c..b8f1c8a 100755 --- a/sndfiler/src/Makefile +++ b/sndfiler/src/Makefile @@ -2,6 +2,8 @@ NAME=sndfiler CSYM=sndfiler +OBJ=sndfiler.o file_input.o + current: pd_linux # ----------------------- NT ----------------------- @@ -65,13 +67,14 @@ LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ -Wall -W -Wshadow -Wstrict-prototypes -Werror \ -Wno-unused -Wno-parentheses -Wno-switch -LINUXINCLUDE = -I/home/tim/pd/devel_0_39/src +LINUXINCLUDE = -I../../../../pd/src LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: - cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm -lsndfile + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o sndfiler.o -c sndfiler.c + cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o file_input.o -c file_input.c + cc -Wl,-export_dynamic --shared -o $*.pd_linux $(OBJ) -lm -lsndfile -lvorbisfile # $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/sndfiler/src/Makefile.pd_main b/sndfiler/src/Makefile.pd_main index f5a70e5..29bde80 100755 --- a/sndfiler/src/Makefile.pd_main +++ b/sndfiler/src/Makefile.pd_main @@ -41,6 +41,8 @@ CC_FLAGS = -DPD -DUSE_PD_MAIN -O3 -funroll-loops \ -Wno-unused -fomit-frame-pointer LD_FLAGS = --export-dynamic -shared -o +OBJ=sndfiler.o file_input.o + current: @echo ---------------------------- @echo USAGE: @@ -56,11 +58,12 @@ pd_linux: $(NAME).pd_linux .SUFFIXES: .pd_linux CC_UNIX = -DUNIX -fPIC -pthread -LIB_UNIX = -lc -lm -lsndfile $(THREADLIB_PATH)/threadlib.pd_linux +LIB_UNIX = -lc -lm -lsndfile -lvorbisfile $(THREADLIB_PATH)/threadlib.pd_linux .c.pd_linux: - $(CC) $(CC_UNIX) $(CC_FLAGS) $(INCLUDE) -o $*.o -c $*.c - $(LD) $(LD_FLAGS) $*.pd_linux $*.o $(LIB_UNIX) + $(CC) $(CC_UNIX) $(CC_FLAGS) $(INCLUDE) -o sndfiler.o -c sndfiler.c + $(CC) $(CC_UNIX) $(CC_FLAGS) $(INCLUDE) -o file_input.o -c file_input.c + $(LD) $(LD_FLAGS) $*.pd_linux $(OBJ) $(LIB_UNIX) strip --strip-unneeded $*.pd_linux chmod 755 $*.pd_linux @test -d ../bin || mkdir -p ../bin @@ -97,11 +100,12 @@ pd_darwin: $(NAME).pd_darwin CC_DARWIN = -pthread LD_DARWIN = -bundle -undefined suppress -flat_namespace \ -bundle_loader $(PD_PATH)/bin/pd --export-dynamic \ - -L/sw/lib -L/opt/local/lib -lsndfile \ + -L/sw/lib -L/opt/local/lib -lsndfile -lvorbisfile \ $(THREADLIB_PATH)/threadlib.pd_darwin .c.pd_darwin: - $(CC) $(CC_FLAGS) $(CC_DARWIN) $(INCLUDE) -o $*.o -c $*.c + $(CC) $(CC_UNIX) $(CC_FLAGS) $(INCLUDE) -o sndfiler.o -c sndfiler.c + $(CC) $(CC_UNIX) $(CC_FLAGS) $(INCLUDE) -o file_input.o -c file_input.c $(LD) $(LD_DARWIN) -o $*.pd_darwin $*.o $(LIB) chmod 755 $*.pd_darwin @test -d ../bin || mkdir -p ../bin diff --git a/sndfiler/src/file_input.c b/sndfiler/src/file_input.c new file mode 100644 index 0000000..79ad27e --- /dev/null +++ b/sndfiler/src/file_input.c @@ -0,0 +1,253 @@ +/* + * threaded soundfiler for PD + * Copyright (C) 2005, Georg Holzmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "sndfiler.h" +#include "file_input.h" + +int check_fileformat(t_symbol* file) +{ + FILE *fp = NULL; + OggVorbis_File vorbisfile; + + // partially opens a vorbis file to test for Vorbis-ness + if( !(fp = fopen(file->s_name, "r")) ) + return -1; + + if( ov_test(fp, &vorbisfile, NULL, 0) < 0 ) + { + fclose(fp); + return USE_LIBSNDFILE; + } + + ov_clear(&vorbisfile); + return USE_LIBVORBISFILE; +} + +int read_libsndfile(t_float** helper_arrays, int channel_count, int seek, + int resize, int array_size, t_symbol* file) +{ + int arraysize = array_size; + int writesize = 0, i=0, j=0; + SNDFILE* sndfile; + SF_INFO info; + + sndfile = sf_open(file->s_name, SFM_READ, &info); + + if(!sndfile) + return -1; + + int pos = 0; + int maxchannels = (channel_count < info.channels) ? + channel_count : info.channels; + + t_float * item = alloca(maxchannels * sizeof(t_float)); + + // negative seek: offset from the end of the file + if(seek<0) + { + if(CHECK_SEEK(seek+info.frames, info.frames)) + pos = sf_seek(sndfile, seek, SEEK_END); + else pos = -1; + } + if(seek>0) + { + if(CHECK_SEEK(seek, info.frames)) + pos = sf_seek(sndfile, seek, SEEK_SET); + else pos = -1; + } + if(pos == -1) + { + sf_close(sndfile); + post("invalid seek in soundfile"); + return -1; + } + + if(resize) + { + writesize = (info.frames-pos); + arraysize = writesize; + } + else + writesize = (arraysize>(info.frames-pos)) ? + info.frames-pos : arraysize; + +#if (_POSIX_MEMLOCK - 0) >= 200112L + munlockall(); +#endif + + for (i = 0; i != channel_count; ++i) + { + helper_arrays[i] = getalignedbytes(arraysize * sizeof(t_float)); + } + + for (i = 0; i != writesize; ++i) + { + sf_read_float(sndfile, item, info.channels); + + for (j = 0; j != info.channels; ++j) + { + if (j < channel_count) + { + helper_arrays[j][i] = item[j]; + } + } + } + + // fill remaining elements with zero + if(!resize && (arraysize > (info.frames-pos))) + { + for (i = writesize; i != arraysize; ++i) + { + for (j = 0; j != info.channels; ++j) + { + if (j < channel_count) + { + helper_arrays[j][i] = 0; + } + } + } + } + +#if (_POSIX_MEMLOCK - 0) >= 200112L + mlockall(MCL_FUTURE); +#endif + + sf_close(sndfile); + return arraysize; +} + +int read_libvorbisfile(t_float** helper_arrays, int channel_count, int seek, + int resize, int array_size, t_symbol* file) +{ + int arraysize = array_size; + int writesize = 0, i=0, j=0; + int pos=0, maxchannels=0, frames=0, frames_read=0; + int current_section=0, finished=0; + float **buftmp = NULL; + FILE *fp = NULL; + OggVorbis_File vorbisfile; + vorbis_info *info; + + if( !(fp = fopen(file->s_name, "r")) ) + return -1; + + if( ov_open(fp, &vorbisfile, NULL, 0) < 0 ) + { + fclose(fp); + return -1; + } + + info = ov_info(&vorbisfile, -1); + frames = ov_pcm_total(&vorbisfile, -1); + if( !info || frames==OV_EINVAL ) + { + ov_clear(&vorbisfile); + post("failed to get info about vorbis file"); + return -1; + } + + maxchannels = (channel_count < info->channels) ? + channel_count : info->channels; + + // negative seek: offset from the end of the file + if(seek<0) + { + if(CHECK_SEEK(frames+seek, frames)) + { + int ret = ov_pcm_seek(&vorbisfile, frames+seek); + if(ret!=0) + pos =-1; + else + pos = frames+seek; + } + else pos = -1; + } + if(seek>0) + { + if(CHECK_SEEK(seek, frames)) + { + int ret = ov_pcm_seek(&vorbisfile, seek); + if(ret!=0) + pos =-1; + else + pos = seek; + } + else pos = -1; + } + if(pos == -1) + { + ov_clear(&vorbisfile); + post("invalid seek in vorbis file"); + return -1; + } + + if(resize) + { + writesize = (frames-pos); + arraysize = writesize; + } + else + writesize = (arraysize>(frames-pos)) ? + frames-pos : arraysize; + +#if (_POSIX_MEMLOCK - 0) >= 200112L + munlockall(); +#endif + + for (i = 0; i != channel_count; ++i) + { + helper_arrays[i] = getalignedbytes(arraysize * sizeof(t_float)); + } + + for (i = 0; i != writesize; ++i) + { + int ret = ov_read_float(&vorbisfile, &buftmp, 1, + ¤t_section); + if(ret!=1) + post("wrong return type while ogg decoding!"); + + for (j = 0; j != channel_count; ++j) + { + helper_arrays[j][i] = buftmp[j][0]; + } + } + + // fill remaining elements with zero + if(!resize && (arraysize > (frames-pos))) + { + for (i = writesize; i != arraysize; ++i) + { + for (j = 0; j != info->channels; ++j) + { + if (j < channel_count) + { + helper_arrays[j][i] = 0; + } + } + } + } + +#if (_POSIX_MEMLOCK - 0) >= 200112L + mlockall(MCL_FUTURE); +#endif + + ov_clear(&vorbisfile); + return arraysize; +} diff --git a/sndfiler/src/file_input.h b/sndfiler/src/file_input.h new file mode 100644 index 0000000..e5b5232 --- /dev/null +++ b/sndfiler/src/file_input.h @@ -0,0 +1,66 @@ +/* + * threaded soundfiler for PD + * Copyright (C) 2005, Georg Holzmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _FILE_INPUT__ +#define _FILE_INPUT__ + +#define USE_LIBSNDFILE 0 +#define USE_LIBVORBISFILE 1 + +//! returns 1 if s is in [0,c) +#define CHECK_SEEK(s, c) (s<0 ? 0 : (s>=c ? 0 : 1)) + +/*! + * checks which library to use + * + * @param file filename + * @return USE_LIBSNDFILE or USE_LIBVORBISFILE, -1 if there was an error + */ +int check_fileformat(t_symbol* file); + +/*! + * read audio data with libsndfile + * + * @param helper_arrays (unallocated) pointer to the data + * @param channel_count nr of channels + * @param seek frames to seek in file + * @param resize 1 if array should be resized + * @param array_size size of the array in samples + * @param file filename + * @return new arraysiize, -1 if there was a failure + */ +int read_libsndfile(t_float** helper_arrays, int channel_count, int seek, + int resize, int array_size, t_symbol* file); + +/*! + * read audio data with libvorbisfile + * + * @param helper_arrays (unallocated) pointer to the data + * @param channel_count nr of channels + * @param seek frames to seek in file + * @param resize 1 if array should be resized + * @param array_size size of the array in samples + * @param file filename + * @return new arraysiize, -1 if there was a failure + */ +int read_libvorbisfile(t_float** helper_arrays, int channel_count, int seek, + int resize, int array_size, t_symbol* file); + +#endif //_FILE_INPUT__ diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c index 9bf6b65..4cd14d9 100755 --- a/sndfiler/src/sndfiler.c +++ b/sndfiler/src/sndfiler.c @@ -1,6 +1,6 @@ /* * - * threaded soundfiler based on libsndfile + * threaded soundfiler for pd * Copyright (C) 2005, Tim Blechmann * (C) 2005, Georg Holzmann * @@ -20,14 +20,18 @@ * Boston, MA 02111-1307, USA. */ -/* to be compatible with main pd */ -#ifdef USE_PD_MAIN +#include "sndfiler.h" +#include "file_input.h" + -#define getalignedbytes(a) getbytes(a) -#define freealignedbytes(a,b) freebytes(a,b) -#include "threadlib.h" +/************ forward declarations **************/ -/* forward declaration */ +#ifdef UNIX +/* real-time flag, true if priority boosted */ +extern int sys_hipriority; +#endif + +#ifdef USE_PD_MAIN struct _garray { t_gobj x_gobj; @@ -39,56 +43,6 @@ struct _garray char x_saveit; /* true if we should save this with parent */ char x_listviewing; /* true if list view window is open */ }; - -#else /* now for pd_devel */ - -#include "m_pd.h" -#include "m_fifo.h" - -#include "pthread.h" - -#endif /* USE_PD_MAIN */ - - -#include "g_canvas.h" -#include "sndfile.h" - -#include "stdlib.h" -#include "sched.h" /* for thread priority */ -#include -#include "semaphore.h" - -/* for alloca */ -#ifdef MSW -#include -#else -#include "alloca.h" -#endif - -#if (_POSIX_MEMLOCK - 0) >= 200112L -#include -#endif /* _POSIX_MEMLOCK */ - -#ifdef __APPLE__ -#include -#include -#include -#define SEM_T semaphore_t -#define SEM_INIT(s) (semaphore_create(mach_task_self(),&s,SYNC_POLICY_FIFO,0) == 0) -#define SEM_SIGNAL(s) semaphore_signal(s) -#define SEM_WAIT(s) semaphore_wait(s) -#else -#define SEM_T sem_t -#define SEM_INIT(s) (sem_init(&s,0,0) == 0) -#define SEM_SIGNAL(s) sem_post(&s) -#define SEM_WAIT(s) sem_wait(&s) -#endif - -/************ forward declarations **************/ - -#ifdef UNIX -/* real-time flag, true if priority boosted */ -extern int sys_hipriority; #endif /* get a garray's "array" structure. */ @@ -206,7 +160,7 @@ static void sndfiler_start_thread(void) /* 1mb of stack should be enough */ pthread_attr_setstacksize(&sf_attr,1048576); - + #ifdef UNIX if (sys_hipriority == 1/* && getuid() == 0 */) { @@ -252,18 +206,15 @@ static t_int sndfiler_synchonize(t_int * w); static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) { - int i, j; + int i, j, lib; int channel_count; t_float** helper_arrays; int resize = 0; - int seek = 0, arraysize = 0, writesize; + int seek = 0, arraysize = 0; t_symbol* file; t_garray ** arrays; - SNDFILE* sndfile; - SF_INFO info; - // parse flags while (argc > 0 && argv->a_type == A_SYMBOL && *argv->a_w.w_symbol->s_name == '-') @@ -276,9 +227,10 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) } else if (!strcmp(flag, "skip")) { - if (argc < 2 || argv[1].a_type != A_FLOAT || - ((seek = argv[1].a_w.w_float) == 0)) + if (argc < 2 || argv[1].a_type != A_FLOAT) goto usage; + else + seek = argv[1].a_w.w_float; argc -= 2; argv += 2; } else goto usage; @@ -323,85 +275,23 @@ static void sndfiler_read_cb(t_sndfiler * x, int argc, t_atom* argv) } arraysize = size; } - - sndfile = sf_open(file->s_name, SFM_READ, &info); - if (sndfile) + lib = check_fileformat(file); + if(lib == USE_LIBSNDFILE) + arraysize = read_libsndfile(helper_arrays, channel_count, seek, + resize, arraysize, file); + else if(lib == USE_LIBVORBISFILE) + arraysize = read_libvorbisfile(helper_arrays, channel_count, seek, + resize, arraysize, file); + else { - int pos = 0; - int maxchannels = (channel_count < info.channels) ? - channel_count : info.channels; + pd_error(x, "Error opening file"); + return; + } - t_float * item = alloca(maxchannels * sizeof(t_float)); - + if(arraysize > 0) + { t_int ** syncdata = getbytes(sizeof(t_int*) * 5); - - // negative seek: offset from the end of the file - if(seek<0) - { - pos = sf_seek(sndfile, seek, SEEK_END); - } - if(seek>0) - { - pos = sf_seek(sndfile, seek, SEEK_SET); - } - if(pos == -1) - { - pd_error(x, "invalid seek in soundfile"); - return; - } - - if(resize) - { - writesize = (info.frames-pos); - arraysize = writesize; - } - else - writesize = (arraysize>(info.frames-pos)) ? - info.frames-pos : arraysize; - -#if (_POSIX_MEMLOCK - 0) >= 200112L - munlockall(); -#endif - - for (i = 0; i != channel_count; ++i) - { - helper_arrays[i] = getalignedbytes(arraysize * sizeof(t_float)); - } - - for (i = 0; i != writesize; ++i) - { - sf_read_float(sndfile, item, info.channels); - - for (j = 0; j != info.channels; ++j) - { - if (j < channel_count) - { - helper_arrays[j][i] = item[j]; - } - } - } - - // fill remaining elements with zero - if(!resize && (arraysize>(info.frames-pos))) - { - for (i = writesize; i != arraysize; ++i) - { - for (j = 0; j != info.channels; ++j) - { - if (j < channel_count) - { - helper_arrays[j][i] = 0; - } - } - } - } - -#if (_POSIX_MEMLOCK - 0) >= 200112L - mlockall(MCL_FUTURE); -#endif - - sf_close(sndfile); syncdata[0] = (t_int*)arrays; syncdata[1] = (t_int*)helper_arrays; diff --git a/sndfiler/src/sndfiler.h b/sndfiler/src/sndfiler.h new file mode 100755 index 0000000..f5fbd2c --- /dev/null +++ b/sndfiler/src/sndfiler.h @@ -0,0 +1,87 @@ +/* + * + * threaded soundfiler for pd + * Copyright (C) 2005, Tim Blechmann + * (C) 2005, Georg Holzmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef _SND_FILER__ +#define _SND_FILER__ + + +/* to be compatible with main pd */ +#ifdef USE_PD_MAIN + +#define getalignedbytes(a) getbytes(a) +#define freealignedbytes(a,b) freebytes(a,b) +#include "threadlib.h" + +#else /* now for pd_devel */ + +#include "m_pd.h" +#include "m_fifo.h" + +#include "pthread.h" + +#endif /* USE_PD_MAIN */ + + +#include "g_canvas.h" +#include "sndfile.h" +#include "vorbis/codec.h" +#include "vorbis/vorbisfile.h" + +#include "stdlib.h" +#include +#include "sched.h" /* for thread priority */ +#include +#include "semaphore.h" + +#ifdef MSW +#include +#include +#endif + +/* for alloca */ +#ifdef MSW +#include +#else +#include "alloca.h" +#endif + +#if (_POSIX_MEMLOCK - 0) >= 200112L +#include +#endif /* _POSIX_MEMLOCK */ + +#ifdef __APPLE__ +#include +#include +#include +#define SEM_T semaphore_t +#define SEM_INIT(s) (semaphore_create(mach_task_self(),&s,SYNC_POLICY_FIFO,0) == 0) +#define SEM_SIGNAL(s) semaphore_signal(s) +#define SEM_WAIT(s) semaphore_wait(s) +#else +#define SEM_T sem_t +#define SEM_INIT(s) (sem_init(&s,0,0) == 0) +#define SEM_SIGNAL(s) sem_post(&s) +#define SEM_WAIT(s) sem_wait(&s) +#endif + + +#endif // _SND_FILER__ -- cgit v1.2.1 From ed1c74748d9e187b98ff49cf4d629019e0539584 Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Wed, 1 Feb 2006 09:02:20 +0000 Subject: updated helpfile for new ogg support svn path=/trunk/externals/tb/; revision=4532 --- sndfiler/doc/sndfiler-help.pd | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sndfiler/doc/sndfiler-help.pd b/sndfiler/doc/sndfiler-help.pd index fb402f7..1e4dbeb 100755 --- a/sndfiler/doc/sndfiler-help.pd +++ b/sndfiler/doc/sndfiler-help.pd @@ -25,12 +25,9 @@ #X obj 241 667 table array2; #X obj 55 645 sndfiler; #X text 288 34 threaded soundfiler; -#X text 308 51 using libsndfile; #X text 161 113 ::: SNDFILER :::; -#X text 63 152 A threaded soundfiler for PD using libsndfile.; #X text 65 182 REQUIREMENTS:; #X text 118 199 - pd >= 0.39; -#X text 118 215 - libsndfile; #X text 118 231 - threadlib (for main pd); #X text 48 539 threaded resize of arrays:; #X text 33 267 read a file: read [flags] filename array1 array2 ... @@ -42,12 +39,16 @@ #X text 33 324 -skip : skip nr. of samples in soundfile \, if negative \, it will be counted from the end of the file !; #X text 82 722 (c) 2005 \, Tim Blechmann \, Georg Holzmann; +#X text 184 53 using libsndfile and libvorbisfile; +#X text 53 140 A threaded soundfiler for PD using libsndfile and libvorbisfile +(for ogg files).; +#X text 118 215 - libsndfile + libvorbisfile; #X connect 3 0 20 0; -#X connect 4 0 31 0; +#X connect 4 0 28 0; #X connect 6 0 4 0; #X connect 10 0 9 0; #X connect 12 0 18 0; #X connect 14 0 12 0; #X connect 18 0 13 0; #X connect 20 0 2 0; -#X connect 31 0 5 0; +#X connect 28 0 5 0; -- cgit v1.2.1 From cceea140611ff282d1513937f615abe2b8081ebc Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Fri, 17 Mar 2006 09:37:55 +0000 Subject: removing file svn path=/trunk/externals/tb/; revision=4737 --- sc4pd/pd/LFSaw.pd | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 sc4pd/pd/LFSaw.pd diff --git a/sc4pd/pd/LFSaw.pd b/sc4pd/pd/LFSaw.pd deleted file mode 100644 index 190ddcf..0000000 --- a/sc4pd/pd/LFSaw.pd +++ /dev/null @@ -1,16 +0,0 @@ -#N canvas 0 0 782 300 10; -#X obj 93 170 dac~; -#X obj 107 117 LFSaw~ 440 ar; -#X obj 108 75 sig~ 440; -#X msg 223 88 set \$1; -#X floatatom 227 53 5 0 0 0 - - -; -#X msg 20 31 kr; -#X msg 62 30 ar; -#X obj 405 107 LFSaw 1 100; -#X connect 1 0 0 0; -#X connect 1 0 0 1; -#X connect 2 0 1 0; -#X connect 3 0 1 0; -#X connect 4 0 3 0; -#X connect 5 0 1 0; -#X connect 6 0 1 0; -- cgit v1.2.1 From 13cba7a7997e318fbba01a36912219355e387d52 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 May 2006 18:34:34 +0000 Subject: rewrote most stuff using templates svn path=/trunk/externals/tb/; revision=5105 --- chaos/src/bernoulli_map.hpp | 10 +-- chaos/src/bungalow_tent_map.hpp | 10 +-- chaos/src/chaos_base.hpp | 37 +++------ chaos/src/chaos_defs.hpp | 8 +- chaos/src/chaos_dsp.hpp | 171 ++++++++++++++++++++------------------- chaos/src/chaos_msg.hpp | 38 +++++---- chaos/src/chaos_search.hpp | 28 +++---- chaos/src/chua.hpp | 9 +-- chaos/src/circle_map.hpp | 7 +- chaos/src/coupled_logistic.hpp | 19 ++--- chaos/src/delayed_logistic.hpp | 10 +-- chaos/src/driven_anharmonic.hpp | 10 +-- chaos/src/driven_van_der_pol.hpp | 9 +-- chaos/src/duffing.hpp | 8 +- chaos/src/duffing_map.hpp | 10 +-- chaos/src/gauss_map.hpp | 9 +-- chaos/src/gaussian_map.hpp | 10 +-- chaos/src/henon_map.hpp | 9 +-- chaos/src/hydrogen.hpp | 8 +- chaos/src/ikeda_laser_map.hpp | 9 +-- chaos/src/latoocarfian.hpp | 9 +-- chaos/src/latoomutalpha.hpp | 9 +-- chaos/src/latoomutbeta.hpp | 10 +-- chaos/src/latoomutgamma.hpp | 12 +-- chaos/src/linear_congruental.hpp | 5 +- chaos/src/logistic_map.hpp | 5 +- chaos/src/lorenz.hpp | 5 +- chaos/src/lozi_map.hpp | 10 +-- chaos/src/map_base.hpp | 16 +--- chaos/src/ode_base.cpp | 51 ------------ chaos/src/ode_base.hpp | 96 ++++++++++++++-------- chaos/src/roessler.hpp | 10 +-- chaos/src/sine_map.hpp | 5 +- chaos/src/standard_map.hpp | 5 +- chaos/src/tent_map.hpp | 9 +-- 35 files changed, 260 insertions(+), 426 deletions(-) diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index f084c67..c720e1b 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -25,21 +25,15 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bernoulli: - public map_base + public map_base<1> { public: - bernoulli(): - map_base(1) + bernoulli() { CHAOS_SYS_INIT(x,0.5,0); } - ~bernoulli() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index 4d4836b..fd098f3 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -33,21 +33,15 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class bungalow_tent: - public map_base + public map_base<1> { public: - bungalow_tent(): - map_base(1) + bungalow_tent() { CHAOS_SYS_INIT(x, 0.6,0); CHAOS_PAR_INIT(r, 0.5); } - ~bungalow_tent() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 5c87bed..4b984d9 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -1,7 +1,7 @@ // // // chaos~ -// Copyright (C) 2004 Tim Blechmann +// Copyright (C) 2004, 2006 Tim Blechmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -23,26 +23,23 @@ #include "chaos.hpp" #include -#define MAXDIMENSION 5 // this should be enough for the first - +template class chaos_base { public: - chaos_base(int n): - m_num_eq(n) + chaos_base() { - m_data = new data_t[n]; } - inline t_sample get_data(unsigned int i) { + assert(i attr_ind; - // TableAnyMap attr_ind; /* thomas fragen :-) */ // check the integrity of the system - virtual void m_verify() + inline void m_verify() { } inline void m_bash_denormals() { - for (int i = 0; i != get_num_eq(); ++i) + for (int i = 0; i != dimensions; ++i) { #ifndef DOUBLE_PRECISION if (PD_BIGORSMALL(m_data[i])) @@ -71,28 +67,13 @@ public: } }; - data_t * m_data; // state of the system + data_t m_data[dimensions]; // state of the system protected: - virtual void m_step() = 0; // iteration - const int m_num_eq; // number of equations of the system + virtual void m_step() = 0; // iteration flext::AtomList Parameter; // parameter flext::AtomList System; // system }; -#define CHAOS_CALLBACKS \ -public: \ -void get_dimension(int &i) \ -{ \ - i = m_system->get_num_eq(); \ -} \ -FLEXT_CALLGET_I(get_dimension); - - -#define CHAOS_ATTRIBUTES \ -FLEXT_ADDATTR_GET("dimension",get_dimension); - - - #define __chaos_base_hpp #endif /* __chaos_base_hpp */ diff --git a/chaos/src/chaos_defs.hpp b/chaos/src/chaos_defs.hpp index bf8607c..c4e68a5 100644 --- a/chaos/src/chaos_defs.hpp +++ b/chaos/src/chaos_defs.hpp @@ -100,11 +100,11 @@ data_t m_##NAME; public: \ void get_##NAME(t_float &f) \ { \ - f = m_system->get_##NAME(); \ + f = m_system.get_##NAME(); \ } \ void set_##NAME(t_float &f) \ { \ - m_system->set_##NAME(f); \ + m_system.set_##NAME(f); \ } \ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); @@ -113,11 +113,11 @@ FLEXT_CALLVAR_F(get_##NAME, set_##NAME); public: \ void get_##NAME(int &i) \ { \ - i = m_system->get_##NAME(); \ + i = m_system.get_##NAME(); \ } \ void set_##NAME(int &i) \ { \ - m_system->set_##NAME(i); \ + m_system.set_##NAME(i); \ } \ FLEXT_CALLVAR_I(get_##NAME, set_##NAME); diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 786bee3..9f6dd75 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -20,13 +20,68 @@ #include "chaos_base.hpp" -template class chaos_dsp +template +class chaos_dsp : public flext_dsp { FLEXT_HEADER(chaos_dsp, flext_dsp); +protected: + chaos_dsp(int argc, t_atom* argv) + { + m_sr = 44100; /* assume default sampling rate */ + int size = m_system.get_num_eq(); + + m_values = new t_float[size]; + m_slopes = new t_float[size]; + m_nextvalues = new t_float[size]; + m_nextmidpts = new t_float[size]; + m_curves = new t_float[size]; + + /* create inlets and zero arrays*/ + for (int i = 0; i != size; ++i) + { + AddOutSignal(); + m_values[i] = 0; + m_slopes[i] = 0; + m_nextvalues[i] = 0; + m_nextmidpts[i] = 0; + m_curves[i] = 0; + } + + FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); + FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); + + if (argc > 0) + { + CHAOS_INIT(freq, GetAInt(argv[0])); + } + else + { + CHAOS_INIT(freq, 440); + } + + if (argc > 1) + { + CHAOS_INIT(imethod, GetAInt(argv[1])); + } + else + { + CHAOS_INIT(imethod, 0); + } + m_phase = 0; + } + + ~chaos_dsp() + { + delete[] m_values; + delete[] m_slopes; + delete[] m_nextvalues; + delete[] m_nextmidpts; + delete[] m_curves; + } + public: - /* signal functions: */ /* for frequency = sr */ void m_signal_(int n, t_sample *const *insigs,t_sample *const *outsigs); @@ -58,7 +113,7 @@ public: void (thisType::*m_routine)(int n, t_sample *const *insigs,t_sample *const *outsigs); /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ t_sample * m_values; /* actual value */ t_sample * m_slopes; /* actual slope for cubic interpolation */ @@ -106,15 +161,15 @@ public: } if (imethod == 0) - for (int j = 0; j != m_system->get_num_eq(); ++j) + for (int j = 0; j != m_system.get_num_eq(); ++j) { - m_values[j] = m_system->get_data(j); + m_values[j] = m_system.get_data(j); m_slopes[j] = 0; } if(i == 2 && imethod != 2) { - for (int j = 0; j != m_system->get_num_eq(); ++j) + for (int j = 0; j != m_system.get_num_eq(); ++j) { m_phase = 0; /* reschedule to avoid click, find a better way later*/ m_nextvalues[j] = m_values[j]; @@ -183,67 +238,13 @@ public: #define CHAOS_DSP_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_dsp, chaos_dsp) \ \ -SYSTEM##_dsp(int argc, t_atom* argv ) \ -{ \ - m_sr = 44100; /* assume default sampling rate */ \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - m_values = new t_float[size]; \ - m_slopes = new t_float[size]; \ - m_nextvalues = new t_float[size]; \ - m_nextmidpts = new t_float[size]; \ - m_curves = new t_float[size]; \ - \ - /* create inlets and zero arrays*/ \ - for (int i = 0; i != size; ++i) \ - { \ - AddOutSignal(); \ - m_values[i] = 0; \ - m_slopes[i] = 0; \ - m_nextvalues[i] = 0; \ - m_nextmidpts[i] = 0; \ - m_curves[i] = 0; \ - } \ - \ - FLEXT_ADDATTR_VAR("frequency", get_freq, set_freq); \ - FLEXT_ADDATTR_VAR("interpolation_method",get_imethod, set_imethod); \ - \ - if (argc > 0) \ - { \ - CHAOS_INIT(freq, GetAInt(argv[0])); \ - } \ - else \ - { \ - CHAOS_INIT(freq, 440); \ - } \ - \ - if (argc > 1) \ - { \ - CHAOS_INIT(imethod, GetAInt(argv[1])); \ - } \ - else \ - { \ - CHAOS_INIT(imethod, 0); \ - } \ - \ - m_phase = 0; \ - \ - ATTRIBUTES; \ -} \ - \ -~SYSTEM##_dsp() \ +SYSTEM##_dsp(int argc, t_atom* argv): \ + chaos_dsp(argc, argv) \ { \ - delete m_system; \ - delete[] m_values; \ - delete[] m_slopes; \ - delete[] m_nextvalues; \ - delete[] m_nextmidpts; \ - delete[] m_curves; \ + ATTRIBUTES; \ } \ \ -FLEXT_ATTRVAR_F(m_freq); \ +FLEXT_ATTRVAR_F(m_freq); \ FLEXT_ATTRVAR_I(m_imethod); @@ -252,14 +253,14 @@ template void chaos_dsp::m_signal_(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); for (int i = 0; i!=n; ++i) { - m_system->m_perform(); + m_system.m_perform(); for (int j = 0; j != outlets; ++j) { - outsigs[j][i] = m_system->get_data(j); + outsigs[j][i] = m_system.get_data(j); } } } @@ -269,7 +270,7 @@ template void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -278,7 +279,7 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, { while (phase <= 0) { - m_system->m_perform(); + m_system.m_perform(); phase += m_sr * m_invfreq; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -287,7 +288,7 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, for (int i = 0; i != outlets; ++i) { - SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + SetSamples(outsigs[i]+offset, next, m_system.get_data(i)); } offset += next; } @@ -299,7 +300,7 @@ template void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -308,7 +309,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); } @@ -318,7 +319,7 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, for (int i = 0; i != outlets; ++i) { - SetSamples(outsigs[i]+offset, next, m_system->get_data(i)); + SetSamples(outsigs[i]+offset, next, m_system.get_data(i)); } offset += next; } @@ -330,7 +331,7 @@ template void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -340,11 +341,11 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + m_slopes[j] = (m_system.get_data(j) - m_values[j]) / phase; } int next = (phase < n) ? phase : n; @@ -370,7 +371,7 @@ template void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -380,11 +381,11 @@ void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, { if (phase <= 0) { - m_system->m_perform(); + m_system.m_perform(); phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) - m_slopes[j] = (m_system->get_data(j) - m_values[j]) / phase; + m_slopes[j] = (m_system.get_data(j) - m_values[j]) / phase; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -409,7 +410,7 @@ template void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); int phase = int(m_phase); @@ -419,14 +420,14 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; for (int j = 0; j != outlets; ++j) { t_sample value = m_nextvalues[j]; - m_nextvalues[j]= m_system->get_data(j); + m_nextvalues[j]= m_system.get_data(j); m_values[j] = m_nextmidpts[j]; m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; @@ -461,7 +462,7 @@ template void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, t_sample *const *outsigs) { - int outlets = m_system->get_num_eq(); + int outlets = m_system.get_num_eq(); float phase = m_phase; @@ -471,14 +472,14 @@ void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, { if (phase == 0) { - m_system->m_perform(); + m_system.m_perform(); phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; for (int j = 0; j != outlets; ++j) { t_sample value = m_nextvalues[j]; - m_nextvalues[j]= m_system->get_data(j); + m_nextvalues[j]= m_system.get_data(j); m_values[j] = m_nextmidpts[j]; m_nextmidpts[j] = (m_nextvalues[j] + value) * 0.5f; diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 357ff6a..9025273 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -20,29 +20,34 @@ #include "chaos_base.hpp" -template class chaos_msg - : public flext_base +template +class chaos_msg: + public flext_base { FLEXT_HEADER(chaos_msg, flext_base); - ~chaos_msg() - { - delete m_system; - } +protected: + chaos_msg(int argc, t_atom* argv) + { + int size = m_system.get_num_eq(); + + for (int i = 0; i != size; ++i) + AddOutFloat(); + FLEXT_ADDBANG(0, m_bang); + } public: - /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ void m_bang() { - m_system->m_perform(); - int outlets = m_system->get_num_eq(); + m_system.m_perform(); + int outlets = m_system.get_num_eq(); while (outlets--) { - ToOutFloat(outlets, m_system->get_data(outlets)); + ToOutFloat(outlets, m_system.get_data(outlets)); } } @@ -54,15 +59,8 @@ public: #define CHAOS_MSG_INIT(SYSTEM, ATTRIBUTES) \ FLEXT_HEADER(SYSTEM##_msg, chaos_msg) \ \ -SYSTEM##_msg(int argc, t_atom* argv ) \ +SYSTEM##_msg(int argc, t_atom* argv ): \ +chaos_msg(argc, argv) \ { \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ - \ - for (int i = 0; i != size; ++i) \ - AddOutFloat(); \ - \ ATTRIBUTES; \ - FLEXT_ADDBANG(0, m_bang); \ } diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp index a7fc44d..1b812a0 100644 --- a/chaos/src/chaos_search.hpp +++ b/chaos/src/chaos_search.hpp @@ -20,6 +20,8 @@ #include "chaos_base.hpp" +#define MAXDIMENSION 5 + template class chaos_search : public flext_base { @@ -28,7 +30,7 @@ template class chaos_search public: /* local data for system, output and interpolation */ - system * m_system; /* the system */ + system m_system; /* the system */ data_t min[MAXDIMENSION]; /* minimal coordinates */ @@ -75,11 +77,11 @@ public: - send lyapunov exponent to 4 */ - for (std::map::iterator it = m_system->attr_ind.begin(); - it != m_system->attr_ind.end(); ++it) + for (std::map::iterator it = m_system.attr_ind.begin(); + it != m_system.attr_ind.end(); ++it) { post("key %s", it->first->s_name); - post("value %f", m_system->get_data(it->second)); + post("value %f", m_system.get_data(it->second)); } } @@ -99,9 +101,7 @@ FLEXT_HEADER(SYSTEM##_search, chaos_search) \ \ SYSTEM##_search(int argc, t_atom* argv ) \ { \ - m_system = new SYSTEM; \ - \ - int size = m_system->get_num_eq(); \ + int size = m_system.get_num_eq(); \ \ \ m_asymptotic_steps = 10000; \ @@ -119,10 +119,6 @@ SYSTEM##_search(int argc, t_atom* argv ) \ FLEXT_ADDMETHOD_(0,"search", m_search); \ } \ \ -~SYSTEM##_search() \ -{ \ - delete m_system; \ -} \ \ FLEXT_ATTRVAR_I(m_transient_steps); \ FLEXT_ATTRVAR_I(m_asymptotic_steps); @@ -132,7 +128,7 @@ FLEXT_ATTRVAR_I(m_asymptotic_steps); template void chaos_search::m_search() { - int dimensions = m_system->get_num_eq(); + int dimensions = m_system.get_num_eq(); ly = 0; data_t diff_old = 0.1; @@ -141,12 +137,12 @@ void chaos_search::m_search() /* transient dynamics */ for (int i = 0; i != m_transient_steps; ++i) { - m_system->m_perform(); + m_system.m_perform(); } for (int i = 0; i != dimensions; ++i) { - last[i] = min[i] = max[i] = m_system->m_data[i]; + last[i] = min[i] = max[i] = m_system.m_data[i]; } /* now we start the analysis */ @@ -154,13 +150,13 @@ void chaos_search::m_search() for (int i = 0; i != m_asymptotic_steps; ++i) { - m_system->m_perform(); + m_system.m_perform(); data_t diff = 0; for (int j = 0; j != dimensions; ++j) { /* update min/max */ - data_t datum = m_system->m_data[j]; + data_t datum = m_system.m_data[j]; if (datum > max[j]) max[j] = datum; else if (datum < min[j]) diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index 997116c..f8c6e31 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -31,11 +31,10 @@ // taken from Viktor Avrutin: lecture notes class chua: - public ode_base + public ode_base<3> { public: - chua(): - ode_base(3) + chua() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.05); @@ -50,10 +49,6 @@ public: CHAOS_PAR_INIT(beta,30); } - ~chua() - { - } - virtual void m_system(data_t* deriv, data_t* data) { data_t x1 = data[0]; diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 0a52993..294b7d6 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -27,11 +27,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class circle_map: - public map_base + public map_base<1> { public: circle_map() - : map_base(1) { CHAOS_SYS_INIT(x, 0.4,0); @@ -39,10 +38,6 @@ public: CHAOS_PAR_INIT(r, 3); } - ~circle_map() - { - - } virtual void m_step() { diff --git a/chaos/src/coupled_logistic.hpp b/chaos/src/coupled_logistic.hpp index 2e4b160..048aae1 100644 --- a/chaos/src/coupled_logistic.hpp +++ b/chaos/src/coupled_logistic.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class coupled_logistic: - public map_base + public map_base<2> { public: - coupled_logistic(): - map_base(2) + coupled_logistic() { CHAOS_PAR_INIT(e, 0.06); CHAOS_PAR_INIT(r, 3.7); @@ -39,11 +38,7 @@ public: CHAOS_SYS_INIT(y, 0.2,1); } - ~coupled_logistic() - { - } - - virtual void m_step() + virtual inline void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; @@ -56,7 +51,7 @@ public: CHAOS_SYSPAR_FUNCS(e); CHAOS_SYSPAR_FUNCS_PRED(r, m_pred_r); - bool m_pred_r(t_float f) + static bool m_pred_r(t_float f) { return (f > 0) && (f < 4); } @@ -64,12 +59,12 @@ public: CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_xy); CHAOS_SYSVAR_FUNCS_PRED(y, 0, m_pred_xy); - bool m_pred_xy(t_float f) + static bool m_pred_xy(t_float f) { return (f > 0) && (f < 1); } - virtual void m_verify() + inline void m_verify() { data_t x = m_data[0]; data_t y = m_data[1]; @@ -83,8 +78,6 @@ public: m_data[1] += -rand_range(0,0.2); } } - - }; #define COUPLED_LOGISTIC_CALLBACKS \ diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index 47360e7..3db7e27 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -26,11 +26,10 @@ // taken from E. Atlee Jackson: Perspective of nonlinear dynamics (Vol. 2) class delayed_logistic: - public map_base + public map_base<1> { public: - delayed_logistic(): - map_base(1) + delayed_logistic() { CHAOS_SYS_INIT(x, 0.5, 0); CHAOS_PAR_INIT(alpha, 3.8); @@ -38,10 +37,7 @@ public: m_delayed = get_x(); /* the initial state of the delay */ } - ~delayed_logistic() - { - - } + virtual void m_step() { diff --git a/chaos/src/driven_anharmonic.hpp b/chaos/src/driven_anharmonic.hpp index 2d72071..7d6bfd6 100644 --- a/chaos/src/driven_anharmonic.hpp +++ b/chaos/src/driven_anharmonic.hpp @@ -29,11 +29,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_anharmonic - : public ode_base + : public ode_base<2> { public: - driven_anharmonic(): - ode_base(2) + driven_anharmonic() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -50,10 +49,7 @@ public: m_t = 0; } - - ~driven_anharmonic() - { - } + virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index e538185..3c034d2 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -30,11 +30,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_van_der_pol - : public ode_base + : public ode_base<3> { public: - driven_van_der_pol(): - ode_base(3) + driven_van_der_pol() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -48,9 +47,7 @@ public: CHAOS_PAR_INIT(k,5); } - ~driven_van_der_pol() - { - } + virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp index 6cdafd6..ee7f7fb 100644 --- a/chaos/src/duffing.hpp +++ b/chaos/src/duffing.hpp @@ -26,11 +26,10 @@ class duffing: - public ode_base + public ode_base<2> { public: - duffing(): - ode_base(2) + duffing() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); @@ -45,9 +44,6 @@ public: t = 0; } - ~duffing() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index f0e3001..46fecbf 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -26,11 +26,10 @@ // taken from Viktor Avrutin: AnT-Demos-4.669 class duffing_map: - public map_base + public map_base<2> { public: - duffing_map(): - map_base(2) + duffing_map() { CHAOS_SYS_INIT(x1, 0.5, 0); CHAOS_SYS_INIT(x2, 0.5, 1); @@ -38,10 +37,7 @@ public: CHAOS_PAR_INIT(b, 0.5); } - ~duffing_map() - { - - } + virtual void m_step() { diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index 641b93a..d013bae 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -28,19 +28,14 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class gauss_map: - public map_base + public map_base<1> { public: - gauss_map(): - map_base(1) + gauss_map() { CHAOS_SYS_INIT(x,0.5, 0); } - ~gauss_map() - { - - } virtual void m_step() { diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index 9b2b8ca..c6aaf1e 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -26,11 +26,10 @@ // taken from Robert C. Hilborn: Chaos and Nonlinear Dynamics class gaussian_map: - public map_base + public map_base<1> { public: - gaussian_map(): - map_base(1) + gaussian_map() { CHAOS_SYS_INIT(x, 0.5, 0); @@ -38,10 +37,7 @@ public: CHAOS_PAR_INIT(c,0.5); } - ~gaussian_map() - { - - } + virtual void m_step() { diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index bb1c6c7..014fa68 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class henon: - public map_base + public map_base<2> { public: - henon(): - map_base(2) + henon() { CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); @@ -39,10 +38,6 @@ public: CHAOS_PAR_INIT(b,0.3); } - ~henon() - { - - } virtual void m_step() { diff --git a/chaos/src/hydrogen.hpp b/chaos/src/hydrogen.hpp index 6df6088..cec6ae3 100644 --- a/chaos/src/hydrogen.hpp +++ b/chaos/src/hydrogen.hpp @@ -24,13 +24,12 @@ // hydrogen atom in a magnetic field class hydrogen - : public ode_base + : public ode_base<4> { public: - hydrogen(): - ode_base(4) + hydrogen() { CHAOS_PAR_INIT(method,2); CHAOS_PAR_INIT(dt,0.01); @@ -45,9 +44,6 @@ public: reset = 0; } - ~hydrogen() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 3c4d587..60e3a77 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -32,11 +32,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class ikeda_laser_map: - public map_base + public map_base<1> { public: - ikeda_laser_map(): - map_base(1) + ikeda_laser_map() { CHAOS_PAR_INIT(c1,0.4); CHAOS_PAR_INIT(c2,0.9); @@ -47,10 +46,6 @@ public: CHAOS_SYS_INIT(y,0.5,1); } - ~ikeda_laser_map() - { - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index eec6116..47abc33 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -28,11 +28,10 @@ // taken from Pickover: Chaos In Wonderland class latoocarfian - : public map_base + : public map_base<2> { public: - latoocarfian(): - map_base(2) + latoocarfian() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0,1); @@ -42,10 +41,6 @@ public: CHAOS_PAR_INIT(c,0.765145); CHAOS_PAR_INIT(d,0.744728); } - - ~latoocarfian() - { - } virtual void m_step() { diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index ac4f28d..255829a 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutalpha - : public map_base + : public map_base<2> { public: - latoomutalpha(): - map_base(2) + latoomutalpha() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.2,1); @@ -41,10 +40,6 @@ public: CHAOS_PAR_INIT(c,0.765145); } - ~latoomutalpha() - { - - } virtual void m_step() { diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index 3a048cd..d663761 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutbeta - : public map_base + : public map_base<2> { public: - latoomutbeta(): - map_base(2) + latoomutbeta() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); @@ -40,11 +39,6 @@ public: CHAOS_PAR_INIT(b,2.879879); } - ~latoomutbeta() - { - - } - virtual void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 5e55225..022e651 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -27,11 +27,10 @@ // taken from Pickover: Chaos In Wonderland class latoomutgamma - : public map_base + : public map_base<2> { public: - latoomutgamma(): - map_base(2) + latoomutgamma() { CHAOS_SYS_INIT(x1,0.5,0); CHAOS_SYS_INIT(x2,0.5,1); @@ -39,11 +38,6 @@ public: CHAOS_PAR_INIT(a,-0.966918); CHAOS_PAR_INIT(b,2.879879); } - - ~latoomutgamma() - { - - } virtual void m_step() { @@ -59,7 +53,7 @@ public: /* function has a fix point for x1 == x2 == 0 */ - virtual void m_verify() + void m_verify() { if (m_data[0] == 0 && m_data[1] == 0) for (int i = 0; i != 2; ++i) diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index bc3536a..f6ce961 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -25,11 +25,10 @@ // taken from Julien C. Sprott, Chaos and Time-Series Analysis class linear_congruental: - public map_base + public map_base<2> { public: - linear_congruental(): - map_base(1) + linear_congruental() { CHAOS_SYS_INIT(x, 0, 0); diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 3e0ef24..7880d21 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -25,11 +25,10 @@ // 0 <= alpha <= 4 class logistic: - public map_base + public map_base<1> { public: - logistic(): - map_base(1) + logistic() { CHAOS_PAR_INIT(alpha, 3.8); CHAOS_SYS_INIT(x, 0.5,0); diff --git a/chaos/src/lorenz.hpp b/chaos/src/lorenz.hpp index b27f954..cf0fa14 100644 --- a/chaos/src/lorenz.hpp +++ b/chaos/src/lorenz.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lorenz - : public ode_base + : public ode_base<3> { public: - lorenz(): - ode_base(3) + lorenz() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.01); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index dee6b0d..24096a6 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -26,11 +26,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class lozi_map: - public map_base + public map_base<2> { public: - lozi_map(): - map_base(2) + lozi_map() { CHAOS_SYS_INIT(x,0,0); CHAOS_SYS_INIT(y,0,1); @@ -39,11 +38,6 @@ public: CHAOS_PAR_INIT(b,0.3); } - ~lozi_map() - { - - } - virtual void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 1395bb8..92016b1 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -23,26 +23,18 @@ #include "chaos_base.hpp" +template class map_base - : public chaos_base + : public chaos_base { protected: - map_base(int n): - chaos_base(n) - { - } - virtual void m_step() { } }; -#define MAP_CALLBACKS \ -CHAOS_CALLBACKS - - -#define MAP_ATTRIBUTES \ -CHAOS_ATTRIBUTES; +#define MAP_CALLBACKS +#define MAP_ATTRIBUTES #define __map_base_hpp #endif /* __map_base_hpp */ diff --git a/chaos/src/ode_base.cpp b/chaos/src/ode_base.cpp index 2830c2f..004a1b3 100644 --- a/chaos/src/ode_base.cpp +++ b/chaos/src/ode_base.cpp @@ -20,55 +20,4 @@ #include "ode_base.hpp" -void ode_base::rk1() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += m_dt * m_k[0][i]; -} - - -void ode_base::rk2() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - m_k[0][i] = m_k[0][i] * 0.5 * m_dt + m_data[i]; - - m_system (m_k[1], m_k[0]); - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += m_dt * m_k[1][i]; -} - - -void ode_base::rk4() -{ - m_system (m_k[0], m_data); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[0][i] *= m_dt; - m_tmp[i] = m_data[i] + 0.5 * m_k[0][i]; - } - - m_system (m_k[1], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[1][i] *= m_dt; - m_tmp[i] = m_data[i] + 0.5 * m_k[1][i]; - } - - m_system (m_k[2], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - { - m_k[2][i] *= m_dt; - m_tmp[i] = m_data[i] + m_k[2][i]; - } - - m_system (m_k[3], m_tmp); - for (int i = 0; i != m_num_eq; ++i) - m_k[3][i] *= m_dt; - - for (int i = 0; i != m_num_eq; ++i) - m_data[i] += (m_k[0][i] + 2. * (m_k[1][i] + m_k[2][i]) + m_k[3][i]) - / 6.; -} diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index 11811f7..b198dc5 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -23,45 +23,27 @@ #include "chaos_base.hpp" -class ode_base - : public chaos_base +template +class ode_base: + public chaos_base { public: - ode_base(int n): - chaos_base (n) - { - for (int i = 0; i != 3; ++i) - { - m_k[i] = new data_t[n]; - } - m_tmp = new data_t[n]; - - } - ~ode_base() - { - for (int i = 0; i != 3; ++i) - { - delete[] m_k[i]; - } - delete[] m_tmp; - } - void set_method(int i) { - if (i >=0 && i <4) + if (i >= 0 && i < 4) { m_method = (unsigned char) i; switch (i) { case 0: - m_routine = &ode_base::rk1; + m_routine = &ode_base::rk1; break; case 1: - m_routine = &ode_base::rk2; + m_routine = &ode_base::rk2; break; case 2: - m_routine = &ode_base::rk4; + m_routine = &ode_base::rk4; } } else @@ -86,27 +68,75 @@ public: } protected: - void (ode_base::*m_routine)(void); + void (ode_base::*m_routine)(void); unsigned char m_method; /* 0: rk1, 1: rk2, 3: rk4 */ - data_t* m_k[3]; /* temporary arrays for runge kutta */ - data_t* m_tmp; + data_t m_k0[dimensions]; + data_t m_k1[dimensions]; + data_t m_k2[dimensions]; + data_t m_k3[dimensions]; + data_t m_tmp[dimensions]; +// data_t m_tmp[dimensions]; virtual void m_system (data_t* deriv, data_t* data) = 0; - void rk1 (); - void rk2 (); - void rk4 (); + void rk1() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += m_dt * m_k0[i]; + } + + void rk2() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// m_k0[i] = m_k0[i] * 0.5 * m_dt + m_data[i]; +// +// m_system (m_k1, m_k0); +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += m_dt * m_k1[i]; + } + + void rk4() + { +// m_system (m_k0, m_data); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k0[i] *= m_dt; +// m_tmp[i] = m_data[i] + 0.5 * m_k0[i]; +// } +// +// m_system (m_k1, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k1[i] *= m_dt; +// m_tmp[i] = m_data[i] + 0.5 * m_k1[i]; +// } +// +// m_system (m_k2, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// { +// m_k2[i] *= m_dt; +// m_tmp[i] = m_data[i] + m_k2[i]; +// } +// +// m_system (m_k3, m_tmp); +// for (int i = 0; i != dimensions; ++i) +// m_k3[i] *= m_dt; +// +// for (int i = 0; i != dimensions; ++i) +// m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) +// / 6.; + } }; #define ODE_CALLBACKS \ -CHAOS_CALLBACKS; \ CHAOS_SYS_CALLBACKS_I(method); \ CHAOS_SYS_CALLBACKS(dt); #define ODE_ATTRIBUTES \ -CHAOS_ATTRIBUTES; \ CHAOS_SYS_ATTRIBUTE(method); \ CHAOS_SYS_ATTRIBUTE(dt); diff --git a/chaos/src/roessler.hpp b/chaos/src/roessler.hpp index fd65d4e..aa03a47 100644 --- a/chaos/src/roessler.hpp +++ b/chaos/src/roessler.hpp @@ -23,14 +23,13 @@ // roessler model: dx1/dt = - (x2 + x3) // dx2/dt = x1 + a * x2 // dx3/dt = b + (x1 - c) * x3 -// taken from Peitgen / Jürgens / Saupe: Chaos and Fractals +// taken from Peitgen / J�rgens / Saupe: Chaos and Fractals class roessler - : public ode_base + : public ode_base<3> { public: - roessler(): - ode_base(3) + roessler() { CHAOS_PAR_INIT(method,0); CHAOS_PAR_INIT(dt,0.001); @@ -44,9 +43,6 @@ public: CHAOS_PAR_INIT(c,4); } - ~roessler() - { - } virtual void m_system(data_t* deriv, data_t* data) { diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 3d69065..8a11281 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -26,12 +26,11 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class sine_map: - public map_base + public map_base<1> { public: - sine_map(): - map_base(1) + sine_map() { CHAOS_SYS_INIT(x,0,0); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 4df1eb9..8798edc 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -27,11 +27,10 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class standard_map: - public map_base + public map_base<2> { public: - standard_map(): - map_base(2) + standard_map() { CHAOS_SYS_INIT(I,0.1,0); CHAOS_SYS_INIT(theta,0.2,1); diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 9bd8e62..2e716ac 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -26,19 +26,14 @@ class tent_map: - public map_base + public map_base<1> { public: - tent_map(): - map_base(1) + tent_map() { CHAOS_SYS_INIT(x, 0.6,0); } - ~tent_map() - { - - } virtual void m_step() { -- cgit v1.2.1 From 2c157bd8aa1f5387169cc0c0910d36c8068c4068 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Sun, 21 May 2006 19:17:04 +0000 Subject: improved inlining for maps svn path=/trunk/externals/tb/; revision=5106 --- chaos/src/bernoulli_map.hpp | 2 +- chaos/src/bungalow_tent_map.hpp | 2 +- chaos/src/chaos_base.hpp | 14 +++++++------- chaos/src/chaos_dsp.hpp | 36 +++++++++++++++++++++++++++++------- chaos/src/chaos_msg.hpp | 6 +++++- chaos/src/chaos_search.hpp | 9 ++++++--- chaos/src/circle_map.hpp | 2 +- chaos/src/delayed_logistic.hpp | 2 +- chaos/src/duffing_map.hpp | 2 +- chaos/src/gauss_map.hpp | 2 +- chaos/src/gaussian_map.hpp | 2 +- chaos/src/henon_map.hpp | 2 +- chaos/src/ikeda_laser_map.hpp | 2 +- chaos/src/latoocarfian.hpp | 2 +- chaos/src/latoomutalpha.hpp | 2 +- chaos/src/latoomutbeta.hpp | 2 +- chaos/src/latoomutgamma.hpp | 2 +- chaos/src/linear_congruental.hpp | 2 +- chaos/src/logistic_map.hpp | 2 +- chaos/src/lozi_map.hpp | 2 +- chaos/src/map_base.hpp | 2 +- chaos/src/ode_base.hpp | 2 +- chaos/src/sine_map.hpp | 2 +- chaos/src/standard_map.hpp | 2 +- chaos/src/tent_map.hpp | 2 +- 25 files changed, 68 insertions(+), 39 deletions(-) diff --git a/chaos/src/bernoulli_map.hpp b/chaos/src/bernoulli_map.hpp index c720e1b..781011b 100644 --- a/chaos/src/bernoulli_map.hpp +++ b/chaos/src/bernoulli_map.hpp @@ -34,7 +34,7 @@ public: CHAOS_SYS_INIT(x,0.5,0); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/bungalow_tent_map.hpp b/chaos/src/bungalow_tent_map.hpp index fd098f3..492b6d5 100644 --- a/chaos/src/bungalow_tent_map.hpp +++ b/chaos/src/bungalow_tent_map.hpp @@ -42,7 +42,7 @@ public: CHAOS_PAR_INIT(r, 0.5); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t r = CHAOS_PARAMETER(r); diff --git a/chaos/src/chaos_base.hpp b/chaos/src/chaos_base.hpp index 4b984d9..d18a507 100644 --- a/chaos/src/chaos_base.hpp +++ b/chaos/src/chaos_base.hpp @@ -42,12 +42,12 @@ public: return dimensions; } - inline void m_perform() - { - m_step(); - m_bash_denormals(); - m_verify(); - } +// inline void m_perform() +// { +// m_step(); +// m_bash_denormals(); +// m_verify(); +// } std::map attr_ind; @@ -70,7 +70,7 @@ public: data_t m_data[dimensions]; // state of the system protected: - virtual void m_step() = 0; // iteration +// void m_step() = 0; // iteration flext::AtomList Parameter; // parameter flext::AtomList System; // system }; diff --git a/chaos/src/chaos_dsp.hpp b/chaos/src/chaos_dsp.hpp index 9f6dd75..6ca9ce4 100644 --- a/chaos/src/chaos_dsp.hpp +++ b/chaos/src/chaos_dsp.hpp @@ -257,7 +257,10 @@ void chaos_dsp::m_signal_(int n, t_sample *const *insigs, for (int i = 0; i!=n; ++i) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + for (int j = 0; j != outlets; ++j) { outsigs[j][i] = m_system.get_data(j); @@ -279,7 +282,10 @@ void chaos_dsp::m_signal_n_hf(int n, t_sample *const *insigs, { while (phase <= 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase += m_sr * m_invfreq; } int next = (phase < n) ? int(ceilf (phase)) : n; @@ -309,7 +315,10 @@ void chaos_dsp::m_signal_n(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = int (m_sr * m_invfreq); } @@ -341,7 +350,10 @@ void chaos_dsp::m_signal_l(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = int (m_sr * m_invfreq); for (int j = 0; j != outlets; ++j) @@ -381,7 +393,10 @@ void chaos_dsp::m_signal_l_hf(int n, t_sample *const *insigs, { if (phase <= 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = m_sr * m_invfreq; for (int j = 0; j != outlets; ++j) @@ -420,7 +435,10 @@ void chaos_dsp::m_signal_c(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; @@ -472,7 +490,11 @@ void chaos_dsp::m_signal_c_hf(int n, t_sample *const *insigs, { if (phase == 0) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + + phase = int (m_sr * m_invfreq); phase = (phase > 2) ? phase : 2; diff --git a/chaos/src/chaos_msg.hpp b/chaos/src/chaos_msg.hpp index 9025273..915d6a1 100644 --- a/chaos/src/chaos_msg.hpp +++ b/chaos/src/chaos_msg.hpp @@ -42,7 +42,11 @@ public: void m_bang() { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); + + int outlets = m_system.get_num_eq(); while (outlets--) diff --git a/chaos/src/chaos_search.hpp b/chaos/src/chaos_search.hpp index 1b812a0..fded6bc 100644 --- a/chaos/src/chaos_search.hpp +++ b/chaos/src/chaos_search.hpp @@ -137,7 +137,9 @@ void chaos_search::m_search() /* transient dynamics */ for (int i = 0; i != m_transient_steps; ++i) { - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); } for (int i = 0; i != dimensions; ++i) @@ -149,8 +151,9 @@ void chaos_search::m_search() for (int i = 0; i != m_asymptotic_steps; ++i) { - - m_system.m_perform(); + m_system.m_step(); + m_system.m_bash_denormals(); + m_system.m_verify(); data_t diff = 0; for (int j = 0; j != dimensions; ++j) diff --git a/chaos/src/circle_map.hpp b/chaos/src/circle_map.hpp index 294b7d6..c58391a 100644 --- a/chaos/src/circle_map.hpp +++ b/chaos/src/circle_map.hpp @@ -39,7 +39,7 @@ public: } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t omega = CHAOS_PARAMETER(omega); diff --git a/chaos/src/delayed_logistic.hpp b/chaos/src/delayed_logistic.hpp index 3db7e27..d7f7539 100644 --- a/chaos/src/delayed_logistic.hpp +++ b/chaos/src/delayed_logistic.hpp @@ -39,7 +39,7 @@ public: - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t alpha = CHAOS_PARAMETER(alpha); diff --git a/chaos/src/duffing_map.hpp b/chaos/src/duffing_map.hpp index 46fecbf..2670b7d 100644 --- a/chaos/src/duffing_map.hpp +++ b/chaos/src/duffing_map.hpp @@ -39,7 +39,7 @@ public: - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; diff --git a/chaos/src/gauss_map.hpp b/chaos/src/gauss_map.hpp index d013bae..7e16bea 100644 --- a/chaos/src/gauss_map.hpp +++ b/chaos/src/gauss_map.hpp @@ -37,7 +37,7 @@ public: } - virtual void m_step() + void m_step() { data_t data = m_data[0]; diff --git a/chaos/src/gaussian_map.hpp b/chaos/src/gaussian_map.hpp index c6aaf1e..7793814 100644 --- a/chaos/src/gaussian_map.hpp +++ b/chaos/src/gaussian_map.hpp @@ -39,7 +39,7 @@ public: - virtual void m_step() + void m_step() { data_t data = m_data[0]; diff --git a/chaos/src/henon_map.hpp b/chaos/src/henon_map.hpp index 014fa68..b7ca5bf 100644 --- a/chaos/src/henon_map.hpp +++ b/chaos/src/henon_map.hpp @@ -39,7 +39,7 @@ public: } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; diff --git a/chaos/src/ikeda_laser_map.hpp b/chaos/src/ikeda_laser_map.hpp index 60e3a77..534a9de 100644 --- a/chaos/src/ikeda_laser_map.hpp +++ b/chaos/src/ikeda_laser_map.hpp @@ -46,7 +46,7 @@ public: CHAOS_SYS_INIT(y,0.5,1); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; diff --git a/chaos/src/latoocarfian.hpp b/chaos/src/latoocarfian.hpp index 47abc33..1329bd3 100644 --- a/chaos/src/latoocarfian.hpp +++ b/chaos/src/latoocarfian.hpp @@ -42,7 +42,7 @@ public: CHAOS_PAR_INIT(d,0.744728); } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), diff --git a/chaos/src/latoomutalpha.hpp b/chaos/src/latoomutalpha.hpp index 255829a..bfe76e4 100644 --- a/chaos/src/latoomutalpha.hpp +++ b/chaos/src/latoomutalpha.hpp @@ -41,7 +41,7 @@ public: } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b), diff --git a/chaos/src/latoomutbeta.hpp b/chaos/src/latoomutbeta.hpp index d663761..c1a42b5 100644 --- a/chaos/src/latoomutbeta.hpp +++ b/chaos/src/latoomutbeta.hpp @@ -39,7 +39,7 @@ public: CHAOS_PAR_INIT(b,2.879879); } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 022e651..0120745 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -39,7 +39,7 @@ public: CHAOS_PAR_INIT(b,2.879879); } - virtual void m_step() + void m_step() { data_t x1 = m_data[0], x2 = m_data[1]; data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index f6ce961..25bc837 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -37,7 +37,7 @@ public: CHAOS_PAR_INIT(C, 259200); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; diff --git a/chaos/src/logistic_map.hpp b/chaos/src/logistic_map.hpp index 7880d21..2d19855 100644 --- a/chaos/src/logistic_map.hpp +++ b/chaos/src/logistic_map.hpp @@ -38,7 +38,7 @@ public: { } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t alpha = CHAOS_PARAMETER(alpha); diff --git a/chaos/src/lozi_map.hpp b/chaos/src/lozi_map.hpp index 24096a6..07656d2 100644 --- a/chaos/src/lozi_map.hpp +++ b/chaos/src/lozi_map.hpp @@ -38,7 +38,7 @@ public: CHAOS_PAR_INIT(b,0.3); } - virtual void m_step() + void m_step() { data_t x = m_data[0]; data_t y = m_data[1]; diff --git a/chaos/src/map_base.hpp b/chaos/src/map_base.hpp index 92016b1..afc89fb 100644 --- a/chaos/src/map_base.hpp +++ b/chaos/src/map_base.hpp @@ -28,7 +28,7 @@ class map_base : public chaos_base { protected: - virtual void m_step() + void m_step() { } }; diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index b198dc5..f46332c 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -62,7 +62,7 @@ public: return (f >= 0); } - virtual void m_step() + void m_step() { (this->*m_routine)(); } diff --git a/chaos/src/sine_map.hpp b/chaos/src/sine_map.hpp index 8a11281..d7043f4 100644 --- a/chaos/src/sine_map.hpp +++ b/chaos/src/sine_map.hpp @@ -40,7 +40,7 @@ public: } - virtual void m_step() + void m_step() { m_data[0] = sin (M_PI * m_data[0]); } diff --git a/chaos/src/standard_map.hpp b/chaos/src/standard_map.hpp index 8798edc..399484b 100644 --- a/chaos/src/standard_map.hpp +++ b/chaos/src/standard_map.hpp @@ -43,7 +43,7 @@ public: } - virtual void m_step() + void m_step() { data_t I = m_data[0]; data_t theta = m_data[1]; diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index 2e716ac..f8f2c29 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -35,7 +35,7 @@ public: } - virtual void m_step() + void m_step() { data_t data = m_data[0]; -- cgit v1.2.1 From 47603a7ffe9d354ef5a2af7981504527a9e742da Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Thu, 10 Aug 2006 21:23:33 +0000 Subject: max/msp fix (thanks to thomas for mentioning this) svn path=/trunk/externals/tb/; revision=5551 --- chaos/src/chaos.hpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index bb9971d..971d503 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -30,6 +30,11 @@ #include +#if FLEXT_SYS != FLEXT_SYS_PD +#define PD_BIGORSMALL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \ + (((*(unsigned int*)&(f))&0x60000000)==0x60000000)) +#endif + /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; @@ -42,15 +47,15 @@ typedef float data_t; inline data_t chaos_mod(data_t x, data_t y) { #ifdef DOUBLE_PRECISION - return fmod(x,y); + return fmod(x,y); #else - return fmodf(x,y); + return fmodf(x,y); #endif } inline data_t rand_range(data_t low, data_t high) { - return low + ( (rand() * (high - low)) / RAND_MAX); + return low + ( (rand() * (high - low)) / RAND_MAX); } -- cgit v1.2.1 From fae4d2ec359b596a775973956daf4636856f0141 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 6 Sep 2006 20:32:21 +0000 Subject: cleanups svn path=/trunk/externals/tb/; revision=5880 --- chaos/src/chaos.hpp | 13 -- chaos/src/chua.hpp | 262 +++++++++++++++++++-------------------- chaos/src/driven_van_der_pol.hpp | 108 ++++++++-------- chaos/src/duffing.hpp | 124 +++++++++--------- chaos/src/latoomutgamma.hpp | 94 +++++++------- chaos/src/linear_congruental.hpp | 66 +++++----- chaos/src/ode_base.hpp | 79 ++++++------ chaos/src/tent_map.hpp | 58 ++++----- 8 files changed, 395 insertions(+), 409 deletions(-) diff --git a/chaos/src/chaos.hpp b/chaos/src/chaos.hpp index 971d503..259f56e 100644 --- a/chaos/src/chaos.hpp +++ b/chaos/src/chaos.hpp @@ -38,27 +38,14 @@ /* internal we can work with a higher precision than pd */ #ifdef DOUBLE_PRECISION typedef double data_t; -#define CHAOS_ABS(x) fabs(x) #else typedef float data_t; -#define CHAOS_ABS(x) fabsf(x) #endif -inline data_t chaos_mod(data_t x, data_t y) -{ -#ifdef DOUBLE_PRECISION - return fmod(x,y); -#else - return fmodf(x,y); -#endif -} - inline data_t rand_range(data_t low, data_t high) { return low + ( (rand() * (high - low)) / RAND_MAX); } - - #define __chaos_hpp #endif /* __chaos_hpp */ diff --git a/chaos/src/chua.hpp b/chaos/src/chua.hpp index f8c6e31..7669a24 100644 --- a/chaos/src/chua.hpp +++ b/chaos/src/chua.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -23,143 +23,143 @@ // chua system: dx1/dt = alpha * (x2 - x1 - h(x1)) // dx2/dt = x1 - x2 + x3 // dx3/dt = - beta * x2 -// +// // with h(x) = b*x + a - b (for x > 1) // a*x (for -1 <= x <= 1 // b*x - a + b (for x < -1) -// +// // taken from Viktor Avrutin: lecture notes class chua: - public ode_base<3> + public ode_base<3> { public: - chua() - { - CHAOS_PAR_INIT(method,2); - CHAOS_PAR_INIT(dt,0.05); - - CHAOS_SYS_INIT(x1,1,1); - CHAOS_SYS_INIT(x2,1,1); - CHAOS_SYS_INIT(x3,1,1); - - CHAOS_PAR_INIT(a,140); - CHAOS_PAR_INIT(b,30); - CHAOS_PAR_INIT(alpha,30); - CHAOS_PAR_INIT(beta,30); - } - - virtual void m_system(data_t* deriv, data_t* data) - { - data_t x1 = data[0]; - data_t x2 = data[1]; - data_t x3 = data[2]; - - data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); - - data_t h; - - if (x1 > 1) - h = b*x1 + a - b; - else if (x1 < -1) - h = b*x1 - a + b; - else - h = a*x1; - - deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h); - deriv[1] = x1 - x2 + x3; - deriv[2] = - CHAOS_PARAMETER(beta) * x2; - } - - virtual void m_verify() - { - data_t x1 = m_data[0]; - data_t x2 = m_data[1]; - data_t x3 = m_data[2]; - - if ( CHAOS_ABS(x3) < 1e-10) - x3 = 0; - - if (x1 == 0 && x2 == 0 && x3 == 0) /* fixpoint at (0,0,0) */ - { - reset(); - return; - } - else - { - data_t c = m_c; - if (m_c) - { - data_t mc = - c; - if (x1 == c && x3 == mc) /* fixpoint at (c,0,-c) */ - { - reset(); - return; - } - if (x1 == mc && x3 == c) /* fixpoint at (-c,0,c) */ - { - reset(); - return; - } - } - } - } - - inline void reset() - { - m_data[0] = rand_range(-1,1); - m_data[1] = rand_range(-1,1); - m_data[2] = rand_range(-1,1); - } - - CHAOS_SYSVAR_FUNCS(x1, 0); - CHAOS_SYSVAR_FUNCS(x2, 1); - CHAOS_SYSVAR_FUNCS(x3, 2); - - /* due to stability issues, we hook into the predicates */ - data_t m_c; - bool m_pred_a(data_t a) - { - data_t b = CHAOS_PARAMETER(b); - m_c = (b - a) / (b + 1); - return true; - } - - bool m_pred_b(data_t b) - { - if (b == -1) - m_c = 0; - else - { - data_t a = CHAOS_PARAMETER(a); - m_c = (b - a) / (b + 1); - } - return true; - } - - CHAOS_SYSPAR_FUNCS_PRED(a, m_pred_a); - CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); - CHAOS_SYSPAR_FUNCS(alpha); - CHAOS_SYSPAR_FUNCS(beta); + chua() + { + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.05); + + CHAOS_SYS_INIT(x1,1,1); + CHAOS_SYS_INIT(x2,1,1); + CHAOS_SYS_INIT(x3,1,1); + + CHAOS_PAR_INIT(a,140); + CHAOS_PAR_INIT(b,30); + CHAOS_PAR_INIT(alpha,30); + CHAOS_PAR_INIT(beta,30); + } + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x1 = data[0]; + data_t x2 = data[1]; + data_t x3 = data[2]; + + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + + data_t h; + + if (x1 > 1) + h = b*x1 + a - b; + else if (x1 < -1) + h = b*x1 - a + b; + else + h = a*x1; + + deriv[0] = CHAOS_PARAMETER(alpha) * (x2 - x1 - h); + deriv[1] = x1 - x2 + x3; + deriv[2] = - CHAOS_PARAMETER(beta) * x2; + } + + virtual void m_verify() + { + data_t x1 = m_data[0]; + data_t x2 = m_data[1]; + data_t x3 = m_data[2]; + + if ( std::abs(x3) < 1e-10) + x3 = 0; + + if (x1 == 0 && x2 == 0 && x3 == 0) /* fixpoint at (0,0,0) */ + { + reset(); + return; + } + else + { + data_t c = m_c; + if (m_c) + { + data_t mc = - c; + if (x1 == c && x3 == mc) /* fixpoint at (c,0,-c) */ + { + reset(); + return; + } + if (x1 == mc && x3 == c) /* fixpoint at (-c,0,c) */ + { + reset(); + return; + } + } + } + } + + inline void reset() + { + m_data[0] = rand_range(-1,1); + m_data[1] = rand_range(-1,1); + m_data[2] = rand_range(-1,1); + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + CHAOS_SYSVAR_FUNCS(x3, 2); + + /* due to stability issues, we hook into the predicates */ + data_t m_c; + bool m_pred_a(data_t a) + { + data_t b = CHAOS_PARAMETER(b); + m_c = (b - a) / (b + 1); + return true; + } + + bool m_pred_b(data_t b) + { + if (b == -1) + m_c = 0; + else + { + data_t a = CHAOS_PARAMETER(a); + m_c = (b - a) / (b + 1); + } + return true; + } + + CHAOS_SYSPAR_FUNCS_PRED(a, m_pred_a); + CHAOS_SYSPAR_FUNCS_PRED(b, m_pred_b); + CHAOS_SYSPAR_FUNCS(alpha); + CHAOS_SYSPAR_FUNCS(beta); }; -#define CHUA_CALLBACKS \ -ODE_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(alpha); \ -CHAOS_SYS_CALLBACKS(beta); \ -CHAOS_SYS_CALLBACKS(a); \ -CHAOS_SYS_CALLBACKS(b); \ -CHAOS_SYS_CALLBACKS(x1); \ -CHAOS_SYS_CALLBACKS(x2); \ +#define CHUA_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(alpha); \ +CHAOS_SYS_CALLBACKS(beta); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(b); \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ CHAOS_SYS_CALLBACKS(x3); -#define CHUA_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(a); \ -CHAOS_SYS_ATTRIBUTE(b); \ -CHAOS_SYS_ATTRIBUTE(alpha); \ -CHAOS_SYS_ATTRIBUTE(beta); \ -CHAOS_SYS_ATTRIBUTE(x1); \ -CHAOS_SYS_ATTRIBUTE(x2); \ +#define CHUA_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(b); \ +CHAOS_SYS_ATTRIBUTE(alpha); \ +CHAOS_SYS_ATTRIBUTE(beta); \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ CHAOS_SYS_ATTRIBUTE(x3); diff --git a/chaos/src/driven_van_der_pol.hpp b/chaos/src/driven_van_der_pol.hpp index 3c034d2..31c2e2d 100644 --- a/chaos/src/driven_van_der_pol.hpp +++ b/chaos/src/driven_van_der_pol.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -30,66 +30,66 @@ // taken from Willi-Hans Steeb: Chaos and Fractals class driven_van_der_pol - : public ode_base<3> + : public ode_base<3> { public: - driven_van_der_pol() - { - CHAOS_PAR_INIT(method,2); - CHAOS_PAR_INIT(dt,0.01); + driven_van_der_pol() + { + CHAOS_PAR_INIT(method,2); + CHAOS_PAR_INIT(dt,0.01); - CHAOS_SYS_INIT(u1,0.8, 0); - CHAOS_SYS_INIT(u2,0.6, 1); - CHAOS_SYS_INIT(u3,0.4, 2); + CHAOS_SYS_INIT(u1,0.8, 0); + CHAOS_SYS_INIT(u2,0.6, 1); + CHAOS_SYS_INIT(u3,0.4, 2); - CHAOS_PAR_INIT(a,5); - CHAOS_PAR_INIT(Omega,2.466); - CHAOS_PAR_INIT(k,5); - } - + CHAOS_PAR_INIT(a,5); + CHAOS_PAR_INIT(Omega,2.466); + CHAOS_PAR_INIT(k,5); + } - virtual void m_system(data_t* deriv, data_t* data) - { - data_t u1 = data[0], u2 = data[1], u3 = data[2]; - - deriv[0] = u2; - deriv[1] = - CHAOS_PARAMETER(a) * (u1*u1 -1) * u2 - u1 + - CHAOS_PARAMETER(k)*cos(u3); - deriv[2] = CHAOS_PARAMETER(Omega); - } - - virtual void m_verify() - { - /* make sure to stay in the range of 2 pi */ - if (m_data[2] > 2*M_PI) - m_data[2] = chaos_mod(m_data[2], 2*M_PI); - } - CHAOS_SYSVAR_FUNCS(u1, 0); - CHAOS_SYSVAR_FUNCS(u2, 1); - CHAOS_SYSVAR_FUNCS(u3, 2); + void m_system(data_t* deriv, data_t* data) + { + data_t u1 = data[0], u2 = data[1], u3 = data[2]; - CHAOS_SYSPAR_FUNCS(a); - CHAOS_SYSPAR_FUNCS(k); - CHAOS_SYSPAR_FUNCS(Omega); + deriv[0] = u2; + deriv[1] = - CHAOS_PARAMETER(a) * (u1*u1 -1) * u2 - u1 + + CHAOS_PARAMETER(k)*cos(u3); + deriv[2] = CHAOS_PARAMETER(Omega); + } + + void m_verify() + { + /* make sure to stay in the range of 2 pi */ + if (m_data[2] > 2*M_PI) + m_data[2] = std::fmod(m_data[2], data_t(2*M_PI)); + } + + CHAOS_SYSVAR_FUNCS(u1, 0); + CHAOS_SYSVAR_FUNCS(u2, 1); + CHAOS_SYSVAR_FUNCS(u3, 2); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(k); + CHAOS_SYSPAR_FUNCS(Omega); }; -#define DRIVEN_VAN_DER_POL_CALLBACKS \ -ODE_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(u1); \ -CHAOS_SYS_CALLBACKS(u2); \ -CHAOS_SYS_CALLBACKS(u3); \ -CHAOS_SYS_CALLBACKS(a); \ -CHAOS_SYS_CALLBACKS(k); \ +#define DRIVEN_VAN_DER_POL_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(u1); \ +CHAOS_SYS_CALLBACKS(u2); \ +CHAOS_SYS_CALLBACKS(u3); \ +CHAOS_SYS_CALLBACKS(a); \ +CHAOS_SYS_CALLBACKS(k); \ CHAOS_SYS_CALLBACKS(Omega); -#define DRIVEN_VAN_DER_POL_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(u1); \ -CHAOS_SYS_ATTRIBUTE(u2); \ -CHAOS_SYS_ATTRIBUTE(u3); \ -CHAOS_SYS_ATTRIBUTE(a); \ -CHAOS_SYS_ATTRIBUTE(k); \ +#define DRIVEN_VAN_DER_POL_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(u1); \ +CHAOS_SYS_ATTRIBUTE(u2); \ +CHAOS_SYS_ATTRIBUTE(u3); \ +CHAOS_SYS_ATTRIBUTE(a); \ +CHAOS_SYS_ATTRIBUTE(k); \ CHAOS_SYS_ATTRIBUTE(Omega); diff --git a/chaos/src/duffing.hpp b/chaos/src/duffing.hpp index ee7f7fb..b5d931c 100644 --- a/chaos/src/duffing.hpp +++ b/chaos/src/duffing.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2005 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -22,73 +22,73 @@ // duffing equation: dx/dt = y // dy/dt = x * (1 - x^2) + R*cos(omega * t) - gamma * y -// +// class duffing: - public ode_base<2> + public ode_base<2> { public: - duffing() - { - CHAOS_PAR_INIT(method,0); - CHAOS_PAR_INIT(dt,0.01); - - CHAOS_SYS_INIT(x, 0.5, 0); - CHAOS_SYS_INIT(y, 0.5, 1); - - CHAOS_PAR_INIT(R, 0.4); - CHAOS_PAR_INIT(omega, 1); - CHAOS_PAR_INIT(gamma, 0.25); - - t = 0; - } - - - virtual void m_system(data_t* deriv, data_t* data) - { - data_t x = data[0], y = data[1]; - - deriv[0] = y; - deriv[1] = x * (1 - x*x) + - CHAOS_PARAMETER(R) * cos( CHAOS_PARAMETER(omega) * t) - - CHAOS_PARAMETER(gamma) * y; - t += CHAOS_PARAMETER(dt); - t = chaos_mod(t, M_PI); - } - - virtual void m_verify() - { - if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) - for (int i = 0; i != 3; ++i) - m_data[i] = rand_range(0,3); - } - - - CHAOS_SYSVAR_FUNCS(x,0); - CHAOS_SYSVAR_FUNCS(y,1); - - CHAOS_SYSPAR_FUNCS(R); - CHAOS_SYSPAR_FUNCS(omega); - CHAOS_SYSPAR_FUNCS(gamma); + duffing() + { + CHAOS_PAR_INIT(method,0); + CHAOS_PAR_INIT(dt,0.01); + + CHAOS_SYS_INIT(x, 0.5, 0); + CHAOS_SYS_INIT(y, 0.5, 1); + + CHAOS_PAR_INIT(R, 0.4); + CHAOS_PAR_INIT(omega, 1); + CHAOS_PAR_INIT(gamma, 0.25); + + t = 0; + } + + + virtual void m_system(data_t* deriv, data_t* data) + { + data_t x = data[0], y = data[1]; + + deriv[0] = y; + deriv[1] = x * (1 - x*x) + + CHAOS_PARAMETER(R) * cos( CHAOS_PARAMETER(omega) * t) - + CHAOS_PARAMETER(gamma) * y; + t += CHAOS_PARAMETER(dt); + t = std::fmod(t, data_t(M_PI)); + } + + virtual void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0) + for (int i = 0; i != 3; ++i) + m_data[i] = rand_range(0,3); + } + + + CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSVAR_FUNCS(y,1); + + CHAOS_SYSPAR_FUNCS(R); + CHAOS_SYSPAR_FUNCS(omega); + CHAOS_SYSPAR_FUNCS(gamma); private: - data_t t; + data_t t; }; -#define DUFFING_CALLBACKS \ -ODE_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(x); \ -CHAOS_SYS_CALLBACKS(y); \ -CHAOS_SYS_CALLBACKS(R); \ -CHAOS_SYS_CALLBACKS(gamma); \ +#define DUFFING_CALLBACKS \ +ODE_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x); \ +CHAOS_SYS_CALLBACKS(y); \ +CHAOS_SYS_CALLBACKS(R); \ +CHAOS_SYS_CALLBACKS(gamma); \ CHAOS_SYS_CALLBACKS(omega); -#define DUFFING_ATTRIBUTES \ -ODE_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(x); \ -CHAOS_SYS_ATTRIBUTE(y); \ -CHAOS_SYS_ATTRIBUTE(R); \ -CHAOS_SYS_ATTRIBUTE(gamma); \ +#define DUFFING_ATTRIBUTES \ +ODE_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x); \ +CHAOS_SYS_ATTRIBUTE(y); \ +CHAOS_SYS_ATTRIBUTE(R); \ +CHAOS_SYS_ATTRIBUTE(gamma); \ CHAOS_SYS_ATTRIBUTE(omega); diff --git a/chaos/src/latoomutgamma.hpp b/chaos/src/latoomutgamma.hpp index 0120745..040a071 100644 --- a/chaos/src/latoomutgamma.hpp +++ b/chaos/src/latoomutgamma.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -27,59 +27,59 @@ // taken from Pickover: Chaos In Wonderland class latoomutgamma - : public map_base<2> + : public map_base<2> { public: - latoomutgamma() - { - CHAOS_SYS_INIT(x1,0.5,0); - CHAOS_SYS_INIT(x2,0.5,1); - - CHAOS_PAR_INIT(a,-0.966918); - CHAOS_PAR_INIT(b,2.879879); - } + latoomutgamma() + { + CHAOS_SYS_INIT(x1,0.5,0); + CHAOS_SYS_INIT(x2,0.5,1); - void m_step() - { - data_t x1 = m_data[0], x2 = m_data[1]; - data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); - data_t tmp; - - tmp = sin(x1*b); - m_data[0] = CHAOS_ABS(sin(x2*b)) + tmp*tmp; - tmp = sin(x2*a); - m_data[1] = CHAOS_ABS(sin(x1*a)) + tmp*tmp; - } + CHAOS_PAR_INIT(a,-0.966918); + CHAOS_PAR_INIT(b,2.879879); + } + void m_step() + { + data_t x1 = m_data[0], x2 = m_data[1]; + data_t a = CHAOS_PARAMETER(a), b = CHAOS_PARAMETER(b); + data_t tmp; - /* function has a fix point for x1 == x2 == 0 */ - void m_verify() - { - if (m_data[0] == 0 && m_data[1] == 0) - for (int i = 0; i != 2; ++i) - m_data[i] = rand_range(-1,1); - } - - CHAOS_SYSVAR_FUNCS(x1, 0); - CHAOS_SYSVAR_FUNCS(x2, 1); + tmp = sin(x1*b); + m_data[0] = std::abs(sin(x2*b)) + tmp*tmp; + tmp = sin(x2*a); + m_data[1] = std::abs(sin(x1*a)) + tmp*tmp; + } - CHAOS_SYSPAR_FUNCS(a); - CHAOS_SYSPAR_FUNCS(b); + + /* function has a fix point for x1 == x2 == 0 */ + void m_verify() + { + if (m_data[0] == 0 && m_data[1] == 0) + for (int i = 0; i != 2; ++i) + m_data[i] = rand_range(-1,1); + } + + CHAOS_SYSVAR_FUNCS(x1, 0); + CHAOS_SYSVAR_FUNCS(x2, 1); + + CHAOS_SYSPAR_FUNCS(a); + CHAOS_SYSPAR_FUNCS(b); }; -#define LATOOMUTGAMMA_CALLBACKS \ -MAP_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(x1); \ -CHAOS_SYS_CALLBACKS(x2); \ -CHAOS_SYS_CALLBACKS(a); \ +#define LATOOMUTGAMMA_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(x1); \ +CHAOS_SYS_CALLBACKS(x2); \ +CHAOS_SYS_CALLBACKS(a); \ CHAOS_SYS_CALLBACKS(b); -#define LATOOMUTGAMMA_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(x1); \ -CHAOS_SYS_ATTRIBUTE(x2); \ -CHAOS_SYS_ATTRIBUTE(a); \ +#define LATOOMUTGAMMA_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(x1); \ +CHAOS_SYS_ATTRIBUTE(x2); \ +CHAOS_SYS_ATTRIBUTE(a); \ CHAOS_SYS_ATTRIBUTE(b); diff --git a/chaos/src/linear_congruental.hpp b/chaos/src/linear_congruental.hpp index 25bc837..9c6310f 100644 --- a/chaos/src/linear_congruental.hpp +++ b/chaos/src/linear_congruental.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -25,43 +25,43 @@ // taken from Julien C. Sprott, Chaos and Time-Series Analysis class linear_congruental: - public map_base<2> + public map_base<2> { public: - linear_congruental() - { - CHAOS_SYS_INIT(x, 0, 0); - - CHAOS_PAR_INIT(A, 1741); - CHAOS_PAR_INIT(B, 54773); - CHAOS_PAR_INIT(C, 259200); - } + linear_congruental() + { + CHAOS_SYS_INIT(x, 0, 0); + + CHAOS_PAR_INIT(A, 1741); + CHAOS_PAR_INIT(B, 54773); + CHAOS_PAR_INIT(C, 259200); + } - void m_step() - { - data_t x = m_data[0]; + void m_step() + { + data_t x = m_data[0]; - m_data[0] = chaos_mod( CHAOS_PARAMETER(A) * x + CHAOS_PARAMETER(B), CHAOS_PARAMETER(C)); - } + m_data[0] = std::fmod( CHAOS_PARAMETER(A) * x + CHAOS_PARAMETER(B), CHAOS_PARAMETER(C)); + } - CHAOS_SYSVAR_FUNCS(x,0); + CHAOS_SYSVAR_FUNCS(x,0); - CHAOS_SYSPAR_FUNCS(A); - CHAOS_SYSPAR_FUNCS(B); - CHAOS_SYSPAR_FUNCS(C); + CHAOS_SYSPAR_FUNCS(A); + CHAOS_SYSPAR_FUNCS(B); + CHAOS_SYSPAR_FUNCS(C); }; -#define LINEAR_CONGRUENTAL_CALLBACKS \ -MAP_CALLBACKS; \ -CHAOS_SYS_CALLBACKS(A); \ -CHAOS_SYS_CALLBACKS(B); \ -CHAOS_SYS_CALLBACKS(C); \ +#define LINEAR_CONGRUENTAL_CALLBACKS \ +MAP_CALLBACKS; \ +CHAOS_SYS_CALLBACKS(A); \ +CHAOS_SYS_CALLBACKS(B); \ +CHAOS_SYS_CALLBACKS(C); \ CHAOS_SYS_CALLBACKS(x); -#define LINEAR_CONGRUENTAL_ATTRIBUTES \ -MAP_ATTRIBUTES; \ -CHAOS_SYS_ATTRIBUTE(A); \ -CHAOS_SYS_ATTRIBUTE(B); \ -CHAOS_SYS_ATTRIBUTE(C); \ +#define LINEAR_CONGRUENTAL_ATTRIBUTES \ +MAP_ATTRIBUTES; \ +CHAOS_SYS_ATTRIBUTE(A); \ +CHAOS_SYS_ATTRIBUTE(B); \ +CHAOS_SYS_ATTRIBUTE(C); \ CHAOS_SYS_ATTRIBUTE(x); diff --git a/chaos/src/ode_base.hpp b/chaos/src/ode_base.hpp index f46332c..42478bc 100644 --- a/chaos/src/ode_base.hpp +++ b/chaos/src/ode_base.hpp @@ -76,59 +76,58 @@ protected: data_t m_k1[dimensions]; data_t m_k2[dimensions]; data_t m_k3[dimensions]; - data_t m_tmp[dimensions]; -// data_t m_tmp[dimensions]; + data_t m_tmp[dimensions]; virtual void m_system (data_t* deriv, data_t* data) = 0; void rk1() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += m_dt * m_k0[i]; + m_system (m_k0, chaos_base::m_data); + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += m_dt * m_k0[i]; } void rk2() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// m_k0[i] = m_k0[i] * 0.5 * m_dt + m_data[i]; -// -// m_system (m_k1, m_k0); -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += m_dt * m_k1[i]; + for (int i = 0; i != dimensions; ++i) + m_k0[i] = m_k0[i] * 0.5 * m_dt + chaos_base::m_data[i]; + + m_system (m_k0, chaos_base::m_data); + m_system (m_k1, m_k0); + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += m_dt * m_k1[i]; } void rk4() { -// m_system (m_k0, m_data); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k0[i] *= m_dt; -// m_tmp[i] = m_data[i] + 0.5 * m_k0[i]; -// } -// -// m_system (m_k1, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k1[i] *= m_dt; -// m_tmp[i] = m_data[i] + 0.5 * m_k1[i]; -// } -// -// m_system (m_k2, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// { -// m_k2[i] *= m_dt; -// m_tmp[i] = m_data[i] + m_k2[i]; -// } -// -// m_system (m_k3, m_tmp); -// for (int i = 0; i != dimensions; ++i) -// m_k3[i] *= m_dt; -// -// for (int i = 0; i != dimensions; ++i) -// m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) -// / 6.; + m_system (m_k0, chaos_base::m_data); + for (int i = 0; i != dimensions; ++i) + { + m_k0[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + 0.5 * m_k0[i]; + } + + m_system (m_k1, m_tmp); + for (int i = 0; i != dimensions; ++i) + { + m_k1[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + 0.5 * m_k1[i]; + } + + m_system (m_k2, m_tmp); + for (int i = 0; i != dimensions; ++i) + { + m_k2[i] *= m_dt; + m_tmp[i] = chaos_base::m_data[i] + m_k2[i]; + } + + m_system (m_k3, m_tmp); + for (int i = 0; i != dimensions; ++i) + m_k3[i] *= m_dt; + + for (int i = 0; i != dimensions; ++i) + chaos_base::m_data[i] += (m_k0[i] + 2. * (m_k1[i] + m_k2[i]) + m_k3[i]) + / 6.; } }; diff --git a/chaos/src/tent_map.hpp b/chaos/src/tent_map.hpp index f8f2c29..b0961ee 100644 --- a/chaos/src/tent_map.hpp +++ b/chaos/src/tent_map.hpp @@ -1,18 +1,18 @@ -// -// +// +// // chaos~ // Copyright (C) 2004 Tim Blechmann -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; see the file COPYING. If not, write to // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, @@ -26,36 +26,36 @@ class tent_map: - public map_base<1> + public map_base<1> { public: - tent_map() - { - CHAOS_SYS_INIT(x, 0.6,0); - } - - - void m_step() - { - data_t data = m_data[0]; - - m_data[0] = 1 - 2*CHAOS_ABS(data); - } - - CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); - bool m_pred_x(t_float f) - { - return (f > -1) && (f < 1); - } + tent_map() + { + CHAOS_SYS_INIT(x, 0.6,0); + } + + + void m_step() + { + data_t data = m_data[0]; + + m_data[0] = 1 - 2*std::abs(data); + } + + CHAOS_SYSVAR_FUNCS_PRED(x, 0, m_pred_x); + bool m_pred_x(t_float f) + { + return (f > -1) && (f < 1); + } }; -#define TENT_MAP_CALLBACKS \ -MAP_CALLBACKS \ +#define TENT_MAP_CALLBACKS \ +MAP_CALLBACKS \ CHAOS_SYS_CALLBACKS(x); -#define TENT_MAP_ATTRIBUTES \ -MAP_ATTRIBUTES \ +#define TENT_MAP_ATTRIBUTES \ +MAP_ATTRIBUTES \ CHAOS_SYS_ATTRIBUTE(x); - + -- cgit v1.2.1 From e8c0887941bff7f23f48f8ccd5b8cab2c992a83f Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 17 Dec 2007 06:23:46 +0000 Subject: changed helpfile to standard name svn path=/trunk/externals/tb/; revision=9097 --- jack_transport/jack_transport-help.pd | 13 +++++++++++++ jack_transport/jack_transport.pd | 13 ------------- jack_transport/makefile | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 jack_transport/jack_transport-help.pd delete mode 100644 jack_transport/jack_transport.pd diff --git a/jack_transport/jack_transport-help.pd b/jack_transport/jack_transport-help.pd new file mode 100644 index 0000000..4460085 --- /dev/null +++ b/jack_transport/jack_transport-help.pd @@ -0,0 +1,13 @@ +#N canvas 0 0 450 300 10; +#X obj 100 141 jack_transport; +#X floatatom 140 118 5 0 0 0 - - -; +#X msg 191 120 stop; +#X msg 191 97 start; +#X floatatom 87 174 9 0 0 0 - - -; +#X obj 42 58 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 +-1; +#X connect 0 0 4 0; +#X connect 1 0 0 0; +#X connect 2 0 0 0; +#X connect 3 0 0 0; +#X connect 5 0 0 0; diff --git a/jack_transport/jack_transport.pd b/jack_transport/jack_transport.pd deleted file mode 100644 index 4460085..0000000 --- a/jack_transport/jack_transport.pd +++ /dev/null @@ -1,13 +0,0 @@ -#N canvas 0 0 450 300 10; -#X obj 100 141 jack_transport; -#X floatatom 140 118 5 0 0 0 - - -; -#X msg 191 120 stop; -#X msg 191 97 start; -#X floatatom 87 174 9 0 0 0 - - -; -#X obj 42 58 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 --1; -#X connect 0 0 4 0; -#X connect 1 0 0 0; -#X connect 2 0 0 0; -#X connect 3 0 0 0; -#X connect 5 0 0 0; diff --git a/jack_transport/makefile b/jack_transport/makefile index d4bb5fb..9446d42 100644 --- a/jack_transport/makefile +++ b/jack_transport/makefile @@ -64,7 +64,7 @@ LINUXCFLAGS = -DPD -O3 -fPIC -funroll-loops -fomit-frame-pointer \ -Wall -W -Wshadow -Wstrict-prototypes -Werror \ -Wno-unused -Wno-parentheses -Wno-switch -g -LINUXINCLUDE = -I../../../src +LINUXINCLUDE = -I../../../pd/src LSTRIP = strip --strip-unneeded -R .note -R .comment -- cgit v1.2.1 From 6c03ffeef182c00462a6d0375ed81dc0d9983124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 19 Jun 2008 13:50:58 +0000 Subject: removed the svn:executable bit for code, patches and text svn path=/trunk/externals/tb/; revision=10048 --- sc4pd/config-pd-darwin.txt | 0 sc4pd/config-pd-linux.txt | 0 sc4pd/headers/app/TabletEvents.h | 0 sc4pd/headers/common/SC_AllocPool.h | 0 sc4pd/headers/common/SC_Sem.h | 0 sc4pd/headers/common/dfftlib.h | 0 sc4pd/headers/common/fftlib.h | 0 sc4pd/headers/lang/AdvancingAllocPool.h | 0 sc4pd/headers/lang/AllocPools.h | 0 sc4pd/headers/lang/ByteCodeArray.h | 0 sc4pd/headers/lang/FIFOT.h | 0 sc4pd/headers/lang/GC.h | 0 sc4pd/headers/lang/HashTable.h | 0 sc4pd/headers/lang/InitAlloc.h | 0 sc4pd/headers/lang/MiscInlineMath.h | 0 sc4pd/headers/lang/OSCData.h | 0 sc4pd/headers/lang/Opcodes.h | 0 sc4pd/headers/lang/PowerOfTwoAllocPool.h | 0 sc4pd/headers/lang/PredefinedSymbols.h | 0 sc4pd/headers/lang/PriorityQueue.h | 0 sc4pd/headers/lang/PyrArchiverT.h | 0 sc4pd/headers/lang/PyrDeepCopier.h | 0 sc4pd/headers/lang/PyrDeepFreezer.h | 0 sc4pd/headers/lang/PyrErrors.h | 0 sc4pd/headers/lang/PyrFilePrim.h | 0 sc4pd/headers/lang/PyrFileUtils.h | 0 sc4pd/headers/lang/PyrInterpreter.h | 0 sc4pd/headers/lang/PyrKernel.h | 0 sc4pd/headers/lang/PyrKernelProto.h | 0 sc4pd/headers/lang/PyrLexer.h | 0 sc4pd/headers/lang/PyrListPrim.h | 0 sc4pd/headers/lang/PyrMathPrim.h | 0 sc4pd/headers/lang/PyrMessage.h | 0 sc4pd/headers/lang/PyrObject.h | 0 sc4pd/headers/lang/PyrObjectProto.h | 0 sc4pd/headers/lang/PyrParseNode.h | 0 sc4pd/headers/lang/PyrPrimitive.h | 0 sc4pd/headers/lang/PyrPrimitiveProto.h | 0 sc4pd/headers/lang/PyrSched.h | 0 sc4pd/headers/lang/PyrSignal.h | 0 sc4pd/headers/lang/PyrSignalPrim.h | 0 sc4pd/headers/lang/PyrSlot.h | 0 sc4pd/headers/lang/PyrSymbol.h | 0 sc4pd/headers/lang/PyrSymbolTable.h | 0 sc4pd/headers/lang/ReadWriteMacros.h | 0 sc4pd/headers/lang/SCBase.h | 0 sc4pd/headers/lang/SC_ComPort.h | 0 sc4pd/headers/lang/SC_List.h | 0 sc4pd/headers/lang/SC_LogFile.h | 0 sc4pd/headers/lang/SC_Msg.h | 0 sc4pd/headers/lang/SC_SynthImpl.h | 0 sc4pd/headers/lang/SC_UnorderedList.h | 0 sc4pd/headers/lang/SFHeaders.h | 0 sc4pd/headers/lang/Samp.h | 0 sc4pd/headers/lang/SimpleStack.h | 0 sc4pd/headers/lang/VMGlobals.h | 0 sc4pd/headers/lang/bullet.h | 0 sc4pd/headers/lang/readSamples.h | 0 sc4pd/headers/plugin_interface/Hash.h | 0 sc4pd/headers/plugin_interface/SC_BoundsMacros.h | 0 sc4pd/headers/plugin_interface/SC_Constants.h | 0 sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h | 0 sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h | 0 sc4pd/headers/plugin_interface/SC_RGen.h | 0 sc4pd/headers/plugin_interface/SC_Types.h | 0 sc4pd/headers/plugin_interface/clz.h | 0 sc4pd/headers/server/HashTable.h | 0 sc4pd/headers/server/MsgFifo.h | 0 sc4pd/headers/server/PriorityQueue.h | 0 sc4pd/headers/server/SC_ComPort.h | 0 sc4pd/headers/server/SC_CoreAudio.h | 0 sc4pd/headers/server/SC_Errors.h | 0 sc4pd/headers/server/SC_Lib.h | 0 sc4pd/headers/server/SC_Lib_Cintf.h | 0 sc4pd/headers/server/SC_List.h | 0 sc4pd/headers/server/SC_Lock.h | 0 sc4pd/headers/server/SC_Reply.h | 0 sc4pd/headers/server/SC_SyncCondition.h | 0 sc4pd/make-files.txt | 0 sndfiler/GnuGPL.txt | 0 sndfiler/doc/sndfiler-help.pd | 0 sndfiler/src/sndfiler.c | 0 sndfiler/src/sndfiler.h | 0 tbext/config-pd-darwin.txt | 0 tbext/config-pd-linux.txt | 0 tbext/make-files.txt | 0 86 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 sc4pd/config-pd-darwin.txt mode change 100755 => 100644 sc4pd/config-pd-linux.txt mode change 100755 => 100644 sc4pd/headers/app/TabletEvents.h mode change 100755 => 100644 sc4pd/headers/common/SC_AllocPool.h mode change 100755 => 100644 sc4pd/headers/common/SC_Sem.h mode change 100755 => 100644 sc4pd/headers/common/dfftlib.h mode change 100755 => 100644 sc4pd/headers/common/fftlib.h mode change 100755 => 100644 sc4pd/headers/lang/AdvancingAllocPool.h mode change 100755 => 100644 sc4pd/headers/lang/AllocPools.h mode change 100755 => 100644 sc4pd/headers/lang/ByteCodeArray.h mode change 100755 => 100644 sc4pd/headers/lang/FIFOT.h mode change 100755 => 100644 sc4pd/headers/lang/GC.h mode change 100755 => 100644 sc4pd/headers/lang/HashTable.h mode change 100755 => 100644 sc4pd/headers/lang/InitAlloc.h mode change 100755 => 100644 sc4pd/headers/lang/MiscInlineMath.h mode change 100755 => 100644 sc4pd/headers/lang/OSCData.h mode change 100755 => 100644 sc4pd/headers/lang/Opcodes.h mode change 100755 => 100644 sc4pd/headers/lang/PowerOfTwoAllocPool.h mode change 100755 => 100644 sc4pd/headers/lang/PredefinedSymbols.h mode change 100755 => 100644 sc4pd/headers/lang/PriorityQueue.h mode change 100755 => 100644 sc4pd/headers/lang/PyrArchiverT.h mode change 100755 => 100644 sc4pd/headers/lang/PyrDeepCopier.h mode change 100755 => 100644 sc4pd/headers/lang/PyrDeepFreezer.h mode change 100755 => 100644 sc4pd/headers/lang/PyrErrors.h mode change 100755 => 100644 sc4pd/headers/lang/PyrFilePrim.h mode change 100755 => 100644 sc4pd/headers/lang/PyrFileUtils.h mode change 100755 => 100644 sc4pd/headers/lang/PyrInterpreter.h mode change 100755 => 100644 sc4pd/headers/lang/PyrKernel.h mode change 100755 => 100644 sc4pd/headers/lang/PyrKernelProto.h mode change 100755 => 100644 sc4pd/headers/lang/PyrLexer.h mode change 100755 => 100644 sc4pd/headers/lang/PyrListPrim.h mode change 100755 => 100644 sc4pd/headers/lang/PyrMathPrim.h mode change 100755 => 100644 sc4pd/headers/lang/PyrMessage.h mode change 100755 => 100644 sc4pd/headers/lang/PyrObject.h mode change 100755 => 100644 sc4pd/headers/lang/PyrObjectProto.h mode change 100755 => 100644 sc4pd/headers/lang/PyrParseNode.h mode change 100755 => 100644 sc4pd/headers/lang/PyrPrimitive.h mode change 100755 => 100644 sc4pd/headers/lang/PyrPrimitiveProto.h mode change 100755 => 100644 sc4pd/headers/lang/PyrSched.h mode change 100755 => 100644 sc4pd/headers/lang/PyrSignal.h mode change 100755 => 100644 sc4pd/headers/lang/PyrSignalPrim.h mode change 100755 => 100644 sc4pd/headers/lang/PyrSlot.h mode change 100755 => 100644 sc4pd/headers/lang/PyrSymbol.h mode change 100755 => 100644 sc4pd/headers/lang/PyrSymbolTable.h mode change 100755 => 100644 sc4pd/headers/lang/ReadWriteMacros.h mode change 100755 => 100644 sc4pd/headers/lang/SCBase.h mode change 100755 => 100644 sc4pd/headers/lang/SC_ComPort.h mode change 100755 => 100644 sc4pd/headers/lang/SC_List.h mode change 100755 => 100644 sc4pd/headers/lang/SC_LogFile.h mode change 100755 => 100644 sc4pd/headers/lang/SC_Msg.h mode change 100755 => 100644 sc4pd/headers/lang/SC_SynthImpl.h mode change 100755 => 100644 sc4pd/headers/lang/SC_UnorderedList.h mode change 100755 => 100644 sc4pd/headers/lang/SFHeaders.h mode change 100755 => 100644 sc4pd/headers/lang/Samp.h mode change 100755 => 100644 sc4pd/headers/lang/SimpleStack.h mode change 100755 => 100644 sc4pd/headers/lang/VMGlobals.h mode change 100755 => 100644 sc4pd/headers/lang/bullet.h mode change 100755 => 100644 sc4pd/headers/lang/readSamples.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/Hash.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/SC_BoundsMacros.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/SC_Constants.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/SC_RGen.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/SC_Types.h mode change 100755 => 100644 sc4pd/headers/plugin_interface/clz.h mode change 100755 => 100644 sc4pd/headers/server/HashTable.h mode change 100755 => 100644 sc4pd/headers/server/MsgFifo.h mode change 100755 => 100644 sc4pd/headers/server/PriorityQueue.h mode change 100755 => 100644 sc4pd/headers/server/SC_ComPort.h mode change 100755 => 100644 sc4pd/headers/server/SC_CoreAudio.h mode change 100755 => 100644 sc4pd/headers/server/SC_Errors.h mode change 100755 => 100644 sc4pd/headers/server/SC_Lib.h mode change 100755 => 100644 sc4pd/headers/server/SC_Lib_Cintf.h mode change 100755 => 100644 sc4pd/headers/server/SC_List.h mode change 100755 => 100644 sc4pd/headers/server/SC_Lock.h mode change 100755 => 100644 sc4pd/headers/server/SC_Reply.h mode change 100755 => 100644 sc4pd/headers/server/SC_SyncCondition.h mode change 100755 => 100644 sc4pd/make-files.txt mode change 100755 => 100644 sndfiler/GnuGPL.txt mode change 100755 => 100644 sndfiler/doc/sndfiler-help.pd mode change 100755 => 100644 sndfiler/src/sndfiler.c mode change 100755 => 100644 sndfiler/src/sndfiler.h mode change 100755 => 100644 tbext/config-pd-darwin.txt mode change 100755 => 100644 tbext/config-pd-linux.txt mode change 100755 => 100644 tbext/make-files.txt diff --git a/sc4pd/config-pd-darwin.txt b/sc4pd/config-pd-darwin.txt old mode 100755 new mode 100644 diff --git a/sc4pd/config-pd-linux.txt b/sc4pd/config-pd-linux.txt old mode 100755 new mode 100644 diff --git a/sc4pd/headers/app/TabletEvents.h b/sc4pd/headers/app/TabletEvents.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/common/SC_AllocPool.h b/sc4pd/headers/common/SC_AllocPool.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/common/SC_Sem.h b/sc4pd/headers/common/SC_Sem.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/common/dfftlib.h b/sc4pd/headers/common/dfftlib.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/common/fftlib.h b/sc4pd/headers/common/fftlib.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/AdvancingAllocPool.h b/sc4pd/headers/lang/AdvancingAllocPool.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/AllocPools.h b/sc4pd/headers/lang/AllocPools.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/ByteCodeArray.h b/sc4pd/headers/lang/ByteCodeArray.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/FIFOT.h b/sc4pd/headers/lang/FIFOT.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/GC.h b/sc4pd/headers/lang/GC.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/HashTable.h b/sc4pd/headers/lang/HashTable.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/InitAlloc.h b/sc4pd/headers/lang/InitAlloc.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/MiscInlineMath.h b/sc4pd/headers/lang/MiscInlineMath.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/OSCData.h b/sc4pd/headers/lang/OSCData.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/Opcodes.h b/sc4pd/headers/lang/Opcodes.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PowerOfTwoAllocPool.h b/sc4pd/headers/lang/PowerOfTwoAllocPool.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PredefinedSymbols.h b/sc4pd/headers/lang/PredefinedSymbols.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PriorityQueue.h b/sc4pd/headers/lang/PriorityQueue.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrArchiverT.h b/sc4pd/headers/lang/PyrArchiverT.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrDeepCopier.h b/sc4pd/headers/lang/PyrDeepCopier.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrDeepFreezer.h b/sc4pd/headers/lang/PyrDeepFreezer.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrErrors.h b/sc4pd/headers/lang/PyrErrors.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrFilePrim.h b/sc4pd/headers/lang/PyrFilePrim.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrFileUtils.h b/sc4pd/headers/lang/PyrFileUtils.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrInterpreter.h b/sc4pd/headers/lang/PyrInterpreter.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrKernel.h b/sc4pd/headers/lang/PyrKernel.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrKernelProto.h b/sc4pd/headers/lang/PyrKernelProto.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrLexer.h b/sc4pd/headers/lang/PyrLexer.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrListPrim.h b/sc4pd/headers/lang/PyrListPrim.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrMathPrim.h b/sc4pd/headers/lang/PyrMathPrim.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrMessage.h b/sc4pd/headers/lang/PyrMessage.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrObject.h b/sc4pd/headers/lang/PyrObject.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrObjectProto.h b/sc4pd/headers/lang/PyrObjectProto.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrParseNode.h b/sc4pd/headers/lang/PyrParseNode.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrPrimitive.h b/sc4pd/headers/lang/PyrPrimitive.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrPrimitiveProto.h b/sc4pd/headers/lang/PyrPrimitiveProto.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrSched.h b/sc4pd/headers/lang/PyrSched.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrSignal.h b/sc4pd/headers/lang/PyrSignal.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrSignalPrim.h b/sc4pd/headers/lang/PyrSignalPrim.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrSlot.h b/sc4pd/headers/lang/PyrSlot.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrSymbol.h b/sc4pd/headers/lang/PyrSymbol.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/PyrSymbolTable.h b/sc4pd/headers/lang/PyrSymbolTable.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/ReadWriteMacros.h b/sc4pd/headers/lang/ReadWriteMacros.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SCBase.h b/sc4pd/headers/lang/SCBase.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SC_ComPort.h b/sc4pd/headers/lang/SC_ComPort.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SC_List.h b/sc4pd/headers/lang/SC_List.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SC_LogFile.h b/sc4pd/headers/lang/SC_LogFile.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SC_Msg.h b/sc4pd/headers/lang/SC_Msg.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SC_SynthImpl.h b/sc4pd/headers/lang/SC_SynthImpl.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SC_UnorderedList.h b/sc4pd/headers/lang/SC_UnorderedList.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SFHeaders.h b/sc4pd/headers/lang/SFHeaders.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/Samp.h b/sc4pd/headers/lang/Samp.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/SimpleStack.h b/sc4pd/headers/lang/SimpleStack.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/VMGlobals.h b/sc4pd/headers/lang/VMGlobals.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/bullet.h b/sc4pd/headers/lang/bullet.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/lang/readSamples.h b/sc4pd/headers/lang/readSamples.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/Hash.h b/sc4pd/headers/plugin_interface/Hash.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/SC_BoundsMacros.h b/sc4pd/headers/plugin_interface/SC_BoundsMacros.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/SC_Constants.h b/sc4pd/headers/plugin_interface/SC_Constants.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h b/sc4pd/headers/plugin_interface/SC_InlineBinaryOp.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h b/sc4pd/headers/plugin_interface/SC_InlineUnaryOp.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/SC_RGen.h b/sc4pd/headers/plugin_interface/SC_RGen.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/SC_Types.h b/sc4pd/headers/plugin_interface/SC_Types.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/plugin_interface/clz.h b/sc4pd/headers/plugin_interface/clz.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/HashTable.h b/sc4pd/headers/server/HashTable.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/MsgFifo.h b/sc4pd/headers/server/MsgFifo.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/PriorityQueue.h b/sc4pd/headers/server/PriorityQueue.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_ComPort.h b/sc4pd/headers/server/SC_ComPort.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_CoreAudio.h b/sc4pd/headers/server/SC_CoreAudio.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_Errors.h b/sc4pd/headers/server/SC_Errors.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_Lib.h b/sc4pd/headers/server/SC_Lib.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_Lib_Cintf.h b/sc4pd/headers/server/SC_Lib_Cintf.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_List.h b/sc4pd/headers/server/SC_List.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_Lock.h b/sc4pd/headers/server/SC_Lock.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_Reply.h b/sc4pd/headers/server/SC_Reply.h old mode 100755 new mode 100644 diff --git a/sc4pd/headers/server/SC_SyncCondition.h b/sc4pd/headers/server/SC_SyncCondition.h old mode 100755 new mode 100644 diff --git a/sc4pd/make-files.txt b/sc4pd/make-files.txt old mode 100755 new mode 100644 diff --git a/sndfiler/GnuGPL.txt b/sndfiler/GnuGPL.txt old mode 100755 new mode 100644 diff --git a/sndfiler/doc/sndfiler-help.pd b/sndfiler/doc/sndfiler-help.pd old mode 100755 new mode 100644 diff --git a/sndfiler/src/sndfiler.c b/sndfiler/src/sndfiler.c old mode 100755 new mode 100644 diff --git a/sndfiler/src/sndfiler.h b/sndfiler/src/sndfiler.h old mode 100755 new mode 100644 diff --git a/tbext/config-pd-darwin.txt b/tbext/config-pd-darwin.txt old mode 100755 new mode 100644 diff --git a/tbext/config-pd-linux.txt b/tbext/config-pd-linux.txt old mode 100755 new mode 100644 diff --git a/tbext/make-files.txt b/tbext/make-files.txt old mode 100755 new mode 100644 -- cgit v1.2.1 From 2c1ff19c4d99921dcd55176b5574e932dda39c68 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 9 Jun 2009 17:34:48 +0000 Subject: replaced -export_dynamic with --export-dynamic and -Wl,--export-dynamic where appropriate. It seems that once upon a time -export_dynamic was a real flag. Now it means -e xport_dynamic, meaning set the entry symbol to xport_dynamic, giving this error message: /usr/bin/ld: warning: cannot find entry symbol xport_dynamic; defaulting to 0000000000001b60 svn path=/trunk/externals/tb/; revision=11724 --- assert/makefile | 2 +- block_delay~/makefile | 2 +- detach/makefile | 2 +- erfc~/makefile | 2 +- erf~/makefile | 2 +- jack_transport/makefile | 2 +- join/makefile | 2 +- sndfiler/src/Makefile | 2 +- volctl~/makefile | 2 +- xvalue/makefile | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/assert/makefile b/assert/makefile index 3a00de1..ac5776c 100644 --- a/assert/makefile +++ b/assert/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/block_delay~/makefile b/block_delay~/makefile index d2d0d21..e946d6d 100644 --- a/block_delay~/makefile +++ b/block_delay~/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/detach/makefile b/detach/makefile index 979bba0..dc50b33 100644 --- a/detach/makefile +++ b/detach/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/erfc~/makefile b/erfc~/makefile index a874c3c..ea26ea1 100644 --- a/erfc~/makefile +++ b/erfc~/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/erf~/makefile b/erf~/makefile index a4c8ed4..525fc48 100644 --- a/erf~/makefile +++ b/erf~/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/jack_transport/makefile b/jack_transport/makefile index 9446d42..5419c2c 100644 --- a/jack_transport/makefile +++ b/jack_transport/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/join/makefile b/join/makefile index bcad613..d4b6e2a 100644 --- a/join/makefile +++ b/join/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/sndfiler/src/Makefile b/sndfiler/src/Makefile index b8f1c8a..3bcd658 100755 --- a/sndfiler/src/Makefile +++ b/sndfiler/src/Makefile @@ -74,7 +74,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o sndfiler.o -c sndfiler.c cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o file_input.o -c file_input.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $(OBJ) -lm -lsndfile -lvorbisfile + cc -Wl,--export-dynamic --shared -o $*.pd_linux $(OBJ) -lm -lsndfile -lvorbisfile # $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/volctl~/makefile b/volctl~/makefile index 3457263..ae241b6 100644 --- a/volctl~/makefile +++ b/volctl~/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o diff --git a/xvalue/makefile b/xvalue/makefile index 4cae4fc..2ce2bf2 100644 --- a/xvalue/makefile +++ b/xvalue/makefile @@ -70,7 +70,7 @@ LSTRIP = strip --strip-unneeded -R .note -R .comment .c.pd_linux: cc $(LINUXCFLAGS) $(LINUXINCLUDE) -o $*.o -c $*.c - cc -Wl,-export_dynamic --shared -o $*.pd_linux $*.o -lm + cc -Wl,--export-dynamic --shared -o $*.pd_linux $*.o -lm $(LSTRIP) $*.pd_linux rm -f $*.o -- cgit v1.2.1 From ca3f35ee0b459fce8554f339910484cd32f35b9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 20 Jul 2011 11:11:13 +0000 Subject: fixed linebreaks svn path=/trunk/externals/tb/; revision=15163 --- sc4pd/headers/lang/SFHeaders.h | 141 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 1 deletion(-) diff --git a/sc4pd/headers/lang/SFHeaders.h b/sc4pd/headers/lang/SFHeaders.h index 0504b27..143652d 100644 --- a/sc4pd/headers/lang/SFHeaders.h +++ b/sc4pd/headers/lang/SFHeaders.h @@ -1 +1,140 @@ -/* SuperCollider real time audio synthesis system Copyright (c) 2002 James McCartney. All rights reserved. http://www.audiosynth.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SFHeaders_ #define _SFHeaders_ #include "SCBase.h" #include "ReadWriteMacros.h" enum { unsupported_sound_file = -1, AIFF_sound_file, AIFC_sound_file, RIFF_sound_file, NeXT_sound_file, IRCAM_sound_file, SD2_sound_file, raw_sound_file }; enum { snd_unsupported = -1, snd_no_snd, snd_16_linear, snd_8_mulaw, snd_8_linear, snd_32_float, snd_32_linear, snd_8_alaw, snd_8_unsigned, snd_24_linear, snd_64_double, snd_16_linear_little_endian, snd_32_linear_little_endian, snd_32_float_little_endian, snd_64_double_little_endian, snd_16_unsigned, snd_16_unsigned_little_endian, snd_24_linear_little_endian, snd_32_vax_float, snd_12_linear, snd_12_linear_little_endian, snd_12_unsigned, snd_12_unsigned_little_endian }; class SFHeaderInfo { public: SFHeaderInfo(); bool WriteHeader(FILE *inFile); void SetPath(char *inPath); double SampleRate() { return mSampleRate; } void SetSampleRate(double inSampleRate) { mSampleRate = inSampleRate; } void SetFormat(int inHeaderFormat, int inSampleFormat, int inCreator); double Freq() { return mFreq; } uint8 LoNote() { return mLoNote; } uint8 HiNote() { return mHiNote; } uint8 LoVeloc() { return mLoVeloc; } uint8 HiVeloc() { return mHiVeloc; } uint8 NumChannels() { return mNumChannels; } int32 NumFramesInFile() { return mNumFramesInFile; } int makeSoundFileHeader(SC_IOStream& rw); int32 headerFileType(); int headerSize(); int sampleFormatSize(); void newSoundFilePath(); bool ReadSoundFileHeader(FILE *fp); int32 CalcFrameSize(); bool SetTypeCreator(); char mPath[256]; double mSampleRate; double mFreq; int32 mNumFramesInFile; int32 mDataOffset; int32 mCreator; void *mExtraStuff; int16 mGain; int8 mHeaderFormat; int8 mSampleFormat; uint8 mNumChannels; uint8 mLoNote, mHiNote, mLoVeloc, mHiVeloc; private: int make_AIFF_header(SC_IOStream& rw); int make_AIFC_header(SC_IOStream& rw); int make_RIFF_header(SC_IOStream& rw); int make_Next_header(SC_IOStream& rw); int make_IRCAM_header(SC_IOStream& rw); int sampleFormat_AIFF(); int sampleFormat_AIFC(); int sampleFormat_RIFF(); int sampleFormat_Next(); int sampleFormat_Next_inv(int inFormat); void writeCompressionFormat_AIFC(SC_IOStream& rw); bool read_AIFF_Header(SC_IOStream& rw); bool read_RIFF_Header(SC_IOStream& rw); bool read_Next_Header(SC_IOStream& rw); }; extern char gDefaultSoundFolder[256]; extern char gDefaultSoundFilePath[256]; int sampleFormatSize(int inSampleFormat); #endif \ No newline at end of file +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +#ifndef _SFHeaders_ +#define _SFHeaders_ + +#include "SCBase.h" +#include "ReadWriteMacros.h" + +enum { + unsupported_sound_file = -1, + AIFF_sound_file, + AIFC_sound_file, + RIFF_sound_file, + NeXT_sound_file, + IRCAM_sound_file, + SD2_sound_file, + raw_sound_file +}; + +enum { + snd_unsupported = -1, + snd_no_snd, + snd_16_linear, + snd_8_mulaw, + snd_8_linear, + snd_32_float, + snd_32_linear, + snd_8_alaw, + snd_8_unsigned, + snd_24_linear, + snd_64_double, + snd_16_linear_little_endian, + snd_32_linear_little_endian, + snd_32_float_little_endian, + snd_64_double_little_endian, + snd_16_unsigned, + snd_16_unsigned_little_endian, + snd_24_linear_little_endian, + snd_32_vax_float, + snd_12_linear, + snd_12_linear_little_endian, + snd_12_unsigned, + snd_12_unsigned_little_endian +}; + + +class SFHeaderInfo +{ +public: + SFHeaderInfo(); + + bool WriteHeader(FILE *inFile); + + void SetPath(char *inPath); + double SampleRate() { return mSampleRate; } + void SetSampleRate(double inSampleRate) { mSampleRate = inSampleRate; } + void SetFormat(int inHeaderFormat, int inSampleFormat, int inCreator); + + double Freq() { return mFreq; } + + uint8 LoNote() { return mLoNote; } + uint8 HiNote() { return mHiNote; } + uint8 LoVeloc() { return mLoVeloc; } + uint8 HiVeloc() { return mHiVeloc; } + + uint8 NumChannels() { return mNumChannels; } + int32 NumFramesInFile() { return mNumFramesInFile; } + + int makeSoundFileHeader(SC_IOStream& rw); + + int32 headerFileType(); + int headerSize(); + int sampleFormatSize(); + void newSoundFilePath(); + + bool ReadSoundFileHeader(FILE *fp); + + int32 CalcFrameSize(); + bool SetTypeCreator(); + + char mPath[256]; + double mSampleRate; + double mFreq; + int32 mNumFramesInFile; + int32 mDataOffset; + int32 mCreator; + void *mExtraStuff; + int16 mGain; + int8 mHeaderFormat; + int8 mSampleFormat; + uint8 mNumChannels; + uint8 mLoNote, mHiNote, mLoVeloc, mHiVeloc; + +private: + + + int make_AIFF_header(SC_IOStream& rw); + int make_AIFC_header(SC_IOStream& rw); + int make_RIFF_header(SC_IOStream& rw); + int make_Next_header(SC_IOStream& rw); + int make_IRCAM_header(SC_IOStream& rw); + + int sampleFormat_AIFF(); + int sampleFormat_AIFC(); + int sampleFormat_RIFF(); + int sampleFormat_Next(); + int sampleFormat_Next_inv(int inFormat); + void writeCompressionFormat_AIFC(SC_IOStream& rw); + + bool read_AIFF_Header(SC_IOStream& rw); + bool read_RIFF_Header(SC_IOStream& rw); + bool read_Next_Header(SC_IOStream& rw); +}; + + +extern char gDefaultSoundFolder[256]; +extern char gDefaultSoundFilePath[256]; + +int sampleFormatSize(int inSampleFormat); + +#endif -- cgit v1.2.1 From a95e3458aaa5f11f78006632be7b3f87d83febcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 30 Apr 2015 21:16:01 +0000 Subject: imported patch from Patrice Colet svn path=/trunk/externals/tb/; revision=17460 --- jack_transport/jack_transport.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/jack_transport/jack_transport.c b/jack_transport/jack_transport.c index 84b269e..e9efd11 100644 --- a/jack_transport/jack_transport.c +++ b/jack_transport/jack_transport.c @@ -24,27 +24,36 @@ static t_class *jack_transport_class; + +float time_beats_per_bar = 4.0; +float time_beat_type = 1.0 / 4.0; +double time_ticks_per_beat = 1920.0; +double time_beats_per_minute = 120.0; + typedef struct _jack_transport { t_object x_obj; t_outlet * x_outlet; + t_outlet * x_outlet_bar; + t_outlet * x_outlet_beat; + t_outlet * x_outlet_beat_type; + t_outlet * x_outlet_beats_per_bar; + t_outlet * x_outlet_beats_per_minute; jack_client_t* x_jack_client; jack_position_t* x_pos; } jack_transport_t; - /* connect to jack server */ static int jack_transport_connect(jack_transport_t * x) { char port_name[80] = ""; - static int client = 0; do { sprintf(port_name,"pure_data_jack_transport_%d",client); client++; } - while (((x->x_jack_client = jack_client_new (port_name)) == 0) && + while (((x->x_jack_client = jack_client_open (port_name, (jack_options_t)0, NULL)) == 0) && client < 100); client = 0; @@ -67,7 +76,13 @@ static jack_transport_t * jack_transport_new(void) int status = 0; jack_transport_t *x = (jack_transport_t*) pd_new(jack_transport_class); + x->x_outlet = outlet_new(&x->x_obj, NULL); + x->x_outlet_bar = outlet_new(&x->x_obj, NULL); + x->x_outlet_beat = outlet_new(&x->x_obj, NULL); + x->x_outlet_beat_type = outlet_new(&x->x_obj, NULL); + x->x_outlet_beats_per_bar = outlet_new(&x->x_obj, NULL); + x->x_outlet_beats_per_minute = outlet_new(&x->x_obj, NULL); x->x_pos = (jack_position_t*) getbytes(sizeof(jack_position_t)); status = jack_transport_connect(x); @@ -87,6 +102,17 @@ static void jack_transport_stoper(jack_transport_t * x) return; } +static void jack_transport_timebase(jack_transport_t * x) +{ + jack_position_t pos; + const int rolling = (jack_transport_query(x->x_jack_client, &pos) == JackTransportRolling); + outlet_float(x->x_outlet_bar, pos.bar); + outlet_float(x->x_outlet_beat, pos.beat); + outlet_float(x->x_outlet_beat_type, pos.beat_type); + outlet_float(x->x_outlet_beats_per_bar, pos.beats_per_bar); + outlet_float(x->x_outlet_beats_per_minute, pos.beats_per_minute); +} + static void jack_transport_bang(jack_transport_t * x) { float f; @@ -94,7 +120,7 @@ static void jack_transport_bang(jack_transport_t * x) return; f = (float)jack_get_current_transport_frame(x->x_jack_client); - + jack_transport_timebase(x); outlet_float(x->x_outlet, f); } -- cgit v1.2.1 From 622422f9fe647dc63fe9c80b1b7205a17e621586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 30 Apr 2015 21:38:10 +0000 Subject: collate extra outlets into a single one that emits routable messages svn path=/trunk/externals/tb/; revision=17461 --- jack_transport/jack_transport.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/jack_transport/jack_transport.c b/jack_transport/jack_transport.c index e9efd11..f781346 100644 --- a/jack_transport/jack_transport.c +++ b/jack_transport/jack_transport.c @@ -25,20 +25,11 @@ static t_class *jack_transport_class; -float time_beats_per_bar = 4.0; -float time_beat_type = 1.0 / 4.0; -double time_ticks_per_beat = 1920.0; -double time_beats_per_minute = 120.0; - typedef struct _jack_transport { t_object x_obj; t_outlet * x_outlet; - t_outlet * x_outlet_bar; - t_outlet * x_outlet_beat; - t_outlet * x_outlet_beat_type; - t_outlet * x_outlet_beats_per_bar; - t_outlet * x_outlet_beats_per_minute; + t_outlet * x_outlet_info; jack_client_t* x_jack_client; jack_position_t* x_pos; } jack_transport_t; @@ -78,11 +69,7 @@ static jack_transport_t * jack_transport_new(void) x->x_outlet = outlet_new(&x->x_obj, NULL); - x->x_outlet_bar = outlet_new(&x->x_obj, NULL); - x->x_outlet_beat = outlet_new(&x->x_obj, NULL); - x->x_outlet_beat_type = outlet_new(&x->x_obj, NULL); - x->x_outlet_beats_per_bar = outlet_new(&x->x_obj, NULL); - x->x_outlet_beats_per_minute = outlet_new(&x->x_obj, NULL); + x->x_outlet_info = outlet_new(&x->x_obj, NULL); x->x_pos = (jack_position_t*) getbytes(sizeof(jack_position_t)); status = jack_transport_connect(x); @@ -105,12 +92,22 @@ static void jack_transport_stoper(jack_transport_t * x) static void jack_transport_timebase(jack_transport_t * x) { jack_position_t pos; + t_atom ap[8]; const int rolling = (jack_transport_query(x->x_jack_client, &pos) == JackTransportRolling); - outlet_float(x->x_outlet_bar, pos.bar); - outlet_float(x->x_outlet_beat, pos.beat); - outlet_float(x->x_outlet_beat_type, pos.beat_type); - outlet_float(x->x_outlet_beats_per_bar, pos.beats_per_bar); - outlet_float(x->x_outlet_beats_per_minute, pos.beats_per_minute); + SETFLOAT(ap+0, pos.bar); + SETFLOAT(ap+1, pos.beat); + SETSYMBOL(ap+2, gensym("type")); + SETFLOAT(ap+3, pos.beat_type); + SETSYMBOL(ap+4, gensym("beats/bar")); + SETFLOAT(ap+5, pos.beats_per_bar); + SETSYMBOL(ap+6, gensym("bpm")); + SETFLOAT(ap+7, pos.beats_per_minute); + + outlet_anything(x->x_outlet_info, gensym("beat"), 2, ap+2); + outlet_anything(x->x_outlet_info, gensym("beat"), 2, ap+4); + outlet_anything(x->x_outlet_info, gensym("beat"), 2, ap+6); + outlet_anything(x->x_outlet_info, gensym("beat"), 1, ap+1); + outlet_anything(x->x_outlet_info, gensym("bar"), 1, ap+0); } static void jack_transport_bang(jack_transport_t * x) @@ -139,7 +136,7 @@ void jack_transport_setup(void) (t_newmethod)jack_transport_new, NULL, sizeof(jack_transport_t), CLASS_DEFAULT, 0); - class_addmethod(jack_transport_class, (t_method)jack_transport_starter, + class_addmethod(jack_transport_class, (t_method)jack_transport_starter, gensym("start"),0,0); class_addmethod(jack_transport_class, (t_method)jack_transport_stoper, gensym("stop"),0,0); -- cgit v1.2.1 From 6932ee2d22511226378218992b0005cb01eb235e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Thu, 30 Apr 2015 21:38:26 +0000 Subject: updated jack_transport help svn path=/trunk/externals/tb/; revision=17462 --- jack_transport/jack_transport-help.pd | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/jack_transport/jack_transport-help.pd b/jack_transport/jack_transport-help.pd index 4460085..f244c5d 100644 --- a/jack_transport/jack_transport-help.pd +++ b/jack_transport/jack_transport-help.pd @@ -1,13 +1,32 @@ -#N canvas 0 0 450 300 10; +#N canvas 617 189 486 323 10; #X obj 100 141 jack_transport; -#X floatatom 140 118 5 0 0 0 - - -; +#X floatatom 140 118 5 0 0 0 - - -, f 5; #X msg 191 120 stop; #X msg 191 97 start; -#X floatatom 87 174 9 0 0 0 - - -; #X obj 42 58 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; -#X connect 0 0 4 0; +#X obj 52 16 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1 +; +#X obj 190 178 route bar beat; +#X floatatom 237 223 0 0 0 0 - - -; +#X floatatom 288 243 0 0 0 0 - - -; +#X floatatom 340 263 0 0 0 0 - - -; +#X floatatom 392 283 0 0 0 0 - - -; +#X floatatom 156 233 0 0 0 0 - - -; +#X floatatom 100 173 0 0 0 0 - - -; +#X obj 237 201 route float type beats/bar bpm; +#X obj 43 35 metro 125; +#X connect 0 0 12 0; +#X connect 0 1 6 0; #X connect 1 0 0 0; #X connect 2 0 0 0; #X connect 3 0 0 0; -#X connect 5 0 0 0; +#X connect 4 0 0 0; +#X connect 5 0 14 0; +#X connect 6 0 11 0; +#X connect 6 1 13 0; +#X connect 13 0 7 0; +#X connect 13 1 8 0; +#X connect 13 2 9 0; +#X connect 13 3 10 0; +#X connect 14 0 4 0; -- cgit v1.2.1