Skip to content

Commit

Permalink
decide
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Feb 21, 2024
1 parent 0ef65b6 commit 96630c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
9 changes: 4 additions & 5 deletions cyclone_objects/binaries/audio/rand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 7 additions & 18 deletions cyclone_objects/binaries/control/decide.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion documentation/help_files/decide-help.pd
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 96630c9

Please sign in to comment.