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 (limited to 'tbext') 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