diff --git a/src/lor~.c b/src/lor~.c index 4179d2e..11f195d 100755 --- a/src/lor~.c +++ b/src/lor~.c @@ -37,10 +37,9 @@ typedef struct _lor } t_lor; - static t_int *lor_perform(t_int *w) { - t_lor *x = (t_lor *)(w[1]); + t_lor *x = (t_lor *)(w[1]); t_sample *in1 = (t_sample *)(w[2]); t_sample *in2 = (t_sample *)(w[3]); t_sample *in3 = (t_sample *)(w[4]); @@ -49,33 +48,31 @@ static t_int *lor_perform(t_int *w) t_sample *out2 = (t_sample *)(w[7]); t_sample *out3 = (t_sample *)(w[8]); int n = (int)(w[9]); - + float x0, y0, z0, x1, y1, z1; float h, a, b, c; while (n--) { - h= *in1++; - a= *in2++; - b=*in3++; - c=*in4++; - - x0 = x->x; - y0 = x->y; - z0 = x->z; - - x1 = x0 + h * a * (y0 - x0); - y1 = y0 + h * (x0 * (b - z0) - y0); - z1 = z0 + h * (x0 * y0 - c * z0); - - /* - distance = sqrt((x1 * x1) + (y1 * y1) + (z1 * z1)); - */ - + h = *in1++; + a = *in2++; + b = *in3++; + c = *in4++; + + // get initial conditions + x0 = x->x; + y0 = x->y; + z0 = x->z; + + // euler's method for differentiation + x1 = x0 + h * a * (y0 - x0); + y1 = y0 + h * (x0 * (b - z0) - y0); + z1 = z0 + h * (x0 * y0 - c * z0); + + // feed the out buffer and the position with the new position *out1++ = x->x = x1; - *out2++ = x->y = y1; + *out2++ = x->y = y1; *out3++ = x->z = z1; - } return (w+10); } @@ -83,26 +80,27 @@ static t_int *lor_perform(t_int *w) void lor_tilde_free(t_lor *x) { -inlet_free(x->in2); -inlet_free(x->in3); -inlet_free(x->in4); - outlet_free(x->out1); - outlet_free(x->out2); - outlet_free(x->out3); + inlet_free(x->in2); + inlet_free(x->in3); + inlet_free(x->in4); + outlet_free(x->out1); + outlet_free(x->out2); + outlet_free(x->out3); } static void lor_dsp(t_lor *x, t_signal **sp) { - dsp_add(lor_perform, 9, x, - sp[0]->s_vec, - sp[1]->s_vec, - sp[2]->s_vec, - sp[3]->s_vec, - sp[4]->s_vec, - sp[5]->s_vec, - sp[6]->s_vec, - sp[0]->s_n); + dsp_add(lor_perform, 9, x, + sp[0]->s_vec, + sp[1]->s_vec, + sp[2]->s_vec, + sp[3]->s_vec, + sp[4]->s_vec, + sp[5]->s_vec, + sp[6]->s_vec, + sp[0]->s_n + ); } @@ -113,7 +111,7 @@ void lor_initx(t_lor *x, int argcount, t_atom *argvec) { if (argvec[i].a_type == A_FLOAT) { - x->x = argvec[i].a_w.w_float; + x->x = argvec[i].a_w.w_float; } } } @@ -124,7 +122,7 @@ void lor_inity(t_lor *x, int argcount, t_atom *argvec) { if (argvec[i].a_type == A_FLOAT) { - x->y = argvec[i].a_w.w_float; + x->y = argvec[i].a_w.w_float; } } } @@ -135,7 +133,7 @@ void lor_initz(t_lor *x, int argcount, t_atom *argvec) { if (argvec[i].a_type == A_FLOAT) { - x->z = argvec[i].a_w.w_float; + x->z = argvec[i].a_w.w_float; } } } @@ -163,8 +161,7 @@ static void *lor_new(void) void lor_tilde_setup(void) { lor_class = class_new(gensym("lor~"), - (t_newmethod)lor_new, 0, - sizeof(t_lor), 0, A_DEFFLOAT, 0); + (t_newmethod)lor_new, 0, sizeof(t_lor), 0, A_DEFFLOAT, 0); CLASS_MAINSIGNALIN(lor_class, t_lor, x_f); @@ -172,4 +169,4 @@ void lor_tilde_setup(void) class_addmethod(lor_class, (t_method)lor_initx, gensym("initx"), A_GIMME, 0); class_addmethod(lor_class, (t_method)lor_inity, gensym("inity"), A_GIMME, 0); class_addmethod(lor_class, (t_method)lor_initz, gensym("initz"), A_GIMME, 0); -} \ No newline at end of file +}