#N canvas 479 38 802 656 12;
#X declare -stdpath ./;
#X floatatom 468 319 4 0 0 0 - - - 0;
#N canvas 293 108 791 659 fft 0;
#X obj 98 224 *~;
#X obj 66 224 *~;
#X obj 66 167 *~;
#X obj 66 139 inlet~;
#X obj 66 194 rfft~;
#X obj 66 324 *~;
#X obj 66 435 rifft~;
#X obj 102 168 tabreceive~ \$0-hann;
#X obj 366 217 samplerate~;
#X obj 357 173 bang~;
#X obj 366 242 t f b, f 6;
#X obj 352 66 r window-size;
#X obj 352 112 block~;
#X obj 366 266 osc~;
#X msg 405 266 0;
#X obj 66 466 *~;
#X obj 102 467 tabreceive~ \$0-hann;
#X obj 66 595 outlet~;
#X obj 112 384 r window-size;
#X obj 66 410 /~ 1000;
#X msg 352 88 set \$1 2;
#X obj 429 312 r \$0-start;
#X obj 357 367 spigot;
#X msg 429 339 1;
#X msg 396 339 0;
#X obj 357 595 outlet;
#X obj 400 449 r window-size;
#X obj 400 519 t f b;
#X obj 432 542 samplerate~;
#X obj 400 542 /;
#X obj 400 565 * 1000;
#X obj 357 541 del;
#X obj 400 473 / 2;
#X obj 400 496 - 1;
#X text 111 268 magnitude of FT;
#X text 77 346 align partials to middle of window;
#X text 98 329 alternate every other sign to;
#X text 409 173 control computations to do every frame;
#X text 65 618 output phase-aligned frames;
#X text 351 618 output a bang to start recording;
#X obj 66 267 sqrt~;
#X text 456 205 set sample rate of the oscillator to Nyquist (here we're operating at twice the global sample rate (queried from [samplerate~]) because of the overlap-2 blocking.) Also set phase to zero at beginning of frame., f 39;
#X text 465 331 When analysis starts \, set a delay to one frame minus a sample (i.e. \, just one 64-sample block before the next frame) which is synchronized with the first frame emerging from [outlet~] at left. In the parent window this is used to start recording synchronously., f 40;
#X connect 0 0 40 0;
#X connect 1 0 40 0;
#X connect 2 0 4 0;
#X connect 3 0 2 0;
#X connect 4 0 1 0;
#X connect 4 0 1 1;
#X connect 4 1 0 0;
#X connect 4 1 0 1;
#X connect 5 0 19 0;
#X connect 6 0 15 0;
#X connect 7 0 2 1;
#X connect 8 0 10 0;
#X connect 9 0 8 0;
#X connect 9 0 22 0;
#X connect 10 0 13 0;
#X connect 10 1 14 0;
#X connect 11 0 20 0;
#X connect 13 0 5 1;
#X connect 14 0 13 1;
#X connect 15 0 17 0;
#X connect 16 0 15 1;
#X connect 18 0 19 1;
#X connect 19 0 6 0;
#X connect 20 0 12 0;
#X connect 21 0 23 0;
#X connect 22 0 24 0;
#X connect 22 0 31 0;
#X connect 23 0 22 1;
#X connect 24 0 22 1;
#X connect 26 0 32 0;
#X connect 27 0 29 0;
#X connect 27 1 28 0;
#X connect 28 0 29 1;
#X connect 29 0 30 0;
#X connect 30 0 31 1;
#X connect 31 0 25 0;
#X connect 32 0 33 0;
#X connect 33 0 27 0;
#X connect 40 0 5 0;
#X restore 99 497 pd fft;
#X floatatom 639 382 5 0 120 0 - pitch-set - 0;
#X floatatom 638 322 5 0 0 0 - specshift-set - 0;
#X obj 638 349 s specshift;
#X obj 468 426 s loco;
#X obj 639 415 s pitch;
#X obj 457 522 output~;
#X floatatom 273 417 8 0 0 0 - \$0-samp-msec - 0;
#X msg 266 296 ../sound/bell.aiff;
#X msg 260 273 ../sound/voice.wav;
#X msg 275 321 ../sound/voice2.wav;
#X text 258 223 change input sound;
#N canvas 331 87 488 425 test-signal 0;
#X obj 50 247 line~;
#X obj 50 167 f;
#X obj 50 379 outlet~;
#X msg 50 221 0 \, \$1 \$2;
#X obj 50 195 pack 0 0;
#X obj 152 164 /;
#X obj 195 163 * 0.001;
#X obj 50 275 tabread4~ \$0-sample;
#X obj 227 289 adc~ 1;
#X obj 317 62 inlet;
#X obj 349 173 samplerate~;
#X obj 152 77 r \$0-samplength;
#X obj 163 108 r \$0-insamprate;
#X obj 49 60 inlet;
#X obj 349 197 s \$0-insamprate;
#X obj 227 324 *~;
#X obj 281 267 del;
#X obj 317 146 t b b;
#X msg 317 300 1;
#X msg 281 296 0;
#X obj 50 343 hip~ 5;
#X obj 50 314 +~;
#X obj 143 227 s \$0-start;
#X text 35 27 play sample once;
#X obj 163 137 t b f;
#X connect 0 0 7 0;
#X connect 1 0 4 0;
#X connect 3 0 0 0;
#X connect 4 0 3 0;
#X connect 5 0 4 1;
#X connect 5 0 16 1;
#X connect 6 0 5 1;
#X connect 7 0 21 0;
#X connect 8 0 15 0;
#X connect 9 0 17 0;
#X connect 10 0 14 0;
#X connect 11 0 1 1;
#X connect 11 0 5 0;
#X connect 12 0 24 0;
#X connect 13 0 1 0;
#X connect 13 0 22 0;
#X connect 15 0 21 1;
#X connect 16 0 19 0;
#X connect 17 0 18 0;
#X connect 17 0 16 0;
#X connect 17 0 22 0;
#X connect 17 1 10 0;
#X connect 18 0 15 1;
#X connect 19 0 15 1;
#X connect 20 0 2 0;
#X connect 21 0 20 0;
#X connect 24 0 5 0;
#X connect 24 1 6 0;
#X restore 99 469 pd test-signal;
#N canvas 248 155 565 454 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 82 311 graph;
#X obj 378 165 osc~;
#X obj 378 190 *~ -0.5;
#X obj 378 214 +~ 0.5;
#X obj 331 247 tabwrite~ \$0-hann;
#X obj 37 88 r window-size;
#X obj 38 173 /;
#X obj 127 142 samplerate~;
#X obj 38 251 s window-sec;
#X obj 177 204 swap;
#X obj 177 228 /;
#X obj 177 252 s window-hz;
#X obj 49 201 * 1000;
#X obj 49 228 s window-msec;
#X obj 38 115 t f b f;
#X msg 173 92 resize \$1;
#X obj 173 116 s \$0-hann;
#X obj 330 105 r window-hz;
#X msg 382 130 0;
#X obj 330 131 t f b;
#X text 15 8 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).;
#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 80 363 pd hann-window;
#X msg 79 241 512;
#X msg 85 262 1024;
#X msg 91 284 2048;
#X obj 79 331 s window-size;
#X msg 96 306 4096;
#X text 108 402 ---analyze---;
#X text 92 421 sample;
#X obj 138 529 tabwrite~ \$0-nophase;
#X obj 99 561 output~;
#X msg 476 367 0 \, 400 4000;
#X msg 481 394 0 \, 400 10000;
#X text 55 61 This patch takes an incoming sound \, does an overlap-2 FFT analysis of it \, and bashes the phases of the spectra so that when regenerated the components will all have zero phase at the middle of each window. You can use the windows as waveforms and cross-fade them at will without getting phase modulation. This might be useful for making synthetic instruments that mimic the spectral variation of recorded sounds., f 46;
#X text 564 359 normal speed, f 6;
#X text 574 393 slow;
#X text 509 254 ------ playback -------;
#N canvas 226 38 923 890 playback 0;
#X obj 170 619 r invblk;
#X obj 71 646 *~;
#X obj 132 644 clip~ 1 1000;
#X floatatom 157 129 0 0 0 0 - - - 0;
#X floatatom 592 48 0 0 0 0 - - - 0;
#X obj 491 622 *~;
#X obj 637 592 samphold~;
#X obj 724 592 samphold~;
#X obj 532 592 samphold~;
#X obj 476 734 clip~ -0.5 0.5;
#X obj 476 757 cos~;
#X obj 654 680 +~;
#X obj 655 759 -~;
#X obj 637 786 *~;
#X obj 665 811 +~;
#X obj 647 835 *~;
#X obj 89 575 *~;
#X obj 257 555 samphold~;
#X obj 365 582 samphold~;
#X obj 592 448 phasor~;
#X obj 257 311 wrap~;
#X obj 592 23 r pitch;
#X obj 592 97 mtof;
#X obj 365 254 line~;
#X obj 365 354 -~;
#X text 127 82 spectral stretch;
#X obj 132 528 samphold~;
#X obj 698 335 t b f, f 8;
#X obj 733 360 /;
#X obj 71 671 clip~ -0.5 0.5;
#X obj 71 693 cos~;
#X obj 282 619 +~;
#X obj 275 698 -~;
#X obj 257 721 *~;
#X obj 294 746 +~;
#X text 431 232 samples;
#X text 431 217 period in;
#X text 263 575 weight for;
#X text 263 590 next block;
#X obj 592 515 wrap~;
#X obj 733 385 s invblk;
#X obj 572 679 r invblk;
#X obj 698 259 r window-size;
#X obj 157 105 r specshift;
#X obj 275 62 r loco;
#X obj 476 704 *~;
#X obj 532 704 clip~ 1 1000;
#X obj 592 72 - 12;
#X obj 157 176 + 69;
#X obj 157 199 mtof;
#X obj 157 222 / 440;
#X obj 132 314 *~ 1;
#X obj 592 490 +~ 0.5;
#X obj 132 619 *~ 1;
#X obj 532 679 *~ 1;
#X obj 476 779 +~ 1;
#X obj 71 716 +~ 1;
#X obj 365 435 *~ 1;
#X obj 275 646 +~ 0;
#X obj 655 709 +~ 0;
#X obj 71 527 -~ 0.5;
#X obj 476 592 -~ 0.5;
#X obj 276 866 outlet~;
#X obj 275 672 tabread4~ \$0-nophase;
#X obj 312 698 tabread4~ \$0-nophase;
#X obj 655 733 tabread4~ \$0-nophase;
#X obj 690 758 tabread4~ \$0-nophase;
#X obj 365 377 +~ 0.5;
#X text 139 550 grain size;
#X text 392 354 integer part of loc;
#X text 419 378 middle of block;
#X text 312 416 convert to samples, f 10;
#X text 657 440 run two copies 180 degrees out of phase, f 20;
#X obj 276 771 *~;
#X obj 276 812 +~;
#X obj 712 309 s blksize;
#X obj 686 682 r blksize;
#X obj 320 647 r blksize;
#X obj 406 405 r blksize;
#X obj 698 283 / 2;
#X obj 429 195 /;
#X obj 429 168 samplerate~;
#X obj 429 145 t b f;
#X obj 157 152 * 0.125;
#X text 328 51 read location in sec/100, f 13;
#X obj 307 178 samplerate~;
#X obj 275 131 / 100;
#X obj 275 155 t f b;
#X obj 275 178 *;
#X obj 308 203 r blksize;
#X obj 275 203 /;
#X text 210 167 read location \, blocks, f 9;
#X msg 661 135 set \$1;
#X obj 787 111 r pitch;
#X msg 787 135 set \$1;
#X obj 661 111 r specshift;
#X text 763 360 1/(block size);
#X obj 661 159 s specshift-set;
#X obj 787 159 s pitch-set;
#X text 120 14 OVERLAPPED \, WINDOWED SAMPLE PLAYBACK;
#X text 658 70 - with controls for pitch \, location \, and spectral shift, f 28;
#X text 685 204 analysis overlap was 2 so our block size is (window size)/2, f 20;
#X obj 275 88 unpack float float;
#X text 35 745 window shaped by raised cos, f 13;
#X text 22 560 offset into ==> sample, f 9;
#X text 389 601 middle of block, f 8;
#X text 328 719 weighted sum of 2 windows, f 12;
#X text 175 302 fractional part of loc, f 11;
#X text 81 241 grain size in samples, f 10;
#X msg 698 357 1;
#X connect 0 0 53 1;
#X connect 1 0 29 0;
#X connect 2 0 1 1;
#X connect 3 0 83 0;
#X connect 4 0 47 0;
#X connect 5 0 11 0;
#X connect 6 0 13 0;
#X connect 7 0 11 1;
#X connect 8 0 5 1;
#X connect 8 0 54 0;
#X connect 9 0 10 0;
#X connect 10 0 55 0;
#X connect 11 0 59 0;
#X connect 11 0 66 0;
#X connect 12 0 13 1;
#X connect 13 0 14 0;
#X connect 14 0 15 1;
#X connect 15 0 74 1;
#X connect 16 0 31 0;
#X connect 17 0 33 0;
#X connect 18 0 31 1;
#X connect 19 0 26 1;
#X connect 19 0 18 1;
#X connect 19 0 17 1;
#X connect 19 0 52 0;
#X connect 19 0 60 0;
#X connect 20 0 24 1;
#X connect 20 0 17 0;
#X connect 20 0 6 0;
#X connect 21 0 4 0;
#X connect 22 0 19 0;
#X connect 22 0 82 0;
#X connect 23 0 20 0;
#X connect 23 0 24 0;
#X connect 24 0 67 0;
#X connect 26 0 16 1;
#X connect 26 0 53 0;
#X connect 27 0 109 0;
#X connect 27 1 28 1;
#X connect 28 0 40 0;
#X connect 29 0 30 0;
#X connect 30 0 56 0;
#X connect 31 0 58 0;
#X connect 31 0 64 0;
#X connect 32 0 33 1;
#X connect 33 0 34 0;
#X connect 34 0 73 1;
#X connect 39 0 8 1;
#X connect 39 0 6 1;
#X connect 39 0 7 1;
#X connect 39 0 61 0;
#X connect 41 0 54 1;
#X connect 42 0 79 0;
#X connect 43 0 3 0;
#X connect 44 0 102 0;
#X connect 45 0 9 0;
#X connect 46 0 45 1;
#X connect 47 0 22 0;
#X connect 48 0 49 0;
#X connect 49 0 50 0;
#X connect 50 0 51 1;
#X connect 51 0 26 0;
#X connect 51 0 8 0;
#X connect 52 0 39 0;
#X connect 53 0 2 0;
#X connect 54 0 46 0;
#X connect 55 0 15 0;
#X connect 56 0 73 0;
#X connect 57 0 18 0;
#X connect 57 0 7 0;
#X connect 58 0 63 0;
#X connect 59 0 65 0;
#X connect 60 0 16 0;
#X connect 60 0 1 0;
#X connect 61 0 5 0;
#X connect 61 0 45 0;
#X connect 63 0 32 0;
#X connect 64 0 32 1;
#X connect 64 0 34 1;
#X connect 65 0 12 0;
#X connect 66 0 12 1;
#X connect 66 0 14 1;
#X connect 67 0 57 0;
#X connect 73 0 74 0;
#X connect 74 0 62 0;
#X connect 76 0 59 1;
#X connect 77 0 58 1;
#X connect 78 0 57 1;
#X connect 79 0 75 0;
#X connect 79 0 27 0;
#X connect 80 0 51 0;
#X connect 81 0 80 0;
#X connect 82 0 81 0;
#X connect 82 1 80 1;
#X connect 83 0 48 0;
#X connect 85 0 88 1;
#X connect 86 0 87 0;
#X connect 87 0 88 0;
#X connect 87 1 85 0;
#X connect 88 0 90 0;
#X connect 89 0 90 1;
#X connect 90 0 23 0;
#X connect 92 0 97 0;
#X connect 93 0 94 0;
#X connect 94 0 98 0;
#X connect 95 0 92 0;
#X connect 102 0 86 0;
#X connect 102 1 23 1;
#X connect 109 0 28 0;
#X restore 457 484 pd playback;
#X text 685 315 octave);
#X text 181 420 live;
#X text 400 64 You can save the analyses and needn't be running the FFT patch to do the resynthesis. You can read a sample \, select window size \, and press "sample" to analyze it \, or else analyze a "live" input. You'll hear the phase-bashed sample as the analysis runs. You can regenerate the sound with specified pitch \, sample location \, and spectral shift \, using the "playback" controls., f 44;
#X text 137 248 analysis;
#X text 134 234 (redo;
#X text 137 264 after;
#X text 138 279 changing;
#X text 138 295 window;
#X text 139 309 size);
#X obj 468 342 pack f 100;
#X obj 194 440 bng 19 250 50 0 empty empty empty 0 -6 0 8 #dfdfdf #000000 #000000;
#X obj 99 439 bng 19 250 50 0 empty empty empty 0 -6 0 8 #dfdfdf #000000 #000000;
#X text 636 285 spectral shift (hundredths of, f 14;
#X text 462 281 location in sample (hundredths of sec), f 19;
#X obj 35 23 cnv 5 5 25 empty empty Phase\ Bashing 15 13 0 16 #dfdfdf #202020 0;
#N canvas 627 119 765 557 insample 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-sample 62079 float 2;
#X coords 0 1 62079 -1 400 150 1;
#X restore 325 124 graph;
#X obj 96 230 soundfiler;
#X obj 149 151 symbol \$0-sample;
#X obj 96 181 pack s s;
#X msg 96 206 read -resize \$1 \$2;
#X obj 95 396 s \$0-samplength;
#X obj 117 305 /;
#X obj 117 329 * 1000;
#X obj 117 353 s \$0-samp-msec;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-nophase 62079 float 2;
#X coords 0 1 62079 -1 400 150 1;
#X restore 324 309 graph;
#X msg 96 450 resize \$1;
#X obj 96 426 r \$0-samplength;
#X obj 96 475 s \$0-nophase;
#X msg 163 257 \$1;
#X obj 163 296 s \$0-insamprate;
#X obj 96 146 t a b;
#X obj 29 36 inlet;
#X obj 29 80 route bang;
#X obj 28 115 openpanel;
#X connect 1 0 5 0;
#X connect 1 0 6 0;
#X connect 1 1 13 0;
#X connect 2 0 3 1;
#X connect 3 0 4 0;
#X connect 4 0 1 0;
#X connect 6 0 7 0;
#X connect 7 0 8 0;
#X connect 10 0 12 0;
#X connect 11 0 10 0;
#X connect 13 0 6 1;
#X connect 13 0 14 0;
#X connect 15 0 3 0;
#X connect 15 1 2 0;
#X connect 16 0 17 0;
#X connect 17 0 18 0;
#X connect 17 1 15 0;
#X connect 18 0 15 0;
#X restore 259 380 pd insample;
#X obj 260 247 loadbang;
#X obj 287 350 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X text 311 351 choose sample;
#X text 249 443 sample length (ms);
#N canvas 900 402 450 300 init 0;
#X obj 141 231 declare -stdpath ./;
#X obj 121 103 loadbang;
#X msg 121 129 \; window-size 1024 \; pitch 48 \; specshift 0;
#X text 85 36 This subpatch initializes the patch., f 27;
#X connect 1 0 2 0;
#X restore 654 537 pd init;
#X connect 0 0 40 0;
#X connect 1 0 22 0;
#X connect 1 0 23 0;
#X connect 1 1 22 0;
#X connect 2 0 6 0;
#X connect 3 0 4 0;
#X connect 9 0 46 0;
#X connect 10 0 46 0;
#X connect 11 0 46 0;
#X connect 13 0 1 0;
#X connect 15 0 18 0;
#X connect 16 0 18 0;
#X connect 17 0 18 0;
#X connect 19 0 18 0;
#X connect 24 0 5 0;
#X connect 25 0 5 0;
#X connect 30 0 7 0;
#X connect 40 0 5 0;
#X connect 41 0 13 1;
#X connect 42 0 13 0;
#X connect 47 0 10 0;
#X connect 48 0 46 0;
