From 96630c9606f9ee4a3c2a09854826e11281c45d1b Mon Sep 17 00:00:00 2001 From: porres Date: Wed, 21 Feb 2024 16:36:49 -0300 Subject: [PATCH] decide --- cyclone_objects/binaries/audio/rand.c | 9 ++++---- cyclone_objects/binaries/control/decide.c | 25 +++++++---------------- documentation/help_files/decide-help.pd | 2 +- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/cyclone_objects/binaries/audio/rand.c b/cyclone_objects/binaries/audio/rand.c index f8c46e2e..1dc58619 100644 --- a/cyclone_objects/binaries/audio/rand.c +++ b/cyclone_objects/binaries/audio/rand.c @@ -14,7 +14,6 @@ typedef struct _rand{ double x_nextphase; float x_rcpsr; float x_sr; - int x_state; float x_target; float x_scaling; // LATER use phase increment unsigned int x_seed; @@ -44,10 +43,10 @@ static t_int *rand_perform(t_int *w){ if(rate < 0) rate = 0; if(ph > lastph){ - int state = x->x_state; + unsigned int state = x->x_seed; float newtarget = ((float)((state & 0x7fffffff) - 0x40000000)) * (float)(1.0 / 0x40000000); - x->x_state = state * 435898247 + 382842987; + x->x_seed = state * 435898247 + 382842987; x->x_scaling = scaling = target - newtarget; x->x_target = target = newtarget; } @@ -76,8 +75,8 @@ static void rand_dsp(t_rand *x, t_signal **sp){ static void *rand_new(t_floatarg f){ t_rand *x = (t_rand *)pd_new(rand_class); x->x_id = cyclone_random_get_id(); - x->x_seed = (int)(time(NULL) * x->x_id * 1319); - x->x_state = x->x_seed * 435898247 + 382842987; + x->x_seed = (unsigned int)(time(NULL) * x->x_id * 1319); + x->x_seed = x->x_seed * 435898247 + 382842987; x->x_lastphase = 0.; x->x_nextphase = 1.; /* start from 0, force retargetting */ x->x_target = x->x_scaling = 0; diff --git a/cyclone_objects/binaries/control/decide.c b/cyclone_objects/binaries/control/decide.c index 7501e26e..b21fb821 100644 --- a/cyclone_objects/binaries/control/decide.c +++ b/cyclone_objects/binaries/control/decide.c @@ -14,21 +14,12 @@ typedef struct _decide{ static t_class *decide_class; -#define RBIT1 1 // random bit algo from NR (method II in 7.4) -#define RBIT2 2 -#define RBIT5 16 -#define RBIT18 131072 -#define RBIT_MASK (RBIT1 + RBIT2 + RBIT5) - static void decide_bang(t_decide *x){ - if(x->x_seed & RBIT18){ - x->x_seed = ((x->x_seed ^ RBIT_MASK) << 1) | RBIT1; - outlet_float(((t_object *)x)->ob_outlet, 1); - } - else{ - x->x_seed <<= 1; - outlet_float(((t_object *)x)->ob_outlet, 0); - } + unsigned int state = x->x_seed; + float rand = ((float)((state & 0x7fffffff) - 0x40000000)) + * (float)(1.0 / 0x40000000); + x->x_seed = state * 435898247 + 382842987; + outlet_float(((t_object *)x)->ob_outlet, rand > 0); } static void decide_float(t_decide *x, t_float f){ @@ -44,10 +35,8 @@ static void decide_ft1(t_decide *x, t_floatarg f){ static void *decide_new(t_floatarg f){ t_decide *x = (t_decide *)pd_new(decide_class); - x->x_id = cyclone_random_get_id(); - x->x_seed = (int)f; - if(x->x_seed == 0) - x->x_seed = (int)(time(NULL)*x->x_id); + x->x_seed = (int)(time(NULL) * x->x_id * 1319); + x->x_state = x->x_seed * 435898247 + 382842987; inlet_new((t_object *)x, (t_pd *)x, &s_float, gensym("ft1")); outlet_new((t_object *)x, &s_float); return(x); diff --git a/documentation/help_files/decide-help.pd b/documentation/help_files/decide-help.pd index 24aa3e45..796df07d 100644 --- a/documentation/help_files/decide-help.pd +++ b/documentation/help_files/decide-help.pd @@ -33,8 +33,8 @@ #X obj 166 200 s \$0-bang; #X text 188 267 same as bang; #X text 186 372 sets the seed (default a random internal one); -#X obj 2 3 ./header dcide; #X text 22 63 Randomly output 0 or 1; +#X obj 2 3 ./header decide; #X connect 20 0 23 0; #X connect 20 0 24 0; #X connect 23 0 21 0;