#N canvas 471 54 637 650 12;
#X declare -stdpath ./;
#X declare -stdpath ./;
#N canvas 447 38 690 818 fft-analysis 0;
#X obj 71 702 *~;
#X obj 32 752 *~;
#X obj 242 133 *~;
#X obj 32 46 *~;
#X obj 32 13 inlet~;
#X obj 32 70 rfft~;
#X obj 32 728 rifft~;
#X obj 32 777 outlet~;
#X obj 203 132 *~;
#X obj 242 182 rsqrt~;
#X obj 84 428 -~;
#X obj 32 701 *~;
#X obj 66 46 tabreceive~ \$0-hann;
#X obj 508 127 r window-size;
#X obj 66 751 tabreceive~ \$0-hann;
#X obj 118 325 *~;
#X msg 508 150 set \$1 4;
#X obj 508 174 block~;
#X obj 105 641 /~ 1000;
#X obj 173 643 r window-size;
#X obj 224 207 *~;
#X obj 118 213 *~;
#X obj 242 158 +~ 1e-20;
#X obj 136 244 lrshift~ 1;
#X obj 279 235 lrshift~ 1;
#X obj 136 270 lrshift~ -1;
#X obj 280 262 lrshift~ -1;
#X obj 262 313 *~;
#X obj 84 482 clip~ 0 1;
#X obj 84 455 *~ 1e+20;
#X obj 84 370 +~;
#X obj 84 515 *~;
#X obj 121 516 lrshift~ 1;
#X obj 225 515 lrshift~ -1;
#X obj 105 547 *~;
#X obj 320 415 -~;
#X obj 320 466 clip~ 0 1;
#X obj 320 440 *~ 1e+20;
#X obj 320 496 *~;
#X obj 359 496 lrshift~ 1;
#X obj 463 495 lrshift~ -1;
#X obj 340 525 *~;
#X obj 340 548 *~ -1;
#X obj 340 571 +~ 1;
#X obj 105 606 +~;
#X obj 225 313 *~;
#X obj 85 325 *~;
#X text 163 482 0 if clean;
#X text 139 546 0 if a neighbor is clean;
#X obj 85 299 +~;
#X obj 118 298 +~;
#X obj 225 287 +~;
#X obj 262 286 +~;
#X text 139 562 1 if all neighbors dirty;
#X obj 153 695 lrshift~ -1;
#X obj 153 671 sig~ 1;
#X obj 105 665 *~;
#X obj 121 428 expr $f1*$f1/1250;
#X obj 338 389 expr $f1*$f1/1250;
#X obj 121 405 r dirty;
#X obj 338 364 r clean;
#X text 281 132 normalize the amplitudes;
#X text 92 70 forward real Hann-windowed FT;
#X text 203 672 I had trouble with the DC bin - this zeros it.;
#X text 119 368 total incoherence;
#X text 394 420 compare incoherence with the threshold;
#X text 394 435 If greater (dirty) \, the "clip" outputs;
#X text 394 450 1 \, otherwise (if clean) \, zero.;
#X text 141 604 add to let in channels;
#X text 141 617 for either criterion;
#X text 390 528 multiply by left and right neighbors \, so 0 if any of the 3 is "clean"., f 37;
#X text 387 567 0 if all neighbors clean 1 if a neighbor dirty, f 24;
#X text 465 378 adjust threshold to quadratic units and scale, f 25;
#X text 368 227 add neighboring amplitude to this one and take squared magnitude of result - do this for both the left neighbor and the right one, f 34;
#X connect 0 0 6 1;
#X connect 1 0 7 0;
#X connect 2 0 22 0;
#X connect 3 0 5 0;
#X connect 4 0 3 0;
#X connect 5 0 11 0;
#X connect 5 0 8 0;
#X connect 5 0 8 1;
#X connect 5 0 21 0;
#X connect 5 1 0 0;
#X connect 5 1 2 0;
#X connect 5 1 2 1;
#X connect 5 1 20 0;
#X connect 6 0 1 0;
#X connect 8 0 22 0;
#X connect 9 0 21 1;
#X connect 9 0 20 1;
#X connect 10 0 29 0;
#X connect 11 0 6 0;
#X connect 12 0 3 1;
#X connect 13 0 16 0;
#X connect 14 0 1 1;
#X connect 15 0 30 0;
#X connect 16 0 17 0;
#X connect 18 0 56 0;
#X connect 19 0 18 1;
#X connect 20 0 24 0;
#X connect 20 0 26 0;
#X connect 20 0 51 0;
#X connect 20 0 52 0;
#X connect 21 0 23 0;
#X connect 21 0 25 0;
#X connect 21 0 49 0;
#X connect 21 0 50 0;
#X connect 22 0 9 0;
#X connect 23 0 49 1;
#X connect 24 0 51 1;
#X connect 25 0 50 1;
#X connect 26 0 52 1;
#X connect 27 0 30 1;
#X connect 28 0 31 0;
#X connect 28 0 33 0;
#X connect 28 0 32 0;
#X connect 29 0 28 0;
#X connect 30 0 10 0;
#X connect 30 0 35 0;
#X connect 31 0 34 0;
#X connect 32 0 31 1;
#X connect 33 0 34 1;
#X connect 34 0 44 0;
#X connect 35 0 37 0;
#X connect 36 0 38 0;
#X connect 36 0 40 0;
#X connect 36 0 39 0;
#X connect 37 0 36 0;
#X connect 38 0 41 0;
#X connect 39 0 38 1;
#X connect 40 0 41 1;
#X connect 41 0 42 0;
#X connect 42 0 43 0;
#X connect 43 0 44 1;
#X connect 44 0 18 0;
#X connect 45 0 30 1;
#X connect 46 0 30 0;
#X connect 49 0 46 0;
#X connect 49 0 46 1;
#X connect 50 0 15 0;
#X connect 50 0 15 1;
#X connect 51 0 45 0;
#X connect 51 0 45 1;
#X connect 52 0 27 0;
#X connect 52 0 27 1;
#X connect 54 0 56 1;
#X connect 55 0 54 0;
#X connect 56 0 11 1;
#X connect 56 0 0 1;
#X connect 57 0 10 1;
#X connect 58 0 35 1;
#X connect 59 0 57 0;
#X connect 60 0 58 0;
#X restore 59 458 pd fft-analysis;
#X floatatom 346 280 6 0 100 0 - - - 0;
#X obj 59 523 output~;
#X floatatom 59 358 5 0 100 0 - - - 0;
#X text 103 336 noise;
#X floatatom 106 358 5 0 100 0 - - - 0;
#N canvas 272 180 615 542 test-signal 0;
#X obj 313 338 *~;
#X obj 133 320 *~;
#X obj 270 267 noise~;
#X obj 295 400 +~;
#X obj 191 275 dbtorms;
#X obj 191 110 inlet;
#X obj 295 481 outlet~;
#X obj 270 292 bp~ 10000 3;
#X text 267 234 filtered noise, f 8;
#X obj 424 376 *~;
#X obj 497 346 dbtorms;
#X obj 497 110 inlet;
#X text 421 240 osc;
#X obj 424 266 osc~ 440;
#X obj 295 439 *~ 3;
#X obj 77 218 *~;
#X obj 77 184 phasor~;
#X obj 77 265 tabread4~ \$0-sample, f 9;
#X obj 77 155 r \$0-hz;
#X obj 111 219 r \$0-size;
#X msg 191 299 \$1 10;
#X obj 191 323 line~;
#X obj 361 295 dbtorms;
#X obj 361 110 inlet;
#X msg 361 319 \$1 10;
#X obj 361 343 line~;
#X msg 497 372 \$1 10;
#X obj 497 396 line~;
#X text 105 31 TEST SIGNAL: looped sample plus noise and oscillator. The inlets control amplitude of each in dB., f 42;
#X connect 0 0 3 1;
#X connect 1 0 3 0;
#X connect 2 0 7 0;
#X connect 3 0 14 0;
#X connect 4 0 20 0;
#X connect 5 0 4 0;
#X connect 7 0 0 0;
#X connect 9 0 3 1;
#X connect 10 0 26 0;
#X connect 11 0 10 0;
#X connect 13 0 9 0;
#X connect 14 0 6 0;
#X connect 15 0 17 0;
#X connect 16 0 15 0;
#X connect 17 0 1 0;
#X connect 18 0 16 0;
#X connect 19 0 15 1;
#X connect 20 0 21 0;
#X connect 21 0 1 1;
#X connect 22 0 24 0;
#X connect 23 0 22 0;
#X connect 24 0 25 0;
#X connect 25 0 0 1;
#X connect 26 0 27 0;
#X connect 27 0 9 1;
#X restore 59 407 pd test-signal;
#X text 43 336 sampler;
#X text 62 300 amplitudes (dB);
#X floatatom 234 278 6 0 100 0 - - - 0;
#X floatatom 154 358 6 0 100 0 - - - 0;
#X text 162 336 osc;
#X msg 483 305 512;
#X msg 492 369 1024;
#X msg 497 396 2048;
#X msg 503 423 4096;
#X obj 234 306 s clean;
#X obj 346 306 s dirty;
#X text 43 198 Two separate thresholds may be adjusted to listen to the "clean" or "dirty" part of the signal. You'll hear anything less incoherent than the clean threshold \, OR more incoherent than the dirty one., f 75;
#X text 43 54 This patch applies a very simple coherence test to distinguish between sinusoids and noise in an input signal. It works very imperfectly (since noise is random \, no matter what test we place on it it will sometimes spoof its way in.) Here we just test that neighboring channels are 180 degrees (pi radians) out of phase \, as they should be in the main lobe in response to a sinusoid. If any three channels are so arranged \, all three are considered as contributing to a sinusoid. To do this we make an "incoherence" measure which is zero if the phase relationship is perfect and progressively larger otherwise., f 75;
#N canvas 734 203 602 538 hann-window 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-hann 1024 float 0;
#X coords 0 1 1023 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 479 538 pd hann-window;
#X obj 430 17 declare -stdpath ./;
#X obj 21 13 cnv 5 5 25 empty empty Pitch/Unpitched\ Separation 15 13 0 16 #dfdfdf #202020 0;
#N canvas 621 135 735 607 insample 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-sample 155944 float 2;
#X coords 0 1 155944 -1 279 142 1 0 0;
#X restore 375 268 graph;
#X obj 121 246 soundfiler;
#X msg 188 276 \$1;
#X obj 163 307 swap;
#X obj 163 335 /;
#X floatatom 163 395 10 0 0 0 - - - 0;
#X obj 175 160 symbol \$0-sample;
#X obj 42 124 openpanel;
#X msg 121 215 read -resize \$1 \$2;
#X obj 121 188 pack s s;
#X obj 121 160 t a b;
#X floatatom 121 446 9 0 0 0 - - - 0;
#X floatatom 248 384 6 0 0 0 - - - 0;
#X text 219 271 sample rate, f 6;
#X obj 54 19 inlet;
#X obj 121 502 s \$0-size;
#X obj 163 421 s \$0-hz;
#X obj 54 63 route bang;
#X obj 42 97 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X obj 352 107 adc~ 1;
#X obj 407 19 inlet;
#X obj 556 78 samplerate~;
#X obj 407 170 tabwrite~ \$0-sample;
#X obj 569 167 s \$0-sample;
#X msg 569 140 resize \$1;
#X obj 556 111 * 2;
#X text 588 112 2 seconds;
#X obj 556 199 s \$0-size;
#X text 169 57 Subpatch to initialize patch \, load file into array and record., f 22;
#X obj 203 547 outlet;
#X obj 248 411 / 1000;
#X obj 203 487 /;
#X obj 224 517 r \$0-ms;
#X obj 493 113 s \$0-hz;
#X msg 493 88 0.5;
#X msg 448 114 2000;
#X obj 448 139 s \$0-ms;
#X obj 450 527 declare -stdpath ./;
#X obj 454 442 loadbang;
#X msg 454 468 \; squelch-set 10;
#X connect 1 0 3 0;
#X connect 1 0 11 0;
#X connect 1 1 2 0;
#X connect 2 0 3 1;
#X connect 2 0 12 0;
#X connect 3 0 4 0;
#X connect 3 1 4 1;
#X connect 4 0 5 0;
#X connect 5 0 16 0;
#X connect 6 0 9 1;
#X connect 7 0 10 0;
#X connect 8 0 1 0;
#X connect 9 0 8 0;
#X connect 10 0 9 0;
#X connect 10 1 6 0;
#X connect 11 0 15 0;
#X connect 11 0 31 0;
#X connect 12 0 30 0;
#X connect 14 0 17 0;
#X connect 17 0 18 0;
#X connect 17 1 10 0;
#X connect 18 0 7 0;
#X connect 19 0 22 0;
#X connect 20 0 21 0;
#X connect 20 0 22 0;
#X connect 20 0 35 0;
#X connect 20 0 34 0;
#X connect 21 0 25 0;
#X connect 24 0 23 0;
#X connect 25 0 24 0;
#X connect 25 0 27 0;
#X connect 30 0 31 1;
#X connect 31 0 29 0;
#X connect 32 0 29 0;
#X connect 34 0 33 0;
#X connect 35 0 36 0;
#X connect 38 0 39 0;
#X restore 274 551 pd insample;
#X obj 296 499 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X msg 270 420 ../sound/bell.aiff;
#X msg 279 443 ../sound/voice.wav;
#X msg 286 467 ../sound/voice2.wav;
#X text 335 395 read input sound;
#X text 323 499 choose a file;
#X obj 270 393 loadbang;
#X obj 348 525 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X text 374 520 record 2 sec, f 6;
#X floatatom 274 580 8 0 0 0 - - - 0;
#X text 339 580 length in ms;
#X text 234 329 0 = silent 100 = all, f 10;
#X text 341 329 100 = silent 0 = all, f 12;
#X obj 492 337 loadbang;
#X obj 483 494 s window-size;
#X floatatom 483 460 5 0 0 0 - - - 0;
#X connect 0 0 2 0;
#X connect 1 0 17 0;
#X connect 3 0 6 0;
#X connect 5 0 6 1;
#X connect 6 0 0 0;
#X connect 9 0 16 0;
#X connect 10 0 6 2;
#X connect 12 0 39 0;
#X connect 13 0 39 0;
#X connect 14 0 39 0;
#X connect 15 0 39 0;
#X connect 23 0 33 0;
#X connect 24 0 23 0;
#X connect 25 0 23 0;
#X connect 26 0 23 0;
#X connect 27 0 23 0;
#X connect 30 0 25 0;
#X connect 31 0 23 1;
#X connect 37 0 13 0;
#X connect 39 0 38 0;
