#N canvas 513 86 605 530 12;
#X declare -stdpath ./;
#N canvas 359 38 837 719 fft 0;
#X obj 63 584 *~;
#X obj 288 539 *~;
#X obj 259 538 *~;
#X obj 351 540 *~;
#X obj 319 539 *~;
#X obj 319 567 +~;
#X obj 259 568 -~;
#X obj 457 470 *~;
#X obj 183 260 *~;
#X obj 151 260 *~;
#X obj 151 285 +~;
#X obj 275 149 *~;
#X obj 243 149 *~;
#X obj 507 384 *~;
#X obj 475 384 *~;
#X obj 168 123 *~;
#X obj 63 681 outlet~;
#X obj 63 559 *~;
#X obj 168 190 rfft~;
#X obj 63 535 rifft~;
#X obj 475 412 rsqrt~;
#X obj 243 173 +~;
#X obj 397 470 *~;
#X obj 101 583 sig~ 0.0002;
#N canvas 167 161 701 458 decision 0;
#X obj 298 131 inlet~;
#X obj 279 400 outlet~;
#X obj 74 213 -~;
#X obj 445 128 inlet~;
#X obj 298 232 -~;
#X obj 316 207 lrshift~ 1;
#X obj 474 212 -~;
#X obj 492 187 lrshift~ -1;
#X obj 279 342 *~;
#X obj 279 371 *~;
#X text 304 103 new;
#X text 452 100 old;
#X text 135 27 Choose whether to replace the "old" signal with the "new" one. The "new" one must be stronger than the old one and also must be stronger than its two neighboring channels;
#X text 466 268 1 if we're louder than neighbor, f 17;
#X obj 474 240 expr~ $v1 > 0;
#X obj 298 260 expr~ $v1 > 0;
#X obj 74 243 expr~ $v1 > 0;
#X text 180 229 1 if new signal stronger than old one, f 15;
#X connect 0 0 2 0;
#X connect 0 0 5 0;
#X connect 0 0 4 0;
#X connect 0 0 6 0;
#X connect 0 0 7 0;
#X connect 2 0 16 0;
#X connect 3 0 2 1;
#X connect 4 0 15 0;
#X connect 5 0 4 1;
#X connect 6 0 14 0;
#X connect 7 0 6 1;
#X connect 8 0 9 0;
#X connect 9 0 1 0;
#X connect 14 0 9 1;
#X connect 15 0 8 1;
#X connect 16 0 8 0;
#X restore 151 312 pd decision;
#X obj 475 434 *~;
#N canvas 352 333 393 308 divide-by-prev 0;
#X obj 204 88 inlet~;
#X obj 266 90 inlet~;
#X obj 204 240 outlet~;
#X obj 267 240 outlet~;
#X obj 70 240 outlet~;
#X obj 138 240 outlet~;
#X obj 171 169 *~;
#X obj 138 169 *~;
#X obj 103 170 *~;
#X obj 70 170 *~;
#X obj 70 198 +~;
#X obj 138 197 -~;
#X obj 89 34 r~ \$0-last-real;
#X obj 121 61 r~ \$0-last-imag;
#X connect 0 0 2 0;
#X connect 0 0 9 0;
#X connect 0 0 6 0;
#X connect 1 0 3 0;
#X connect 1 0 8 0;
#X connect 1 0 7 0;
#X connect 6 0 11 1;
#X connect 7 0 11 0;
#X connect 8 0 10 1;
#X connect 9 0 10 0;
#X connect 10 0 4 0;
#X connect 11 0 5 0;
#X connect 12 0 9 1;
#X connect 12 0 7 1;
#X connect 13 0 8 1;
#X connect 13 0 6 1;
#X restore 500 279 pd divide-by-prev;
#N canvas 650 183 602 327 switch 0;
#X obj 61 160 inlet~;
#X obj 149 96 inlet~;
#X obj 211 97 inlet~;
#X obj 284 94 inlet~;
#X obj 352 94 inlet~;
#X obj 384 182 -~;
#X obj 350 228 +~;
#X obj 384 226 *~;
#X obj 266 179 -~;
#X obj 232 225 +~;
#X obj 266 225 *~;
#X obj 231 275 outlet~;
#X obj 350 271 outlet~;
#X text 88 25 switch between two pairs of inputs. If first inlet is one \, take the left-hand pair \, otherwise the right-hand one.;
#X text 57 137 switch;
#X text 134 73 pass this if one;
#X text 280 74 pass this if zero;
#X connect 0 0 10 1;
#X connect 0 0 7 1;
#X connect 1 0 8 0;
#X connect 2 0 5 0;
#X connect 3 0 9 0;
#X connect 3 0 8 1;
#X connect 4 0 6 0;
#X connect 4 0 5 1;
#X connect 5 0 7 0;
#X connect 6 0 12 0;
#X connect 7 0 6 1;
#X connect 8 0 10 0;
#X connect 9 0 11 0;
#X connect 10 0 9 1;
#X restore 277 369 pd switch;
#X obj 548 358 r revtime;
#X obj 99 560 tabreceive~ \$0-hann;
#X obj 186 83 tabreceive~ \$0-hann, f 11;
#X msg 558 380 set \$1;
#X obj 558 404 s revtime-set;
#X obj 681 50 r window-size;
#X msg 681 72 set \$1 4;
#X obj 681 94 block~;
#X obj 548 428 expr 1 - 0.2/max(0.2 \, $f1);
#X text 438 39 previous output amplitude \, encoding both magnitude and phase, f 19;
#X text 435 136 previous phase increment (unit-magnitude complex number), f 31;
#X obj 442 199 +~ 1e-15;
#X obj 322 81 +~ 1e-15;
#X text 124 683 IFFT and output;
#X text 491 457 normalize increments between 0 and 1 according to revtime., f 29;
#X text 352 564 propagate amplitudes by multiplying in the increments \, which advance the phase and drop magnitude according to revtime., f 40;
#X text 31 289 choose whether to punch in new (amplitude \, increment) pair, f 16;
#N canvas 650 183 602 327 switch 0;
#X obj 61 160 inlet~;
#X obj 149 96 inlet~;
#X obj 211 97 inlet~;
#X obj 315 94 inlet~;
#X obj 375 94 inlet~;
#X obj 409 182 -~;
#X obj 380 228 +~;
#X obj 414 226 *~;
#X obj 292 179 -~;
#X obj 262 225 +~;
#X obj 296 225 *~;
#X obj 261 275 outlet~;
#X obj 380 271 outlet~;
#X text 88 25 switch between two pairs of inputs. If first inlet is one \, take the left-hand pair \, otherwise the right-hand one.;
#X text 57 137 switch;
#X text 134 73 pass this if one;
#X text 311 74 pass this if zero;
#X connect 0 0 10 1;
#X connect 0 0 7 1;
#X connect 1 0 8 0;
#X connect 2 0 5 0;
#X connect 3 0 9 0;
#X connect 3 0 8 1;
#X connect 4 0 6 0;
#X connect 4 0 5 1;
#X connect 5 0 7 0;
#X connect 6 0 12 0;
#X connect 7 0 6 1;
#X connect 8 0 10 0;
#X connect 9 0 11 0;
#X connect 10 0 9 1;
#X restore 397 353 pd switch;
#X obj 322 55 r~ \$0-amp-real;
#X obj 337 107 r~ \$0-amp-imag;
#X obj 442 174 r~ \$0-inc-real;
#X obj 459 226 r~ \$0-inc-imag;
#X obj 616 304 s~ \$0-last-imag;
#X obj 577 327 s~ \$0-last-real;
#X obj 259 650 s~ \$0-amp-real;
#X obj 319 621 s~ \$0-amp-imag;
#X obj 168 14 inlet~;
#X obj 397 536 s~ \$0-inc-real;
#X obj 457 510 s~ \$0-inc-imag;
#X connect 0 0 16 0;
#X connect 1 0 6 1;
#X connect 2 0 6 0;
#X connect 3 0 5 1;
#X connect 4 0 5 0;
#X connect 5 0 53 0;
#X connect 6 0 52 0;
#X connect 7 0 1 0;
#X connect 7 0 3 0;
#X connect 7 0 56 0;
#X connect 8 0 10 1;
#X connect 9 0 10 0;
#X connect 10 0 24 0;
#X connect 11 0 21 1;
#X connect 12 0 21 0;
#X connect 13 0 20 0;
#X connect 14 0 20 0;
#X connect 15 0 18 0;
#X connect 17 0 0 0;
#X connect 18 0 9 0;
#X connect 18 0 9 1;
#X connect 18 0 26 0;
#X connect 18 0 27 1;
#X connect 18 1 8 0;
#X connect 18 1 8 1;
#X connect 18 1 26 1;
#X connect 18 1 27 2;
#X connect 19 0 17 0;
#X connect 20 0 25 0;
#X connect 21 0 24 1;
#X connect 22 0 2 0;
#X connect 22 0 4 0;
#X connect 22 0 55 0;
#X connect 23 0 0 1;
#X connect 24 0 27 0;
#X connect 24 0 45 0;
#X connect 25 0 22 1;
#X connect 25 0 7 1;
#X connect 26 0 45 1;
#X connect 26 1 45 2;
#X connect 26 2 51 0;
#X connect 26 3 50 0;
#X connect 27 0 19 0;
#X connect 27 0 3 1;
#X connect 27 0 2 1;
#X connect 27 1 19 1;
#X connect 27 1 1 1;
#X connect 27 1 4 1;
#X connect 28 0 31 0;
#X connect 28 0 36 0;
#X connect 29 0 17 1;
#X connect 30 0 15 1;
#X connect 31 0 32 0;
#X connect 33 0 34 0;
#X connect 34 0 35 0;
#X connect 36 0 25 1;
#X connect 39 0 45 3;
#X connect 40 0 12 0;
#X connect 40 0 12 1;
#X connect 40 0 27 3;
#X connect 45 0 14 0;
#X connect 45 0 14 1;
#X connect 45 0 22 0;
#X connect 45 1 13 0;
#X connect 45 1 13 1;
#X connect 45 1 7 0;
#X connect 46 0 40 0;
#X connect 47 0 11 0;
#X connect 47 0 11 1;
#X connect 47 0 27 4;
#X connect 48 0 39 0;
#X connect 49 0 45 4;
#X connect 54 0 15 0;
#X restore 214 393 pd fft;
#X floatatom 380 269 4 0 1000 0 - revtime-set - 0;
#X floatatom 89 314 6 0 0 0 - - - 0;
#X text 418 269 reverb time;
#X obj 214 428 output~;
#X obj 89 428 output~;
#X text 50 73 This is a phase vocoder acting as a reverberator. The sound is more coherent (less "whispered") than a real room or a standard delay-based reverberator., f 70;
#X text 50 127 The technique is to "punch" the incoming sound into channels where (1) there's a peak \, and (2) the incoming sound drowns out whatever might already be there. If the sound already in any channel is louder than the input the input for that channel is ignored., f 70;
#N canvas 464 229 262 333 test-sound 0;
#X obj 46 25 inlet;
#X obj 46 145 osc~;
#X obj 115 201 line~;
#X floatatom 46 86 5 0 0 0 - - - 0;
#X obj 46 59 mtof;
#X obj 46 170 cos~;
#X obj 46 194 hip~ 20;
#X obj 46 117 t f b;
#X obj 115 91 bng 19 250 50 0 empty empty empty 0 -6 0 8 #dfdfdf #000000 #000000;
#X obj 160 172 pack 0 30;
#X obj 160 117 del 20;
#X obj 115 144 pack 1 20;
#X obj 46 236 *~;
#X obj 46 272 outlet~;
#X connect 0 0 4 0;
#X connect 1 0 5 0;
#X connect 2 0 12 1;
#X connect 3 0 7 0;
#X connect 4 0 3 0;
#X connect 5 0 6 0;
#X connect 6 0 12 0;
#X connect 7 0 1 0;
#X connect 7 1 8 0;
#X connect 8 0 10 0;
#X connect 8 0 11 0;
#X connect 9 0 2 0;
#X connect 10 0 9 0;
#X connect 11 0 2 0;
#X connect 12 0 13 0;
#X restore 89 356 pd test-sound;
#X obj 380 301 s revtime;
#X text 50 198 For each window \, the amplitude in each channel is propagated by a constant phase increment and multiplied downward by a gain that determines the "reverb time"., f 70;
#N canvas 635 123 602 538 hann-window 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-hann 4096 float 0;
#X coords 0 1 4095 0 300 100 1;
#X restore 148 395 graph;
#X obj 365 185 osc~;
#X obj 365 210 *~ -0.5;
#X obj 365 234 +~ 0.5;
#X obj 348 277 tabwrite~ \$0-hann;
#X obj 124 114 r window-size;
#X obj 195 238 /;
#X obj 213 206 samplerate~;
#X obj 195 316 s window-sec;
#X obj 105 252 swap;
#X obj 105 276 /;
#X obj 105 300 s window-hz;
#X obj 206 266 * 1000;
#X obj 206 293 s window-msec;
#X obj 124 149 t f b f;
#X msg 213 156 resize \$1;
#X obj 213 180 s \$0-hann;
#X obj 317 123 r window-hz;
#X msg 390 155 0;
#X obj 317 151 t f b;
#X text 94 21 calculate Hann window table (variable window size) and constants window-hz (fundamental frequency of analysis) \, window-sec and window-msec (analysis window size in seconds and msec)., f 56;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 3 0 4 0;
#X connect 5 0 14 0;
#X connect 6 0 8 0;
#X connect 6 0 12 0;
#X connect 7 0 6 1;
#X connect 7 0 9 1;
#X connect 9 0 10 0;
#X connect 9 1 10 1;
#X connect 10 0 11 0;
#X connect 12 0 13 0;
#X connect 14 0 6 0;
#X connect 14 0 9 0;
#X connect 14 1 7 0;
#X connect 14 2 15 0;
#X connect 15 0 16 0;
#X connect 17 0 19 0;
#X connect 18 0 1 1;
#X connect 19 0 1 0;
#X connect 19 1 4 0;
#X connect 19 1 18 0;
#X restore 378 341 pd hann-window;
#X text 106 492 reverb in;
#X text 234 492 reverb out;
#X obj 378 472 declare -stdpath ./;
#X obj 89 277 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X obj 30 20 cnv 5 5 25 empty empty Piano\ Reverb 15 13 0 16 #dfdfdf #202020 0;
#X text 118 277 <-- retrigger;
#X text 139 308 short tone pitch (click and drag or set pitch), f 24;
#X obj 378 376 loadbang;
#X msg 378 402 \; window-size 4096 \; revtime 20, f 18;
#X connect 0 0 4 0;
#X connect 1 0 9 0;
#X connect 2 0 8 0;
#X connect 8 0 5 0;
#X connect 8 0 0 0;
#X connect 15 0 2 0;
#X connect 19 0 20 0;
