From 420ada2dde4af8d71bc1d9c6988311961cf47f1b Mon Sep 17 00:00:00 2001 From: daniel aschauer Date: Fri, 9 Jan 2009 17:23:55 +0000 Subject: svn path=/trunk/externals/algocomp/; revision=10494 --- ifs.c.old | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 ifs.c.old (limited to 'ifs.c.old') diff --git a/ifs.c.old b/ifs.c.old new file mode 100755 index 0000000..670de60 --- /dev/null +++ b/ifs.c.old @@ -0,0 +1,77 @@ +#include "m_pd.h" +#include +#include +#include + +static t_class *ifs_class; + + +/* + * An interated function system music example + * a more general approach is needed. + */ +typedef struct _ifs { + t_object x_obj; + t_float R1,R2,S1,S2; + t_float T1[6],T2[6]; + t_float A[6], B[6]; + t_float C[6], D[6],P[6]; + t_float x,y; + t_outlet *x_out,*y_out, *i_out; +} t_ifs; + + +void ifs_bang(t_ifs *x) +{ +float r = ((float) rand())/RAND_MAX; +int i = 0; +while (r > x->P[i]) +i++; +x->x = x->A[i]*x->x + x->B[i]*x->y + x->T1[i]; +x->y = x->C[i]*x->x + x->D[i]*x->y + x->T2[i]; +outlet_float(x->x_out,x->x); +outlet_float(x->y_out,x->y); +outlet_float(x->i_out,r); +} + + + +void *ifs_new(t_floatarg f1) +{ + x->nr_functions = 3; + t_float R1[6],R2[6],S1[6],S2[6]; + t_ifs *x = (t_ifs *)pd_new(ifs_class); + t_int i; + t_float p = 1/x->nr_functions; + R1[0]=R1[1]=R1[2]=R1[3]=R1[4]=R1[5]= 1; + R2[0]=R2[1]=R2[2]=R2[3]=R2[4]=R2[5]= 0; + S1[0]=S1[1]=S1[2]=S1[3]=S1[4]=S1[5]= 0.5;//0.33333; + S2[0]=S2[1]=S2[2]=S2[3]=S2[4]=S2[5]= 1;//0.33333; + x->T1[0] = 0; + x->T2[0] = 2; + x->T1[1] = 1.5; + x->T2[1] = 1; + x->T1[2] = 1.5; + x->T2[2] = -1; + x->T1[3] = 0; + x->T2[3] = -2; + x->T1[4] = -1.5; + x->T2[4] = -1; + x->T1[5] = -1.5; + x->T2[5] = 1; + for (i = 0;i<6;i++) { + x->A[i] = S1[i]*cos(R1[i]); + x->B[i] = -S2[i]*sin(R2[i]); + x->C[i] = S1[i]*sin(R1[i]); + x->D[i] = S2[i]*cos(R2[i]); + x->P[i] = p*(i+1); + } + x->x = 0; + x->y = 0; + x->x_out = outlet_new(&x->x_obj,&s_float); + x->y_out = outlet_new(&x->x_obj,&s_float); + x->i_out = outlet_new(&x->x_obj,&s_float); + post("ifs initialized"); + return (void *)x; +} + -- cgit v1.2.1