#N canvas 551 103 763 598 12;
#X floatatom 480 282 5 0 0 0 - transpo-set -;
#X floatatom 186 319 3 0 0 0 - speed-set -;
#X floatatom 93 321 7 0 0 0 - location-set -;
#N canvas 471 44 754 709 fft-analysis 0;
#X obj 56 486 *~;
#X obj 23 486 *~;
#X obj 23 508 -~;
#X obj 172 484 *~;
#X obj 141 484 *~;
#X obj 141 506 +~;
#X obj 114 202 *~;
#X obj 83 202 *~;
#X obj 55 202 *~;
#X obj 24 202 *~;
#X obj 24 227 +~;
#X obj 128 394 *~;
#X obj 24 631 *~;
#X obj 239 439 rfft~;
#X obj 123 170 rfft~;
#X obj 23 573 rifft~;
#X obj 25 655 outlet~;
#X obj 98 394 *~;
#X obj 98 416 +~;
#X obj 129 227 -~;
#X obj 23 440 *~;
#X obj 56 441 *~;
#X obj 127 633 r window-size;
#X obj 370 603 r window-size;
#X obj 370 652 block~;
#X obj 24 358 +~ 1e-15;
#X obj 23 607 *~;
#X obj 56 607 tabreceive~ \$0-hann;
#X obj 127 655 expr 2/(3*$f1);
#X obj 555 572 loadbang;
#X msg 555 598 \; pd dsp 1 \; window-size 2048 \; transpo 0 \; rewind
bang;
#X msg 370 627 set \$1 4;
#X obj 98 440 q8_rsqrt~;
#N canvas 210 23 1029 784 read-windows 0;
#X obj 146 667 *~;
#X obj 469 418 r window-size;
#X obj 276 282 f;
#X obj 200 51 r window-size;
#X obj 200 99 /;
#X obj 325 669 *~;
#X obj 276 231 bang~;
#X obj 146 531 line~;
#X obj 200 124 * 1000;
#X obj 398 196 r speed;
#X obj 294 256 r location;
#X obj 318 284 +;
#X obj 398 249 *;
#X obj 294 341 / 1000;
#X obj 276 368 *;
#X text 308 368 reading location (samples);
#X obj 165 574 / 4;
#X obj 398 219 * 0.01;
#X floatatom 469 475 7 0 0 0 - - -;
#X obj 469 451 *;
#X obj 589 324 r transpo;
#X obj 589 348 * 0.01;
#X obj 589 372 + 69;
#X obj 589 397 mtof;
#X obj 589 424 / 440;
#X obj 504 451 t b f;
#X obj 146 693 outlet~;
#X obj 325 694 outlet~;
#X obj 343 638 tabreceive~ \$0-hann;
#X obj 763 390 r location;
#X msg 763 413 0;
#X obj 763 436 s speed;
#X obj 778 530 r speed;
#X msg 778 554 set \$1;
#X obj 778 579 s speed-set;
#X text 527 473 stretched window size (samples), f 16;
#X obj 887 529 r transpo;
#X msg 887 555 set \$1;
#X obj 887 580 s transpo-set;
#X obj 821 123 r location;
#X msg 835 309 set \$1;
#X obj 821 169 t b f;
#X obj 835 286 f;
#X obj 763 200 int;
#X obj 763 232 sel 0;
#X msg 822 203 1;
#X msg 822 226 0;
#X obj 763 257 del 300;
#X obj 835 335 s location-set;
#X obj 146 631 tabread4~ \$0-sample;
#X obj 324 611 tabread4~ \$0-sample;
#X obj 294 317 r \$0-insamprate;
#X obj 521 522 r rewind;
#X msg 521 700 \; location \$1;
#X floatatom 199 146 5 0 0 0 - - -;
#X obj 200 75 t f b;
#X obj 232 99 samplerate~;
#X obj 199 171 / 4;
#X obj 353 288 s see-loc;
#X obj 830 145 r see-loc;
#X obj 313 394 / 2;
#X obj 276 394 -;
#X text 349 391 back up 1/2 window;
#X obj 146 597 -~;
#X text 337 52 Read two windows out of the recorded sample \, one 1/4
ahead of the other. The mid point of the front window is specified
by "location". If "speed" is nonzero \, "location" automatically precesses.
, f 45;
#X obj 521 676 * -0.5;
#X text 24 582 "back" window 1/4 cycle behind "front" one, f 16;
#X text 230 171 computation period (msec) for overlap of 4;
#X text 252 145 msec in a window;
#X obj 521 622 /;
#X obj 521 650 * 1000;
#X obj 521 598 t f b;
#X obj 553 622 samplerate~;
#X obj 521 575 f;
#X msg 890 680 \; rewind bang \; speed \$1;
#X obj 890 653 r auto;
#X obj 775 654 r no-detune;
#X text 766 484 reflect control changes;
#X text 766 501 in main window.;
#X text 805 622 misc controls;
#X obj 146 449 f;
#X obj 146 420 b;
#X msg 146 503 0 \, \$1 \$2;
#X msg 775 676 \; transpo 0;
#X text 717 63 if location changes \, update number box in main window
via "location-set" \, but taking care to limit frequency of updates.
, f 38;
#X text 841 402 setting location by hand sets speed to zero., f 19
;
#X text 550 547 "rewind" control takes us to a location depending on
stretched window size., f 25;
#X text 434 242 loop to precess the location according to the "speed"
parameter., f 22;
#X obj 146 476 pack f f;
#X connect 0 0 26 0;
#X connect 1 0 19 0;
#X connect 2 0 11 0;
#X connect 2 0 14 0;
#X connect 3 0 55 0;
#X connect 4 0 8 0;
#X connect 5 0 27 0;
#X connect 6 0 2 0;
#X connect 7 0 63 0;
#X connect 7 0 50 0;
#X connect 8 0 54 0;
#X connect 9 0 17 0;
#X connect 10 0 2 1;
#X connect 11 0 2 1;
#X connect 11 0 58 0;
#X connect 12 0 11 1;
#X connect 13 0 14 1;
#X connect 14 0 61 0;
#X connect 16 0 63 1;
#X connect 17 0 12 0;
#X connect 18 0 16 0;
#X connect 18 0 60 0;
#X connect 18 0 73 1;
#X connect 18 0 80 1;
#X connect 19 0 18 0;
#X connect 20 0 21 0;
#X connect 21 0 22 0;
#X connect 22 0 23 0;
#X connect 23 0 24 0;
#X connect 24 0 25 0;
#X connect 25 0 19 0;
#X connect 25 1 19 1;
#X connect 28 0 5 1;
#X connect 28 0 0 1;
#X connect 29 0 30 0;
#X connect 30 0 31 0;
#X connect 32 0 33 0;
#X connect 33 0 34 0;
#X connect 36 0 37 0;
#X connect 37 0 38 0;
#X connect 39 0 41 0;
#X connect 40 0 48 0;
#X connect 41 0 43 0;
#X connect 41 1 42 1;
#X connect 42 0 40 0;
#X connect 43 0 44 0;
#X connect 44 0 45 0;
#X connect 44 0 47 0;
#X connect 45 0 43 1;
#X connect 46 0 43 1;
#X connect 47 0 46 0;
#X connect 47 0 42 0;
#X connect 49 0 0 0;
#X connect 50 0 5 0;
#X connect 51 0 13 0;
#X connect 52 0 73 0;
#X connect 54 0 57 0;
#X connect 55 0 4 0;
#X connect 55 1 56 0;
#X connect 56 0 4 1;
#X connect 57 0 12 1;
#X connect 57 0 88 1;
#X connect 59 0 41 0;
#X connect 60 0 61 1;
#X connect 61 0 81 0;
#X connect 61 0 49 1;
#X connect 61 0 50 1;
#X connect 63 0 49 0;
#X connect 65 0 53 0;
#X connect 69 0 70 0;
#X connect 70 0 65 0;
#X connect 71 0 69 0;
#X connect 71 1 72 0;
#X connect 72 0 69 1;
#X connect 73 0 71 0;
#X connect 75 0 74 0;
#X connect 76 0 83 0;
#X connect 80 0 88 0;
#X connect 81 0 80 0;
#X connect 82 0 7 0;
#X connect 88 0 82 0;
#X restore 123 142 pd read-windows;
#X obj 141 541 tabsend~ prev-imag;
#X obj 140 574 tabsend~ prev-real;
#X obj 25 14 tabreceive~ prev-real;
#X obj 83 38 tabreceive~ prev-imag;
#X text 277 14 recall previous output amplitude. Its phase will be
added to the phase difference we measure from two windows in the the
recorded sound.;
#X obj 126 78 *~;
#X obj 99 78 *~;
#X obj 99 100 +~;
#X obj 164 103 q8_rsqrt~;
#X obj 164 80 +~ 1e-20;
#X obj 83 128 *~;
#X obj 24 127 *~;
#X obj 182 299 r lock;
#X obj 34 254 lrshift~ 1;
#X obj 29 278 lrshift~ -1;
#X obj 146 254 lrshift~ 1;
#X obj 138 278 lrshift~ -1;
#X obj 42 309 *~;
#X obj 164 321 *~;
#X obj 24 334 +~;
#X obj 130 321 +~;
#X text 252 75 divide by the magnitude to make a unit-magnitude complex
amplitude (phase only). The 1e-20 is to prevent overflows. q8_rsqrt~
is reciprocal square root.;
#X text 252 174 Take FT of the window in back. Multiply its conjugate
by the normalized previous output. The result has the magnitude of
the input sound and phase (previous output phase) minus (back window
phase).;
#X text 254 379 Normalize again \, this time taking care to salt each
channel with 1e-15 so that we get a unit complex number even if everything
was zero heretofore.;
#X text 287 435 Now take the FT of the forward window and multiply
it by the unit complex number from above. The magnitude will be that
of the forward window and the phase will be the previous output phase
plus the phase difference between the two analysis windows -- except
that if "lock" is on \, they will be modified to agree progressively
better with the inter-channel phase relationships of the input.;
#X text 254 251 If "lock" is on \, encourage neighboring channels to
stay in phase by adding the two neighboring complex amplitudes. The
result will tend toward the channel with the strongest amplitude. If
the phase relationships between channels in the output and those in
the input are in parallel \, then neighboring channels of the quotient
will all have the same phase and this will not change any phases. (lrshift
shifts the signal to the left or right depending on its argument.)
;
#X text 264 135 Read two windows \, one 1/4 length behind the other
\, of the input sound \, with Hann window function (see inside).;
#X text 341 566 'set' message to block allows variable size, f 22
;
#X connect 0 0 2 1;
#X connect 1 0 2 0;
#X connect 2 0 35 0;
#X connect 2 0 15 0;
#X connect 3 0 5 1;
#X connect 4 0 5 0;
#X connect 5 0 34 0;
#X connect 5 0 15 1;
#X connect 6 0 19 1;
#X connect 7 0 19 0;
#X connect 8 0 10 1;
#X connect 9 0 10 0;
#X connect 10 0 48 0;
#X connect 10 0 47 0;
#X connect 10 0 53 0;
#X connect 11 0 18 1;
#X connect 12 0 16 0;
#X connect 13 0 1 1;
#X connect 13 0 3 1;
#X connect 13 1 0 1;
#X connect 13 1 4 1;
#X connect 14 0 9 1;
#X connect 14 0 7 1;
#X connect 14 1 6 1;
#X connect 14 1 8 1;
#X connect 15 0 26 0;
#X connect 17 0 18 0;
#X connect 18 0 32 0;
#X connect 19 0 49 0;
#X connect 19 0 50 0;
#X connect 19 0 54 0;
#X connect 20 0 1 0;
#X connect 20 0 4 0;
#X connect 21 0 0 0;
#X connect 21 0 3 0;
#X connect 22 0 28 0;
#X connect 23 0 31 0;
#X connect 25 0 17 1;
#X connect 25 0 17 0;
#X connect 25 0 20 0;
#X connect 26 0 12 0;
#X connect 27 0 26 1;
#X connect 28 0 12 1;
#X connect 29 0 30 0;
#X connect 31 0 24 0;
#X connect 32 0 20 1;
#X connect 32 0 21 1;
#X connect 33 0 14 0;
#X connect 33 1 13 0;
#X connect 36 0 40 1;
#X connect 36 0 40 0;
#X connect 36 0 45 0;
#X connect 37 0 39 1;
#X connect 37 0 39 0;
#X connect 37 0 44 0;
#X connect 39 0 41 1;
#X connect 40 0 41 0;
#X connect 41 0 43 0;
#X connect 42 0 44 1;
#X connect 42 0 45 1;
#X connect 43 0 42 0;
#X connect 44 0 8 0;
#X connect 44 0 7 0;
#X connect 45 0 9 0;
#X connect 45 0 6 0;
#X connect 46 0 51 1;
#X connect 46 0 52 1;
#X connect 47 0 51 0;
#X connect 48 0 51 0;
#X connect 49 0 52 0;
#X connect 50 0 52 0;
#X connect 51 0 53 1;
#X connect 52 0 54 1;
#X connect 53 0 25 0;
#X connect 54 0 11 0;
#X connect 54 0 11 1;
#X connect 54 0 21 0;
#X restore 91 433 pd fft-analysis;
#N canvas 260 23 531 738 phase-tables 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array prev-imag 4096 float 0;
#X coords 0 1000 4096 -1000 400 300 1;
#X restore 67 395 graph;
#N canvas 0 0 450 300 (subpatch) 0;
#X array prev-real 4096 float 0;
#X coords 0 500 4096 -500 400 300 1;
#X restore 67 40 graph;
#X restore 437 469 pd phase-tables;
#X obj 480 305 s transpo;
#X text 183 300 hundredths;
#X text 479 261 in cents;
#X text 386 294 normal;
#X obj 91 471 output~;
#N canvas 385 188 595 536 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 437 493 pd hann-window;
#N canvas 410 109 731 456 insample 0;
#N canvas 0 0 450 300 (subpatch) 0;
#X array \$0-sample 62079 float 0;
#X coords 0 1 62078 -1 400 150 1;
#X restore 302 143 graph;
#X obj 59 141 r read-sample;
#X obj 59 192 unpack s f;
#X obj 59 302 soundfiler;
#X text 418 343 read a sample;
#X obj 338 342 loadbang;
#X obj 59 218 t s b;
#X obj 112 221 symbol \$0-sample;
#X obj 59 253 pack s s;
#X msg 59 278 read -resize \$1 \$2;
#X obj 59 165 t a b;
#X obj 69 331 s \$0-samplength;
#X obj 156 192 s \$0-insamprate;
#X obj 59 365 /;
#X obj 59 389 * 1000;
#X obj 59 412 s \$0-samp-msec;
#X obj 97 365 r \$0-insamprate;
#X obj 70 78 hip~ 5;
#X obj 70 54 adc~ 1;
#X obj 60 17 inlet;
#X obj 132 54 samplerate~;
#X obj 60 106 tabwrite~ \$0-sample;
#X obj 132 78 s \$0-insamprate;
#X msg 338 366 \; read-sample ../sound/voice.wav;
#X obj 306 28 inlet;
#X obj 306 50 openpanel;
#X obj 306 75 s read-sample;
#X obj 156 166 f 44100;
#X connect 1 0 10 0;
#X connect 2 0 6 0;
#X connect 2 1 12 0;
#X connect 3 0 11 0;
#X connect 3 0 13 0;
#X connect 5 0 23 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 27 0;
#X connect 13 0 14 0;
#X connect 14 0 15 0;
#X connect 16 0 13 1;
#X connect 17 0 21 0;
#X connect 18 0 17 0;
#X connect 19 0 20 0;
#X connect 19 0 21 0;
#X connect 20 0 22 0;
#X connect 24 0 25 0;
#X connect 25 0 26 0;
#X connect 27 0 12 0;
#X restore 438 445 pd insample;
#X floatatom 583 443 5 0 0 0 - #0-samp-msec -;
#X msg 235 439 ../sound/bell.aiff;
#X msg 244 462 ../sound/voice.wav;
#X msg 248 484 ../sound/voice2.wav;
#X obj 235 515 s read-sample;
#X obj 438 404 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 480 340 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
1;
#X obj 93 343 s location;
#X obj 186 343 s speed;
#X obj 271 324 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 271 346 s rewind;
#X msg 349 270 200;
#X msg 357 294 100;
#X msg 364 318 20;
#X text 378 269 contract;
#X text 394 318 expand;
#X obj 480 360 s lock;
#X text 480 244 detune;
#X text 93 266 location;
#X text 90 282 (stops;
#X text 95 297 motion);
#X text 184 284 motion in;
#X text 238 417 read input sound;
#X text 628 442 length \, msec;
#X floatatom 582 416 5 0 0 0 - window-size -;
#X msg 582 281 512;
#X msg 588 304 1024;
#X msg 593 327 2048;
#X msg 598 350 4096;
#X obj 582 376 s window-size;
#X text 579 239 window size \,;
#X text 579 254 samples;
#X text 135 242 ------- location controls -------;
#X text 628 415 (check);
#X obj 349 346 s auto;
#X text 85 64 This patch takes a sound \, analyzes windows in it both
for channel magnitude and for phase precession in each channel (compared
to another overlapping window). The real-time output recreates the
same magnitudes and phase precession \, although the phases themselves
are in general different. You can control either the location or its
motion (setting location stops motion \, while setting a non-zero motion
causes the location to change automatically). "Rewind" goes back to
the beginning. You can use different window sizes (use the message
boxes - the number box is for readout). The "lock" feature forces phase
coherency between neighboring channels \, which makes a more present
sound but can add artifacts to the sound. Look in "pd fft-analysis"
to see the workings., f 79;
#X obj 537 283 bng 15 250 50 0 no-detune empty empty 0 -6 0 8 -262144
-1 -1;
#X obj 512 425 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X text 69 21 PHASE VOCODER FOR TIME STRETCHING AND CONTRACTION;
#X text 529 542 updated for Pd version 0.44;
#X text 459 423 file =>;
#X text 456 402 <= record;
#X text 617 280 <= set;
#X connect 0 0 5 0;
#X connect 1 0 20 0;
#X connect 2 0 19 0;
#X connect 3 0 9 0;
#X connect 3 0 9 1;
#X connect 13 0 16 0;
#X connect 14 0 16 0;
#X connect 15 0 16 0;
#X connect 17 0 11 0;
#X connect 18 0 28 0;
#X connect 21 0 22 0;
#X connect 23 0 46 0;
#X connect 24 0 46 0;
#X connect 25 0 46 0;
#X connect 37 0 41 0;
#X connect 38 0 41 0;
#X connect 39 0 41 0;
#X connect 40 0 41 0;
#X connect 49 0 11 1;
