aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Blechmann <timblech@users.sourceforge.net>2004-04-09 13:42:58 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:11:54 +0200
commit604a3ed6ad86c5e25f1a904c012639f821c4d999 (patch)
tree8afebec9e1b6e4b9f52c45d1711b669eefc28267
parent092e3f239e8108d161ad03fb7047d51853dd0008 (diff)
some updates
svn path=/trunk/externals/tb/; revision=1589
-rw-r--r--tbext/him.pd73
-rw-r--r--tbext/source/him.cpp153
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");
}