@@ -37,10 +37,9 @@ typedef struct _lor
37
37
} t_lor ;
38
38
39
39
40
-
41
40
static t_int * lor_perform (t_int * w )
42
41
{
43
- t_lor * x = (t_lor * )(w [1 ]);
42
+ t_lor * x = (t_lor * )(w [1 ]);
44
43
t_sample * in1 = (t_sample * )(w [2 ]);
45
44
t_sample * in2 = (t_sample * )(w [3 ]);
46
45
t_sample * in3 = (t_sample * )(w [4 ]);
@@ -49,60 +48,59 @@ static t_int *lor_perform(t_int *w)
49
48
t_sample * out2 = (t_sample * )(w [7 ]);
50
49
t_sample * out3 = (t_sample * )(w [8 ]);
51
50
int n = (int )(w [9 ]);
52
-
51
+
53
52
float x0 , y0 , z0 , x1 , y1 , z1 ;
54
53
float h , a , b , c ;
55
54
56
55
while (n -- )
57
56
{
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
75
73
* out1 ++ = x -> x = x1 ;
76
- * out2 ++ = x -> y = y1 ;
74
+ * out2 ++ = x -> y = y1 ;
77
75
* out3 ++ = x -> z = z1 ;
78
-
79
76
}
80
77
return (w + 10 );
81
78
}
82
79
83
80
84
81
void lor_tilde_free (t_lor * x )
85
82
{
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 );
92
89
}
93
90
94
91
95
92
static void lor_dsp (t_lor * x , t_signal * * sp )
96
93
{
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
+ );
106
104
}
107
105
108
106
@@ -113,7 +111,7 @@ void lor_initx(t_lor *x, int argcount, t_atom *argvec)
113
111
{
114
112
if (argvec [i ].a_type == A_FLOAT )
115
113
{
116
- x -> x = argvec [i ].a_w .w_float ;
114
+ x -> x = argvec [i ].a_w .w_float ;
117
115
}
118
116
}
119
117
}
@@ -124,7 +122,7 @@ void lor_inity(t_lor *x, int argcount, t_atom *argvec)
124
122
{
125
123
if (argvec [i ].a_type == A_FLOAT )
126
124
{
127
- x -> y = argvec [i ].a_w .w_float ;
125
+ x -> y = argvec [i ].a_w .w_float ;
128
126
}
129
127
}
130
128
}
@@ -135,7 +133,7 @@ void lor_initz(t_lor *x, int argcount, t_atom *argvec)
135
133
{
136
134
if (argvec [i ].a_type == A_FLOAT )
137
135
{
138
- x -> z = argvec [i ].a_w .w_float ;
136
+ x -> z = argvec [i ].a_w .w_float ;
139
137
}
140
138
}
141
139
}
@@ -163,13 +161,12 @@ static void *lor_new(void)
163
161
void lor_tilde_setup (void )
164
162
{
165
163
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 );
168
165
169
166
CLASS_MAINSIGNALIN (lor_class , t_lor , x_f );
170
167
171
168
class_addmethod (lor_class , (t_method )lor_dsp , gensym ("dsp" ), 0 );
172
169
class_addmethod (lor_class , (t_method )lor_initx , gensym ("initx" ), A_GIMME , 0 );
173
170
class_addmethod (lor_class , (t_method )lor_inity , gensym ("inity" ), A_GIMME , 0 );
174
171
class_addmethod (lor_class , (t_method )lor_initz , gensym ("initz" ), A_GIMME , 0 );
175
- }
172
+ }
0 commit comments