#N canvas 413 23 825 723 12;
#X declare -stdpath ./;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-waveform 882 float 0;
#X coords 0 1.02 881 -1.02 200 130 1;
#X restore 552 357 graph;
#X floatatom 65 58 5 0 0 0 - - - 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-env 22050 float 0;
#X coords 0 1.02 22049 -1.02 200 130 1;
#X restore 552 136 graph;
#X obj 65 89 phasor~;
#X text 49 16 ENVELOPE GENERATORS FROM LINE SEGMENTS;
#X obj 72 597 output~;
#X text 49 684 updated for Pd version 0.39;
#X obj 96 128 *~;
#X obj 65 207 -~;
#X obj 65 244 *~;
#X floatatom 135 90 4 0 100 0 - - - 0;
#X obj 71 282 min~;
#X floatatom 130 146 3 0 100 0 - - - 0;
#X obj 130 169 / 100;
#X floatatom 123 202 3 0 100 0 - - - 0;
#X obj 114 446 *~ 2;
#X obj 114 474 min~;
#X obj 165 446 -~ 1;
#X obj 114 418 phasor~ 200;
#X obj 72 542 *~;
#X obj 113 389 tabwrite~ \$0-env;
#X obj 123 225 * -1;
#X obj 128 530 bng 19 250 50 0 empty empty empty 0 -6 0 8 #dfdfdf #000000 #000000;
#X obj 114 555 tabwrite~ \$0-waveform;
#X obj 165 474 *~ -3;
#X obj 114 500 -~ 0.5;
#X text 572 499 ----- 0.02 second ----;
#X text 567 272 ----- 0.5 second ------;
#X text 183 161 Subtract this to make the phasor cross zero at the desired point of the cycle., f 39;
#X text 165 219 multiply the phasor (with the zero crossing shifted as above) by the desired slope \, negating it so the segment points downward., f 43;
#X text 109 275 minimum of rise and decay segments (makes a triangle wave), f 32;
#X obj 71 324 clip~ 0 1;
#X text 147 318 clip the triangle wave to between 0 and 1 \, to make the sustain and silent regions., f 42;
#X text 213 437 this makes a quick-and-dirty triangle wave;
#X text 213 453 as described in the previous patch. It's, f 42;
#X text 285 565 You can make a phasor-generated envelope generator using "min" and "clip" to combine line segments. Here a rise segment starts at phase 0 \, and a decay segment passes through zero at a controllable point (the "duty cycle" \, as a percentage of a cycle.) Each has a controllable slope (in units per cycle). The resulting triangle wave (the minimum of the rise and decay segments) is limited to 1 \, thus making a flat "sustain" segment (unless the rise and decay segments meet at a value less than one \, in which case there is none). Limiting below by 0 prevents us from following the decay segment into negative values. Reasonable values to start with are 6 Hz. frequency \, rise and decay slope 10 \, duty cycle 75%., f 73;
#X text 104 58 <= frequency (Hz.);
#X text 169 90 <= slope of rise segment. Just multiply this by the phase to make the segment., f 39;
#X text 161 144 <= Duty cycle (end of decay segment as % of cycle.);
#X text 152 201 <= slope of decay segment.;
#X text 213 469 used here so we'll have something to listen to., f 42;
#X obj 604 35 declare -stdpath ./;
#X text 151 530 <-- click to graph audio waveform;
#X obj 113 361 bng 19 250 50 0 empty empty empty 0 -6 0 8 #dfdfdf #000000 #000000;
#X text 137 359 <-- click to graph envelope shape;
#X connect 1 0 3 0;
#X connect 3 0 7 0;
#X connect 3 0 8 0;
#X connect 7 0 11 1;
#X connect 8 0 9 0;
#X connect 9 0 11 0;
#X connect 10 0 7 1;
#X connect 11 0 31 0;
#X connect 12 0 13 0;
#X connect 13 0 8 1;
#X connect 14 0 21 0;
#X connect 15 0 16 0;
#X connect 16 0 25 0;
#X connect 17 0 24 0;
#X connect 18 0 15 0;
#X connect 18 0 17 0;
#X connect 19 0 5 0;
#X connect 21 0 9 1;
#X connect 22 0 23 0;
#X connect 24 0 16 1;
#X connect 25 0 23 0;
#X connect 25 0 19 1;
#X connect 31 0 19 0;
#X connect 31 0 20 0;
#X connect 43 0 20 0;
