#N canvas 236 23 1039 698 12;
#X text 86 41 ENVELOPE FOLLOWERS;
#X text 68 224 The env~ object reports the RMS signal level over the last 256 samples (by default) or any other power of 2 that's at least twice the block size. The analysis is done in an overlapped fashion so that results appear every N/2 points if N is the analysis window size. So the larger the window \, the stabler the result and the less frequently it appears. Computation time doesn't depend heavily on N., f 54;
#X text 67 349 Envelope followers are frequently used to detect attacks and periods of silence. (There are fancier attack detectors out there \, though.) Here is a simple threshold-based attack and rest detector., f 54;
#X obj 587 58 dbtorms;
#X obj 511 45 osc~ 440;
#X obj 511 101 env~;
#X floatatom 511 144 6 0 0 0 - - - 0;
#X floatatom 587 35 6 0 0 0 - - - 0;
#X obj 627 128 t b f;
#X floatatom 627 155 4 0 0 0 - - - 0;
#X obj 627 229 route 0 1;
#X obj 607 254 > 55;
#X obj 657 254 < 45;
#X obj 607 277 sel 1;
#X obj 657 277 sel 1;
#X msg 534 310 1;
#X msg 571 311 0;
#X obj 607 312 print attack;
#X obj 627 181 != 0;
#X obj 511 350 t b f;
#X floatatom 510 384 3 0 0 0 - - - 0;
#X obj 510 468 route 0 1;
#X obj 499 496 sel 1;
#X msg 389 639 1;
#X msg 427 639 0;
#X obj 510 412 != 0;
#X obj 563 385 < 45;
#X obj 467 560 timer;
#X obj 590 468 sel 0;
#X obj 540 609 sel 0;
#X obj 480 609 sel 1;
#X obj 480 650 print rest;
#X obj 467 583 > 1000;
#X text 699 228 route the RMS value according to state;
#X text 672 127 ATTACK DETECTION;
#X text 579 350 REST DETECTION;
#X text 67 420 Both detectors are state machines with two states \, on and off. If on \, a test is run to determine whether to turn off \, and vice versa. The tests are run at each output of the rms~ object., f 54;
#X text 95 569 updated for Pd version 0.37;
#X obj 511 78 *~;
#X text 385 111 note 3.01 dB difference between peak and RMS amplitudes., f 16;
#X text 639 462 regardless of state \, when RMS isn't low reset the timer, f 29;
#X text 566 502 If we're not in rest \, and the RMS is low \, check elapsed time since RMS last wasn't low., f 45;
#X text 605 374 Here we always will test RMS against a low value but as before we route the result according to our state \, 1 if "resting" \, 0 if not., f 50;
#X text 690 155 state -- 1 if waiting for low threshold \, 0 if we've attained it and now want the high one., f 30;
#X text 705 259 if off \, 55 dB means attack. If on \, 45 dB or less means state changes to off., f 40;
#X text 555 573 If more than 1 second \, report a rest.;
#X text 591 602 If we're at rest \, pop out of it when RMS isn't low enough., f 29;
#X msg 176 132 \; pd dsp \$1;
#X obj 176 103 tgl 19 0 empty empty empty 17 7 0 10 #dfdfdf #000000 #000000 0 1;
#X obj 627 206 pack f f;
#X obj 510 438 pack f f;
#X connect 3 0 38 1;
#X connect 4 0 38 0;
#X connect 5 0 6 0;
#X connect 5 0 8 0;
#X connect 6 0 19 0;
#X connect 7 0 3 0;
#X connect 8 0 9 0;
#X connect 8 1 49 1;
#X connect 9 0 18 0;
#X connect 10 0 11 0;
#X connect 10 1 12 0;
#X connect 11 0 13 0;
#X connect 12 0 14 0;
#X connect 13 0 15 0;
#X connect 13 0 17 0;
#X connect 14 0 16 0;
#X connect 15 0 9 0;
#X connect 16 0 9 0;
#X connect 18 0 49 0;
#X connect 19 0 20 0;
#X connect 19 1 26 0;
#X connect 20 0 25 0;
#X connect 21 0 22 0;
#X connect 21 1 29 0;
#X connect 22 0 27 1;
#X connect 23 0 20 0;
#X connect 24 0 20 0;
#X connect 25 0 50 0;
#X connect 26 0 28 0;
#X connect 26 0 50 1;
#X connect 27 0 32 0;
#X connect 28 0 27 0;
#X connect 29 0 24 0;
#X connect 30 0 23 0;
#X connect 30 0 31 0;
#X connect 32 0 30 0;
#X connect 38 0 5 0;
#X connect 48 0 47 0;
#X connect 49 0 10 0;
#X connect 50 0 21 0;
