@@ -37,10 +37,9 @@ typedef struct _lor
3737} t_lor ;
3838
3939
40-
4140static t_int * lor_perform (t_int * w )
4241{
43- t_lor * x = (t_lor * )(w [1 ]);
42+ t_lor * x = (t_lor * )(w [1 ]);
4443 t_sample * in1 = (t_sample * )(w [2 ]);
4544 t_sample * in2 = (t_sample * )(w [3 ]);
4645 t_sample * in3 = (t_sample * )(w [4 ]);
@@ -49,60 +48,59 @@ static t_int *lor_perform(t_int *w)
4948 t_sample * out2 = (t_sample * )(w [7 ]);
5049 t_sample * out3 = (t_sample * )(w [8 ]);
5150 int n = (int )(w [9 ]);
52-
51+
5352 float x0 , y0 , z0 , x1 , y1 , z1 ;
5453 float h , a , b , c ;
5554
5655 while (n -- )
5756 {
58- h = * in1 ++ ;
59- a = * in2 ++ ;
60- b = * in3 ++ ;
61- c = * in4 ++ ;
62-
63- x0 = x -> x ;
64- y0 = x -> y ;
65- z0 = x -> z ;
66-
67- x1 = x0 + h * a * (y0 - x0 );
68- y1 = y0 + h * (x0 * (b - z0 ) - y0 );
69- z1 = z0 + h * (x0 * y0 - c * z0 );
70-
71- /*
72- distance = sqrt((x1 * x1) + (y1 * y1) + (z1 * z1));
73- */
74-
57+ h = * in1 ++ ;
58+ a = * in2 ++ ;
59+ b = * in3 ++ ;
60+ c = * in4 ++ ;
61+
62+ // get initial conditions
63+ x0 = x -> x ;
64+ y0 = x -> y ;
65+ z0 = x -> z ;
66+
67+ // euler's method for differentiation
68+ x1 = x0 + h * a * (y0 - x0 );
69+ y1 = y0 + h * (x0 * (b - z0 ) - y0 );
70+ z1 = z0 + h * (x0 * y0 - c * z0 );
71+
72+ // feed the out buffer and the position with the new position
7573 * out1 ++ = x -> x = x1 ;
76- * out2 ++ = x -> y = y1 ;
74+ * out2 ++ = x -> y = y1 ;
7775 * out3 ++ = x -> z = z1 ;
78-
7976 }
8077 return (w + 10 );
8178}
8279
8380
8481void lor_tilde_free (t_lor * x )
8582{
86- inlet_free (x -> in2 );
87- inlet_free (x -> in3 );
88- inlet_free (x -> in4 );
89- outlet_free (x -> out1 );
90- outlet_free (x -> out2 );
91- outlet_free (x -> out3 );
83+ inlet_free (x -> in2 );
84+ inlet_free (x -> in3 );
85+ inlet_free (x -> in4 );
86+ outlet_free (x -> out1 );
87+ outlet_free (x -> out2 );
88+ outlet_free (x -> out3 );
9289}
9390
9491
9592static void lor_dsp (t_lor * x , t_signal * * sp )
9693{
97- dsp_add (lor_perform , 9 , x ,
98- sp [0 ]-> s_vec ,
99- sp [1 ]-> s_vec ,
100- sp [2 ]-> s_vec ,
101- sp [3 ]-> s_vec ,
102- sp [4 ]-> s_vec ,
103- sp [5 ]-> s_vec ,
104- sp [6 ]-> s_vec ,
105- sp [0 ]-> s_n );
94+ dsp_add (lor_perform , 9 , x ,
95+ sp [0 ]-> s_vec ,
96+ sp [1 ]-> s_vec ,
97+ sp [2 ]-> s_vec ,
98+ sp [3 ]-> s_vec ,
99+ sp [4 ]-> s_vec ,
100+ sp [5 ]-> s_vec ,
101+ sp [6 ]-> s_vec ,
102+ sp [0 ]-> s_n
103+ );
106104}
107105
108106
@@ -113,7 +111,7 @@ void lor_initx(t_lor *x, int argcount, t_atom *argvec)
113111 {
114112 if (argvec [i ].a_type == A_FLOAT )
115113 {
116- x -> x = argvec [i ].a_w .w_float ;
114+ x -> x = argvec [i ].a_w .w_float ;
117115 }
118116 }
119117}
@@ -124,7 +122,7 @@ void lor_inity(t_lor *x, int argcount, t_atom *argvec)
124122 {
125123 if (argvec [i ].a_type == A_FLOAT )
126124 {
127- x -> y = argvec [i ].a_w .w_float ;
125+ x -> y = argvec [i ].a_w .w_float ;
128126 }
129127 }
130128}
@@ -135,7 +133,7 @@ void lor_initz(t_lor *x, int argcount, t_atom *argvec)
135133 {
136134 if (argvec [i ].a_type == A_FLOAT )
137135 {
138- x -> z = argvec [i ].a_w .w_float ;
136+ x -> z = argvec [i ].a_w .w_float ;
139137 }
140138 }
141139}
@@ -163,13 +161,12 @@ static void *lor_new(void)
163161void lor_tilde_setup (void )
164162{
165163 lor_class = class_new (gensym ("lor~" ),
166- (t_newmethod )lor_new , 0 ,
167- sizeof (t_lor ), 0 , A_DEFFLOAT , 0 );
164+ (t_newmethod )lor_new , 0 , sizeof (t_lor ), 0 , A_DEFFLOAT , 0 );
168165
169166 CLASS_MAINSIGNALIN (lor_class , t_lor , x_f );
170167
171168 class_addmethod (lor_class , (t_method )lor_dsp , gensym ("dsp" ), 0 );
172169 class_addmethod (lor_class , (t_method )lor_initx , gensym ("initx" ), A_GIMME , 0 );
173170 class_addmethod (lor_class , (t_method )lor_inity , gensym ("inity" ), A_GIMME , 0 );
174171 class_addmethod (lor_class , (t_method )lor_initz , gensym ("initz" ), A_GIMME , 0 );
175- }
172+ }
0 commit comments