Skip to content

Commit

Permalink
amp randomness for velvet~
Browse files Browse the repository at this point in the history
Update 7.[velvet~].[dust2~].pd
  • Loading branch information
porres committed Aug 20, 2024
1 parent 5a4489f commit 76356ea
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 94 deletions.
39 changes: 29 additions & 10 deletions Code_source/Compiled/audio/velvet~.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ typedef struct _velvet{
t_int x_ch;
t_int x_ch2;
t_int x_ch3;
t_int x_ch4;
t_inlet *x_inlet_reg;
t_inlet *x_inlet_ireg;
t_inlet *x_inlet_bias;
t_outlet *x_outlet;
double x_sr_rec;
Expand Down Expand Up @@ -51,7 +53,8 @@ static t_int *velvet_perform(t_int *w){
t_float *in1 = (t_float *)(w[3]);
t_float *in2 = (t_float *)(w[4]); // bias
t_float *in3 = (t_float *)(w[5]); // reg
t_float *out = (t_float *)(w[6]);
t_float *in4 = (t_float *)(w[6]); // ireg
t_float *out = (t_float *)(w[7]);
double *phase = x->x_phase;
double *lastphase = x->x_lastphase;
for(int j = 0; j < x->x_nchans; j++){
Expand All @@ -63,9 +66,16 @@ static t_int *velvet_perform(t_int *w){
bias = bias > 1 ? 1 : bias < 0 ? 0 : bias; // clip bias
t_float reg = x->x_ch3 == 1 ? in3[i] : in3[j*n + i];
reg = reg > 1 ? 1 : reg < 0 ? 0 : reg; // clip reg
t_float ireg = x->x_ch4 == 1 ? in4[i] : in4[j*n + i];
ireg = ireg > 1 ? 1 : ireg < 0 ? 0 : ireg; // clip ireg
t_float imp = 0;
if(phase[j] >= x->x_rand[j] && ((lastphase[j] < x->x_rand[j]) || (x->x_1st[j])))
imp = velvet_random(x) > bias ? 1 : -1;
if(phase[j] >= x->x_rand[j] && ((lastphase[j] < x->x_rand[j]) || (x->x_1st[j]))){
imp = 1;
if(ireg > 0)
imp = imp - (velvet_random(x) * ireg);
if(velvet_random(x) > bias)
imp *= -1;
}
out[j*n + i] = imp;
x->x_1st[j] = 0;
if(phase[j] >= 1.){
Expand All @@ -80,15 +90,15 @@ static t_int *velvet_perform(t_int *w){
}
x->x_phase = phase;
x->x_lastphase = lastphase;
return(w+7);
return(w+8);
}

static void velvet_dsp(t_velvet *x, t_signal **sp){
x->x_n = sp[0]->s_n, x->x_sr_rec = 1.0 / (double)sp[0]->s_sr;
int chs = sp[0]->s_nchans;
if(chs == 1)
chs = x->x_ch;
x->x_ch2 = sp[1]->s_nchans, x->x_ch3 = sp[2]->s_nchans;
x->x_ch2 = sp[1]->s_nchans, x->x_ch3 = sp[2]->s_nchans, x->x_ch4 = sp[3]->s_nchans;
if(x->x_nchans != chs){
x->x_lastphase = (double *)resizebytes(x->x_lastphase,
x->x_nchans * sizeof(double), chs * sizeof(double));
Expand All @@ -102,20 +112,22 @@ static void velvet_dsp(t_velvet *x, t_signal **sp){
for(int j = 0; j < x->x_nchans; j++)
x->x_rand[j] = velvet_random(x);
}
signal_setmultiout(&sp[3], x->x_nchans);
signal_setmultiout(&sp[4], x->x_nchans);
if((x->x_ch2 > 1 && x->x_ch2 != x->x_nchans)
|| (x->x_ch3 > 1 && x->x_ch3 != x->x_nchans)){
dsp_add_zero(sp[3]->s_vec, x->x_nchans*x->x_n);
|| (x->x_ch3 > 1 && x->x_ch3 != x->x_nchans)
|| (x->x_ch4 > 1 && x->x_ch4 != x->x_nchans)){
dsp_add_zero(sp[4]->s_vec, x->x_nchans*x->x_n);
pd_error(x, "[velvet~]: channel sizes mismatch");
return;
}
dsp_add(velvet_perform, 6, x, sp[0]->s_nchans, sp[0]->s_vec,
sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec);
dsp_add(velvet_perform, 7, x, sp[0]->s_nchans, sp[0]->s_vec,
sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec);
}

static void *velvet_free(t_velvet *x){
inlet_free(x->x_inlet_bias);
inlet_free(x->x_inlet_reg);
inlet_free(x->x_inlet_ireg);
outlet_free(x->x_outlet);
freebytes(x->x_phase, x->x_nchans * sizeof(*x->x_phase));
freebytes(x->x_lastphase, x->x_nchans * sizeof(*x->x_lastphase));
Expand All @@ -138,6 +150,7 @@ static void *velvet_new(t_symbol *s, int ac, t_atom *av){
x->x_ch = 1;
float bias = 0.5;
float reg = 0;
float ireg = 0;
velvet_seed(x, s, 0, NULL);
if(ac){
while(av->a_type == A_SYMBOL){
Expand Down Expand Up @@ -170,6 +183,10 @@ static void *velvet_new(t_symbol *s, int ac, t_atom *av){
if(ac && av->a_type == A_FLOAT){
reg = av->a_w.w_float;
ac--, av++;
if(ac && av->a_type == A_FLOAT){
ireg = av->a_w.w_float;
ac--, av++;
}
}
}
}
Expand All @@ -178,6 +195,8 @@ static void *velvet_new(t_symbol *s, int ac, t_atom *av){
pd_float((t_pd *)x->x_inlet_bias, bias);
x->x_inlet_reg = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal);
pd_float((t_pd *)x->x_inlet_reg, reg);
x->x_inlet_ireg = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal);
pd_float((t_pd *)x->x_inlet_reg, ireg);
x->x_outlet = outlet_new(&x->x_obj, &s_signal);
return(x);
errstate:
Expand Down
134 changes: 73 additions & 61 deletions Documentation/Help-files/velvet~-help.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 587 48 560 629 10;
#N canvas 587 48 560 667 10;
#X obj 306 4 cnv 15 250 40 empty empty empty 12 13 0 18 #7c7c7c #e0e4dc 0;
#N canvas 382 141 749 319 (subpatch) 0;
#X coords 0 -1 1 1 252 42 2 100 100;
Expand All @@ -14,31 +14,29 @@
#N canvas 0 22 450 278 (subpatch) 0;
#X coords 0 1 100 -1 302 42 1 0 0;
#X restore 3 3 graph;
#X obj 200 288 else/out~;
#X obj 3 350 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 449 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 540 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 95 458 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 3 603 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X text 182 458 signal -;
#X obj 95 402 cnv 17 3 17 empty empty 1 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 138 423 float/signal -;
#X obj 95 422 cnv 17 3 17 empty empty 2 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 138 403 float/signal -;
#X text 173 548 1) float;
#X text 239 548 - frequency in hertz (default 0);
#X text 173 565 2) float;
#X obj 3 483 cnv 3 550 3 empty empty flags 8 12 0 13 #dcdcdc #000000 0;
#X obj 95 359 cnv 17 3 35 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 228 403 set polarity bias (0 - 1);
#X text 228 423 set regularity (0 - 1);
#X text 243 458 velvet noise signal;
#X text 239 565 - polarity bias (default 0.5), f 32;
#X text 239 582 - regularity (default 0), f 32;
#X text 173 581 3) float;
#X text 135 377 seed <float>;
#X text 216 377 - a float sets seed \, no float sets a unique internal;
#X text 130 493 -seed <float>: sets seed (default: unique internal);
#X obj 200 275 else/out~;
#X obj 3 342 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 461 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 552 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 95 470 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 3 635 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X text 182 470 signal -;
#X obj 95 394 cnv 17 3 17 empty empty 1 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 138 415 float/signal -;
#X obj 95 414 cnv 17 3 17 empty empty 2 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 138 395 float/signal -;
#X text 153 560 1) float;
#X text 219 560 - frequency in hertz (default 0), f 36;
#X text 153 577 2) float;
#X obj 3 495 cnv 3 550 3 empty empty flags 8 12 0 13 #dcdcdc #000000 0;
#X obj 95 351 cnv 17 3 35 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 228 395 set polarity bias (0 - 1);
#X text 243 470 velvet noise signal;
#X text 219 577 - polarity bias (default 0.5), f 36;
#X text 153 593 3) float;
#X text 135 369 seed <float>;
#X text 216 369 - a float sets seed \, no float sets a unique internal;
#X text 130 505 -seed <float>: sets seed (default: unique internal);
#N canvas 777 151 497 399 seed 0;
#X text 75 11 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 75 125 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 @@ -62,7 +60,7 @@
#X connect 11 0 13 0;
#X connect 12 0 7 0;
#X connect 13 0 6 0;
#X restore 477 296 pd seed;
#X restore 477 284 pd seed;
#N canvas 548 154 665 473 multichannel 0;
#X obj 100 97 hsl 128 15 4.1 44100 1 0 empty empty empty -2 -8 0 10 #dcdcdc #000000 #000000 0 1;
#X obj 97 126 nbx 8 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
Expand Down Expand Up @@ -90,41 +88,55 @@
#X connect 13 0 8 2;
#X connect 14 0 13 1;
#X connect 15 0 13 0;
#X restore 429 318 pd multichannel;
#N canvas 730 240 504 521 bias/regularity 0;
#X obj 188 354 else/out~;
#X floatatom 172 222 7 0 44100 0 - - - 12;
#X obj 175 195 hsl 140 18 4.1 44100 1 0 empty empty empty -2 -8 0 10 #dfdfdf #000000 #000000 0 1;
#X obj 235 239 else/knob 40 0 1 0 0.5 empty empty #dfdfdf #7c7c7c black 1 0 0 0 1 320 0 0 0.5;
#X floatatom 235 288 5 0 0 0 - - - 0;
#X obj 282 239 else/knob 40 0 1 0 0 empty empty #dfdfdf #7c7c7c black 1 0 0 0 1 320 0 0 0;
#X floatatom 282 288 5 0 0 0 - - - 0;
#X text 237 219 bias;
#X text 278 219 regularity;
#X text 139 223 rate;
#X obj 189 314 else/velvet~ 440;
#X restore 429 306 pd multichannel;
#X obj 200 239 else/velvet~ 440;
#X floatatom 200 208 6 0 44100 0 - - - 12;
#X text 254 204 rate in Hz (from 0 to sample rate), f 17;
#X obj 203 181 hsl 140 18 4.1 44100 1 0 empty empty empty -2 -8 0 10 #dfdfdf #000000 #000000 0 1;
#X text 37 219 see also:;
#X obj 34 266 else/impulse2~;
#X obj 34 240 else/dust2~;
#X text 134 525 -ch <float>: number of output channels (default 1);
#X text 120 352 float/signal(s) - frequency in hz, f 68;
#X obj 34 292 else/white~;
#X text 228 415 set time regularity (0 - 1);
#X text 138 436 float/signal -;
#X obj 95 435 cnv 17 3 17 empty empty 3 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 228 436 set amplitude irregularity (0 - 1);
#N canvas 730 215 522 554 polarity/regularity 0;
#X obj 192 351 else/out~;
#X floatatom 97 212 8 0 44100 0 - - - 12;
#X obj 100 185 hsl 140 18 4.1 44100 1 0 empty empty empty -2 -8 0 10 #dfdfdf #000000 #000000 0 1;
#X obj 208 236 else/knob 40 0 1 0 0.5 empty empty #dfdfdf #7c7c7c black 1 0 0 0 1 320 0 0 0.5;
#X floatatom 208 285 6 0 0 0 - - - 0;
#X obj 255 236 else/knob 40 0 1 0 0 empty empty #dfdfdf #7c7c7c black 1 0 0 0 1 320 0 0 0;
#X floatatom 255 285 6 0 0 0 - - - 0;
#X text 64 213 rate;
#X obj 193 311 else/velvet~ 440;
#X text 76 22 The polarity bias controls the chance that the impulse is positive or negative. The default value is 0.5 \, which means that both have equal (50-50) chance. For a bias of '0' \, only positive impulses appear \, while you have only negative at a bias of '1'.;
#X text 76 92 The regularity value \, from 0 to 1 \, controls the regularity of impulses. For a value of 0 you have completely random and irregular values for the impulses anywhere within the period. When the value increases \, the random range within the period decreases and it becomes fully regular at a value of 1!;
#X text 96 442 For a bias of 0 and regularity of 1 \, the velvet noise becomes the same as [impulse~].;
#X connect 1 0 10 0;
#X obj 311 260 else/knob 40 0 1 0 0 empty empty #dfdfdf #7c7c7c black 1 0 0 0 1 320 0 0 0;
#X floatatom 311 309 6 0 0 0 - - - 0;
#X text 305 237 time regularity;
#X text 176 218 polarity bias, f 8;
#X text 75 86 A time regularity reduces the time randomness and centers it to the beggining of the period. At full regularity (1) the impulse becomes fully steady at the beggining of the period.;
#X text 75 129 For instance \, a bias of 0 and regularity of 1 \, the velvet noise becomes the same as [impulse~]., f 60;
#X text 360 267 amplitude irregularity, f 12;
#X text 89 426 An amplitude irregularity parameter forces random impulse values towards lower values., f 60;
#X text 90 455 Values up to the sample rate are possible \, which outputs non zero values for all samples. Note that at the sample rate and without time regularity \, the object becomes a clipped white noise \, like you get with [white~ -clip]. On the other hand \, with full amplitude irregularity \, it becomes pure white noise.;
#X connect 1 0 8 0;
#X connect 2 0 1 0;
#X connect 3 0 4 0;
#X connect 4 0 10 1;
#X connect 4 0 8 1;
#X connect 5 0 6 0;
#X connect 6 0 10 2;
#X connect 10 0 0 0;
#X restore 412 274 pd bias/regularity;
#X obj 200 252 else/velvet~ 440;
#X floatatom 200 221 6 0 44100 0 - - - 12;
#X text 254 217 rate in Hz (from 0 to sample rate), f 17;
#X obj 203 194 hsl 140 18 4.1 44100 1 0 empty empty empty -2 -8 0 10 #dfdfdf #000000 #000000 0 1;
#X text 37 232 see also:;
#X obj 34 279 else/impulse2~;
#X obj 34 253 else/dust2~;
#X text 134 513 -ch <float>: number of output channels (default 1);
#X text 120 360 float/signal(s) - frequency in hz, f 68;
#X text 48 91 [velvet~] is a velvet noise generator \, which randomly chooses either positive or negative impulses at random positions in a given period set in Hz. A polarity bias is possible to set the amount of positive and negative impulses \, and a regularity parameter forces an impulse regularity wihtout randomness. The object has support for multichannel. Values up to the sample rate are possible. Note that at the sample rate \, the object becomes a clipped white noise \, like you get with [white~ -clip]., f 74;
#X obj 34 305 else/white~;
#X connect 39 0 11 0;
#X connect 40 0 39 0;
#X connect 42 0 40 0;
#X connect 6 0 8 2;
#X connect 8 0 0 0;
#X connect 10 0 11 0;
#X connect 11 0 8 3;
#X restore 388 262 pd polarity/regularity;
#X text 48 92 [velvet~] is a velvet noise generator \, which randomly chooses either positive (1) or negative (-1) impulses at random positions in a given period set in Hz. A polarity bias is possible to set the amount of positive and negative impulses. A time regularity parameter forces a impulses with less randomness. An amplitude irregularity forces random values (different than 1 or -1). The object has support for multichannel., f 77;
#X text 219 594 - time regularity (default 0), f 36;
#X text 219 610 - amplitude irregularity (default 0);
#X text 153 609 4) float;
#X connect 36 0 11 0;
#X connect 37 0 36 0;
#X connect 39 0 37 0;
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#N canvas 312 38 714 626 12;
#N canvas 312 38 714 653 12;
#X declare -path else;
#X obj 74 536 out~;
#X obj 74 556 out~;
#X obj 504 16 declare -path else;
#X obj 304 373 spectrograph~ 1024 1 0 300 140 100;
#X text 491 350 [spectograph~];
#X obj 74 373 graph~ 441 10 -1 1 200 140 #dfdfdf 0 1;
#X obj 395 244 hsl 162 19 4.1 44100 1 0 empty empty empty -2 -10 0 12 #dfdfdf #000000 #000000 0 1;
#X floatatom 392 270 8 0 0 0 - - - 0;
#X obj 304 393 spectrograph~ 1024 1 0 300 140 100;
#X text 491 370 [spectograph~];
#X obj 74 393 graph~ 441 10 -1 1 200 140 #dfdfdf 0 1;
#X obj 395 264 hsl 162 19 4.1 44100 1 0 empty empty empty -2 -10 0 12 #dfdfdf #000000 #000000 0 1;
#X floatatom 392 290 8 0 0 0 - - - 0;
#X text 40 49 The [velvet~] object from ELSE randomly chooses either positive or negative impulses (1 or -1) at random positions in a given period. It is similar to [dust2~] \, which also outputs random positive and negative impulse values (any non zero value) but with no specific period., f 88;
#X text 40 117 Even though you can set them to produce impulses at lower rates \, they aren't actually 'band limited' noise generators. Both can be thought of as some sort of white noise \, as their spectrum are equally balanced just like white noise. When both are at the maximum rate possible \, they become actual white noise with random values at every sample. In the case of [velvet~] \, it produces clipped white noise (like [white~ -clip]) \, while [dust2~] becomes an actual white noise., f 88;
#X obj 304 298 dust2~ 4.1;
#X obj 392 298 velvet~ 4.1;
#X obj 304 331 xselect~ 2 1, f 13;
#X obj 264 234 vradio 19 1 0 2 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0;
#X text 285 234 dust;
#X text 285 255 velvet;
#X obj 264 283 + 1;
#X text 458 270 rate;
#X obj 304 318 dust2~ 4.1;
#X obj 392 318 velvet~ 4.1;
#X obj 304 351 xselect~ 2 1, f 13;
#X obj 264 254 vradio 19 1 0 2 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0;
#X text 285 254 dust;
#X text 285 275 velvet;
#X obj 264 303 + 1;
#X text 458 290 rate;
#X text 40 117 Even though you can set them to produce impulses at lower rates \, they aren't actually 'band limited' noise generators. Both can be thought of as some sort of white noise \, as their spectrum are equally balanced just like white noise. When both are at the maximum rate possible \, they become actual white noise with random values at every sample. In the case of [velvet~] \, it produces clipped white noise (like [white~ -clip]) \, while [dust2~] becomes an actual white noise. The [velvet~] object can also output pure white noise with the amplitude irregularity parameter (check its help file for details)., f 88;
#X connect 4 0 0 0;
#X connect 5 0 6 0;
#X connect 6 0 8 0;
#X connect 6 0 9 0;
#X connect 6 0 10 0;
#X connect 9 0 11 0;
#X connect 10 0 11 1;
#X connect 11 0 4 0;
#X connect 11 0 2 0;
#X connect 12 0 15 0;
#X connect 15 0 11 0;
#X connect 8 0 10 0;
#X connect 9 0 10 1;
#X connect 10 0 4 0;
#X connect 10 0 2 0;
#X connect 11 0 14 0;
#X connect 14 0 10 0;

0 comments on commit 76356ea

Please sign in to comment.