#N canvas 614 71 618 619 12;
#N canvas 447 24 682 824 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 498 40 loadbang;
#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 msg 498 65 \; pd dsp 1 \; window-size 1024;
#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 24 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 23 0;
#X connect 5 1 0 0;
#X connect 5 1 2 0;
#X connect 5 1 2 1;
#X connect 5 1 22 0;
#X connect 6 0 1 0;
#X connect 8 0 24 0;
#X connect 9 0 23 1;
#X connect 9 0 22 1;
#X connect 10 0 31 0;
#X connect 11 0 6 0;
#X connect 12 0 3 1;
#X connect 13 0 19 0;
#X connect 14 0 17 0;
#X connect 15 0 1 1;
#X connect 16 0 32 0;
#X connect 17 0 18 0;
#X connect 20 0 58 0;
#X connect 21 0 20 1;
#X connect 22 0 26 0;
#X connect 22 0 28 0;
#X connect 22 0 53 0;
#X connect 22 0 54 0;
#X connect 23 0 25 0;
#X connect 23 0 27 0;
#X connect 23 0 51 0;
#X connect 23 0 52 0;
#X connect 24 0 9 0;
#X connect 25 0 51 1;
#X connect 26 0 53 1;
#X connect 27 0 52 1;
#X connect 28 0 54 1;
#X connect 29 0 32 1;
#X connect 30 0 33 0;
#X connect 30 0 35 0;
#X connect 30 0 34 0;
#X connect 31 0 30 0;
#X connect 32 0 10 0;
#X connect 32 0 37 0;
#X connect 33 0 36 0;
#X connect 34 0 33 1;
#X connect 35 0 36 1;
#X connect 36 0 46 0;
#X connect 37 0 39 0;
#X connect 38 0 40 0;
#X connect 38 0 42 0;
#X connect 38 0 41 0;
#X connect 39 0 38 0;
#X connect 40 0 43 0;
#X connect 41 0 40 1;
#X connect 42 0 43 1;
#X connect 43 0 44 0;
#X connect 44 0 45 0;
#X connect 45 0 46 1;
#X connect 46 0 20 0;
#X connect 47 0 32 1;
#X connect 48 0 32 0;
#X connect 51 0 48 0;
#X connect 51 0 48 1;
#X connect 52 0 16 0;
#X connect 52 0 16 1;
#X connect 53 0 47 0;
#X connect 53 0 47 1;
#X connect 54 0 29 0;
#X connect 54 0 29 1;
#X connect 56 0 58 1;
#X connect 57 0 56 0;
#X connect 58 0 11 1;
#X connect 58 0 0 1;
#X connect 59 0 10 1;
#X connect 60 0 37 1;
#X connect 61 0 59 0;
#X connect 62 0 60 0;
#X restore 59 408 pd fft-analysis;
#X floatatom 338 279 0 0 100 0 - - -;
#X text 60 12 PITCHED/UNPITCHED SEPARATION;
#X obj 59 443 output~;
#X floatatom 59 348 0 0 100 0 - - -;
#X text 103 329 noise;
#X floatatom 106 348 0 0 100 0 - - -;
#N canvas 272 180 466 593 test-signal 0;
#X obj 72 295 line~;
#X obj 242 395 *~;
#X obj 72 409 *~;
#X obj 242 286 noise~;
#X obj 224 457 +~;
#X obj 90 382 dbtorms;
#X obj 260 369 dbtorms;
#X obj 90 357 inlet;
#X obj 260 345 inlet;
#X obj 223 535 outlet~;
#X msg 72 267 0 \, \$1 \$2;
#X obj 181 212 /;
#X obj 196 160 * 0.001;
#X obj 196 186 t b f;
#X obj 223 507 hip~ 5;
#X obj 72 100 loadbang;
#X obj 72 146 metro 1000;
#X obj 242 311 bp~ 10000 3;
#X obj 72 125 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
;
#X text 215 211 sample duration \, msec;
#X text 87 69 looped sample playback;
#X obj 72 323 tabread4~ \$0-sample;
#X text 239 259 filtered noise;
#X text 67 16 TEST SIGNAL: looped sample plus noise. The inlets control
amplitude of each in dB., f 42;
#X obj 181 113 r \$0-samplength;
#X obj 196 137 r \$0-insamprate;
#X obj 353 433 *~;
#X obj 371 407 dbtorms;
#X obj 371 383 inlet;
#X text 350 297 osc;
#X obj 353 323 osc~ 440;
#X obj 224 482 *~ 3;
#X obj 72 214 float;
#X obj 72 240 pack float float;
#X connect 0 0 21 0;
#X connect 1 0 4 1;
#X connect 2 0 4 0;
#X connect 3 0 17 0;
#X connect 4 0 31 0;
#X connect 5 0 2 1;
#X connect 6 0 1 1;
#X connect 7 0 5 0;
#X connect 8 0 6 0;
#X connect 10 0 0 0;
#X connect 11 0 16 1;
#X connect 11 0 33 1;
#X connect 12 0 13 0;
#X connect 13 0 11 0;
#X connect 13 1 11 1;
#X connect 14 0 9 0;
#X connect 15 0 18 0;
#X connect 16 0 32 0;
#X connect 17 0 1 0;
#X connect 18 0 16 0;
#X connect 21 0 2 0;
#X connect 24 0 11 0;
#X connect 24 0 32 1;
#X connect 25 0 12 0;
#X connect 26 0 4 1;
#X connect 27 0 26 1;
#X connect 28 0 27 0;
#X connect 30 0 26 0;
#X connect 31 0 14 0;
#X connect 32 0 33 0;
#X connect 33 0 10 0;
#X restore 59 377 pd test-signal;
#X text 43 326 sampler;
#X text 64 306 amplitudes (dB);
#N canvas 388 86 722 350 insample 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-sample 155944 float 0;
#X coords 0 1 155943 -1 400 150 1;
#X restore 259 38 graph;
#X obj 19 23 r read-sample;
#X obj 19 74 unpack s f;
#X obj 19 184 soundfiler;
#X text 356 250 read a sample;
#X obj 276 249 loadbang;
#X obj 19 100 t s b;
#X obj 72 105 symbol \$0-sample;
#X obj 19 135 pack s s;
#X msg 19 160 read -resize \$1 \$2;
#X obj 19 47 t a b;
#X msg 276 273 \; read-sample ../sound/bell.aiff;
#X obj 29 210 s \$0-samplength;
#X obj 116 74 s \$0-insamprate;
#X obj 19 247 /;
#X obj 19 271 * 1000;
#X obj 19 294 s \$0-samp-msec;
#X obj 55 244 r \$0-insamprate;
#X obj 116 49 f 44100;
#X connect 1 0 10 0;
#X connect 2 0 6 0;
#X connect 2 1 13 0;
#X connect 3 0 12 0;
#X connect 3 0 14 0;
#X connect 5 0 11 0;
#X connect 6 0 8 0;
#X connect 6 1 7 0;
#X connect 7 0 8 1;
#X connect 8 0 9 0;
#X connect 9 0 3 0;
#X connect 10 0 2 0;
#X connect 10 1 18 0;
#X connect 14 0 15 0;
#X connect 15 0 16 0;
#X connect 17 0 14 1;
#X connect 18 0 13 0;
#X restore 216 496 pd insample;
#X msg 216 395 ../sound/bell.aiff;
#X msg 223 418 ../sound/voice.wav;
#X msg 230 441 ../sound/voice2.wav;
#X text 219 375 change input sound;
#X obj 216 468 s read-sample;
#X floatatom 216 523 5 0 0 0 - #0-samp-msec -;
#X text 269 522 sample length \, msec;
#X floatatom 216 277 0 0 100 0 - - -;
#X floatatom 154 348 0 0 100 0 - - -;
#X text 152 328 osc;
#X msg 436 296 512;
#X msg 442 319 1024;
#X msg 447 343 2048;
#X obj 436 392 s window-size;
#X msg 453 366 4096;
#X obj 216 300 s clean;
#X text 216 323 0=silent;
#X text 214 343 100=all;
#X obj 338 302 s dirty;
#X text 334 323 100=silent;
#X text 336 340 0=all;
#X text 351 566 updated for Pd version 0.39;
#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 67;
#X text 43 48 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 67;
#N canvas 577 259 559 559 tables 0;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-inc-imag 2048 float 2;
#X coords 0 1 2048 -1 200 140 1;
#X restore 289 389 graph;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-inc-real 2048 float 2;
#X coords 0 1 2048 -1 200 140 1 0 0;
#X restore 77 388 graph;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-precess-imag 2048 float 2;
#X coords 0 1 2048 -1 200 140 1 0 0;
#X restore 289 209 graph;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-precess-real 2048 float 2;
#X coords 0 1 2048 -1 200 140 1 0 0;
#X restore 77 208 graph;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-last-imag 2048 float 2;
#X coords 0 1 2048 -1 200 140 1 0 0;
#X restore 289 39 graph;
#N canvas 0 22 450 278 (subpatch) 0;
#X array \$0-last-real 2048 float 2;
#X coords 0 1 2048 -1 200 140 1 0 0;
#X restore 77 38 graph;
#X restore 435 465 pd tables;
#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 435 440 pd hann-window;
#X connect 0 0 3 0;
#X connect 0 0 3 1;
#X connect 1 0 29 0;
#X connect 4 0 7 0;
#X connect 6 0 7 1;
#X connect 7 0 0 0;
#X connect 11 0 15 0;
#X connect 12 0 15 0;
#X connect 13 0 15 0;
#X connect 18 0 26 0;
#X connect 19 0 7 2;
#X connect 21 0 24 0;
#X connect 22 0 24 0;
#X connect 23 0 24 0;
#X connect 25 0 24 0;
