Skip to content

Commit

Permalink
dust changes
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Aug 15, 2024
1 parent 30fff48 commit c90d124
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 74 deletions.
27 changes: 6 additions & 21 deletions Code_source/Compiled/audio/dust2~.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef struct _dust2{
t_float x_sample_dur;
t_random_state x_rstate;
t_float x_density;
t_float *x_lastout;
int x_id;
int x_nchans;
int x_ch;
Expand All @@ -31,23 +30,19 @@ static t_int *dust2_perform(t_int *w){
int chs = (t_int)(w[2]); // number of channels in main input signal (density)
t_float *in1 = (t_float *)(w[3]);
t_float *out = (t_sample *)(w[4]);
t_float *lastout = x->x_lastout;
uint32_t *s1 = &x->x_rstate.s1;
uint32_t *s2 = &x->x_rstate.s2;
uint32_t *s3 = &x->x_rstate.s3;
for(int i = 0; i < x->x_n; i++){
for(int j = 0; j < x->x_nchans; j++){ // for 'n' out channels
t_float density = chs == 1 ? in1[i] : in1[j*x->x_n + i];
t_float thresh = density * x->x_sample_dur;
t_float scale = thresh > 0 ? 2./thresh : 0;
t_float density = chs == 1 ? in1[i] : in1[j*x->x_n + i];
t_float thresh = density * x->x_sample_dur;
t_float scale = thresh > 0 ? 2./thresh : 0;
t_float random = (t_float)(random_frand(s1, s2, s3) * 0.5 + 0.5);
t_float output = random < thresh ? (random * scale) - 1 : 0;
if(output != 0 && lastout[j] != 0)
output = 0;
out[j*x->x_n + i] = lastout[j] = output;
out[j*x->x_n + i] = output;
}
}
x->x_lastout = lastout;
return(w+5);
}

Expand All @@ -57,26 +52,16 @@ static void dust2_dsp(t_dust2 *x, t_signal **sp){
int chs = sp[0]->s_nchans;
if(chs == 1)
chs = x->x_ch;
if(x->x_nchans != chs){
x->x_lastout = (t_float *)resizebytes(x->x_lastout,
x->x_nchans * sizeof(t_float), chs * sizeof(t_float));
x->x_nchans = chs;
}
x->x_nchans = chs;
signal_setmultiout(&sp[1], x->x_nchans);
dsp_add(dust2_perform, 4, x, sp[0]->s_nchans, sp[0]->s_vec, sp[1]->s_vec);
}

static void *dust2_free(t_dust2 *x){
freebytes(x->x_lastout, x->x_nchans * sizeof(*x->x_lastout));
return(void *)x;
}

static void *dust2_new(t_symbol *s, int ac, t_atom *av){
t_dust2 *x = (t_dust2 *)pd_new(dust2_class);
x->x_id = random_get_id();
x->x_nchans = 1;
dust2_seed(x, s, 0, NULL);
x->x_lastout = (t_float *)getbytes(sizeof(*x->x_lastout));
x->x_ch = 1;
x->x_density = 0;
if(ac){
Expand Down Expand Up @@ -118,7 +103,7 @@ static void *dust2_new(t_symbol *s, int ac, t_atom *av){

void dust2_tilde_setup(void){
dust2_class = class_new(gensym("dust2~"), (t_newmethod)dust2_new,
(t_method)dust2_free, sizeof(t_dust2), CLASS_MULTICHANNEL, A_GIMME, 0);
0, sizeof(t_dust2), CLASS_MULTICHANNEL, A_GIMME, 0);
CLASS_MAINSIGNALIN(dust2_class, t_dust2, x_density);
class_addmethod(dust2_class, (t_method)dust2_dsp, gensym("dsp"), A_CANT, 0);
class_addmethod(dust2_class, (t_method)dust2_seed, gensym("seed"), A_GIMME, 0);
Expand Down
27 changes: 6 additions & 21 deletions Code_source/Compiled/audio/dust~.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef struct _dust{
t_float x_sample_dur;
t_random_state x_rstate;
t_float x_density;
t_float *x_lastout;
int x_id;
int x_nchans;
int x_ch;
Expand All @@ -31,23 +30,19 @@ static t_int *dust_perform(t_int *w){
int chs = (t_int)(w[2]); // number of channels in main input signal (density)
t_float *in = (t_float *)(w[3]);
t_float *out = (t_sample *)(w[4]);
t_float *lastout = x->x_lastout;
uint32_t *s1 = &x->x_rstate.s1;
uint32_t *s2 = &x->x_rstate.s2;
uint32_t *s3 = &x->x_rstate.s3;
for(int i = 0; i < x->x_n; i++){
for(int j = 0; j < x->x_nchans; j++){ // for 'n' out channels
t_float density = chs == 1 ? in[i] : in[j*x->x_n + i];
t_float thresh = density * x->x_sample_dur;
t_float scale = thresh > 0 ? 1./thresh : 0;
t_float density = chs == 1 ? in[i] : in[j*x->x_n + i];
t_float thresh = density * x->x_sample_dur;
t_float scale = thresh > 0 ? 1./thresh : 0;
t_float random = (t_float)(random_frand(s1, s2, s3) * 0.5 + 0.5);
t_float output = random < thresh ? random * scale : 0;
if(output != 0 && lastout[j] != 0)
output = 0;
out[j*x->x_n + i] = lastout[j] = output;
out[j*x->x_n + i] = output;
}
}
x->x_lastout = lastout;
return(w+5);
}

Expand All @@ -57,26 +52,16 @@ static void dust_dsp(t_dust *x, t_signal **sp){
int chs = sp[0]->s_nchans;
if(chs == 1)
chs = x->x_ch;
if(x->x_nchans != chs){
x->x_lastout = (t_float *)resizebytes(x->x_lastout,
x->x_nchans * sizeof(t_float), chs * sizeof(t_float));
x->x_nchans = chs;
}
x->x_nchans = chs;
signal_setmultiout(&sp[1], x->x_nchans);
dsp_add(dust_perform, 4, x, sp[0]->s_nchans, sp[0]->s_vec, sp[1]->s_vec);
}

static void *dust_free(t_dust *x){
freebytes(x->x_lastout, x->x_nchans * sizeof(*x->x_lastout));
return(void *)x;
}

static void *dust_new(t_symbol *s, int ac, t_atom *av){
t_dust *x = (t_dust *)pd_new(dust_class);
x->x_id = random_get_id();
x->x_nchans = 1;
dust_seed(x, s, 0, NULL);
x->x_lastout = (t_float *)getbytes(sizeof(*x->x_lastout));
x->x_ch = 1;
x->x_density = 0;
if(ac){
Expand Down Expand Up @@ -118,7 +103,7 @@ static void *dust_new(t_symbol *s, int ac, t_atom *av){

void dust_tilde_setup(void){
dust_class = class_new(gensym("dust~"), (t_newmethod)dust_new,
(t_method)dust_free, sizeof(t_dust), CLASS_MULTICHANNEL, A_GIMME, 0);
0, sizeof(t_dust), CLASS_MULTICHANNEL, A_GIMME, 0);
CLASS_MAINSIGNALIN(dust_class, t_dust, x_density);
class_addmethod(dust_class, (t_method)dust_dsp, gensym("dsp"), A_CANT, 0);
class_addmethod(dust_class, (t_method)dust_seed, gensym("seed"), A_GIMME, 0);
Expand Down
4 changes: 2 additions & 2 deletions Documentation/Help-files/dust2~-help.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 538 29 563 532 10;
#N canvas 538 38 563 532 10;
#X obj 3 3 cnv 15 301 42 empty empty dust2~ 20 20 2 37 #e0e0e0 #000000 0;
#X obj 307 4 cnv 15 250 40 empty empty empty 12 13 0 18 #7c7c7c #e0e4dc 0;
#N canvas 0 22 450 278 (subpatch) 0;
Expand Down Expand Up @@ -62,7 +62,6 @@
#X text 217 360 - set number of output channels;
#X text 147 447 -ch <float>: number of output channels (default 1);
#X text 218 396 - random impulses;
#X text 53 87 [dust~] is based on SuperCollider's "Dust2" UGEN and outputs random impulse values (from -1 to 1) at random times according to a density parameter. The difference to SuperCollider's is that it only produces actual impulses (one non zero value in between 0 valued samples). It has support for multichannel output., f 71;
#N canvas 494 125 607 338 multichannel 0;
#X obj 100 87 hsl 128 15 1 5000 1 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1;
#X obj 97 116 nbx 8 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
Expand All @@ -85,6 +84,7 @@
#X connect 10 0 6 0;
#X restore 430 277 pd multichannel;
#X text 145 360 ch <float>;
#X text 53 87 [dust~] is based on SuperCollider's "Dust2" UGEN and outputs random impulse values (from -1 to 1) at random times according to a density parameter. At high frequencies there's a good chance of consecutive non zero values. To the extreme \, it becomes white noiset., f 68;
#X connect 10 0 12 0;
#X connect 12 0 14 0;
#X connect 14 0 11 0;
60 changes: 30 additions & 30 deletions Documentation/Help-files/dust~-help.pd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#N canvas 481 51 560 535 10;
#X obj 218 173 hsl 128 15 1 5000 1 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1;
#X obj 215 255 else/out~;
#N canvas 481 51 562 523 10;
#X obj 218 163 hsl 128 15 1 5000 1 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1;
#X obj 215 245 else/out~;
#X obj 3 4 cnv 15 301 42 empty empty dust~ 20 20 2 37 #e0e0e0 #000000 0;
#X obj 307 5 cnv 15 250 40 empty empty empty 12 13 0 18 #7c7c7c #e0e4dc 0;
#N canvas 0 22 450 278 (subpatch) 0;
Expand All @@ -15,26 +15,26 @@
#X obj 479 12 cnv 10 10 10 empty empty Locus 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 465 27 cnv 10 10 10 empty empty ELSE 0 6 2 13 #7c7c7c #e0e4dc 0;
#X obj 93 41 cnv 4 4 4 empty empty impulses 0 28 2 18 #e0e0e0 #000000 0;
#X obj 4 508 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X obj 4 321 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 4 388 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 4 475 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 107 397 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 106 330 cnv 17 3 50 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 169 397 signal;
#X text 177 484 1) float;
#X obj 215 202 nbx 8 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X text 299 203 density;
#X text 218 330 - density (rate) of random impulses;
#X text 238 483 - density (default 0);
#X obj 215 228 else/dust~ 1;
#X text 133 331 float/signal;
#X text 133 347 seed <float>;
#X text 40 247 see also:;
#X obj 37 269 else/dust2~;
#X obj 6 424 cnv 3 550 3 empty empty flags 8 12 0 13 #dcdcdc #000000 0;
#X text 135 433 -seed <float>: seed value (default: unique internal);
#X text 217 347 - a float sets seed \, no float sets a unique internal;
#X obj 4 498 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X obj 4 311 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 4 378 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 4 465 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 107 387 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 106 320 cnv 17 3 50 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 169 387 signal;
#X text 177 474 1) float;
#X obj 215 192 nbx 8 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X text 299 193 density;
#X text 218 320 - density (rate) of random impulses;
#X text 238 473 - density (default 0);
#X obj 215 218 else/dust~ 1;
#X text 133 321 float/signal;
#X text 133 337 seed <float>;
#X text 40 237 see also:;
#X obj 37 259 else/dust2~;
#X obj 6 414 cnv 3 550 3 empty empty flags 8 12 0 13 #dcdcdc #000000 0;
#X text 135 423 -seed <float>: seed value (default: unique internal);
#X text 217 337 - a float sets seed \, no float sets a unique internal;
#N canvas 777 84 466 384 seed 0;
#X text 64 15 Pseudo random number generators aren't true random number generators. Instead \, an algorithm is used to provide a sequence of numbers that seems random. The same sequence can be reproduced if you set a "seed" value \, which can be any integer number., f 57;
#X text 64 129 You can set a seed with the '-seed' flag. If you don't supply it \, each object gets its own seed internal seed. If you send a 'seed' message without float \, the object also gets a unique seed value., f 57;
Expand All @@ -58,8 +58,8 @@
#X connect 10 0 12 0;
#X connect 11 0 4 0;
#X connect 12 0 5 0;
#X restore 481 254 pd seed;
#X text 218 398 - random positive impulses;
#X restore 481 244 pd seed;
#X text 218 388 - random positive impulses;
#N canvas 494 125 607 338 multichannel 0;
#X obj 100 87 hsl 128 15 1 5000 1 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1;
#X obj 97 116 nbx 8 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
Expand All @@ -80,11 +80,11 @@
#X connect 7 0 10 0;
#X connect 8 0 3 0;
#X connect 10 0 6 0;
#X restore 433 280 pd multichannel;
#X text 53 95 [dust~] is based on SuperCollider's "Dust" UGEN and outputs random impulse values (only positive values up to 1) at random times according to a density parameter. The difference to SuperCollider's is that it only produces actual impulses (one non zero value in between 0 valued samples). It has support for multichannel output., f 71;
#X text 147 449 -ch <float>: number of output channels (default 1);
#X text 145 363 ch <float>;
#X text 217 362 - set number of output channels;
#X restore 433 270 pd multichannel;
#X text 147 439 -ch <float>: number of output channels (default 1);
#X text 145 353 ch <float>;
#X text 217 352 - set number of output channels;
#X text 53 95 [dust~] is based on SuperCollider's "Dust" UGEN and outputs random impulse values (only positive values up to 1) at random times according to a density parameter. At high frequencies there's a good chance of consecutive non zero values. To the extreme \, it becomes white noise with a DC offset., f 71;
#X connect 0 0 20 0;
#X connect 20 0 24 0;
#X connect 24 0 1 0;

0 comments on commit c90d124

Please sign in to comment.