aboutsummaryrefslogtreecommitdiff
path: root/desiredata/doc/3.audio.examples/I07.phase.vocoder.pd
blob: 735b8cd2ed56083e30b5292d484d1060ae131af0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
#N canvas 425 33 744 599 12;
#X floatatom 494 315 5 0 0 0 - transpo-set -;
#X floatatom 167 383 3 0 0 0 - speed-set -;
#X floatatom 55 385 7 0 0 0 - location-set -;
#N canvas 90 42 821 693 fft-analysis 0;
#X obj 51 477 *~;
#X obj 18 477 *~;
#X obj 18 499 -~;
#X obj 167 475 *~;
#X obj 136 475 *~;
#X obj 136 497 +~;
#X obj 109 193 *~;
#X obj 78 193 *~;
#X obj 50 193 *~;
#X obj 19 193 *~;
#X obj 19 218 +~;
#X obj 127 379 *~;
#X obj 20 622 *~;
#X obj 238 430 rfft~;
#X obj 108 161 rfft~;
#X obj 19 564 rifft~;
#X obj 21 646 outlet~;
#X obj 97 379 *~;
#X obj 97 401 +~;
#X obj 124 218 -~;
#X obj 18 431 *~;
#X obj 51 432 *~;
#X obj 127 622 r window-size;
#X obj 426 595 r window-size;
#X obj 426 644 block~;
#X obj 19 349 +~ 1e-15;
#X obj 19 598 *~;
#X obj 52 598 tabreceive~ \$0-hann;
#X obj 127 643 expr 2/(3*$f1);
#X obj 591 563 loadbang;
#X msg 591 589 \; pd dsp 1 \; window-size 2048 \; transpo 0 \; rewind
bang;
#X msg 426 619 set \$1 4;
#X obj 97 425 q8_rsqrt~;
#N canvas 139 105 1006 799 read-windows 0;
#X obj 18 693 *~;
#X obj 340 448 r window-size;
#X obj 156 300 f;
#X obj 102 91 r window-size;
#X obj 102 139 /;
#X obj 195 695 *~;
#X obj 156 255 bang~;
#X obj 17 551 line~;
#X obj 102 164 * 1000;
#X obj 288 224 r speed;
#X obj 178 276 r location;
#X obj 198 302 +;
#X obj 288 272 *;
#X obj 183 470 +;
#X obj 143 446 t f f;
#X msg 17 523 \$1 \, \$2 \$3;
#X obj 17 496 pack 0 0 0;
#X obj 178 371 / 1000;
#X obj 156 394 *;
#X text 188 394 reading location (samples);
#X obj 51 597 / 4;
#X obj 288 245 * 0.01;
#X floatatom 340 498 7 0 0 0 - - -;
#X obj 340 474 *;
#X obj 499 365 r transpo;
#X obj 499 387 * 0.01;
#X obj 501 408 + 69;
#X obj 502 429 mtof;
#X obj 502 451 / 440;
#X obj 375 474 t b f;
#X obj 19 719 outlet~;
#X obj 195 720 outlet~;
#X obj 218 664 tabreceive~ \$0-hann;
#X obj 803 386 r location;
#X msg 803 409 0;
#X obj 803 432 s speed;
#X obj 768 508 r speed;
#X msg 768 532 set \$1;
#X obj 768 557 s speed-set;
#X text 411 498 stretched window size (samples);
#X obj 877 507 r transpo;
#X msg 877 533 set \$1;
#X obj 877 558 s transpo-set;
#X obj 808 94 r location;
#X msg 826 278 set \$1;
#X obj 808 140 t b f;
#X obj 826 257 f;
#X obj 754 171 int;
#X obj 754 203 sel 0;
#X msg 813 174 1;
#X msg 813 197 0;
#X obj 754 228 del 300;
#X obj 826 302 s location-set;
#X obj 17 637 tabread4~ \$0-sample;
#X obj 194 637 tabread4~ \$0-sample;
#X obj 178 347 r \$0-insamprate;
#X obj 528 586 r rewind;
#X msg 528 744 \; location \$1;
#X floatatom 111 187 5 0 0 0 - - -;
#X obj 102 115 t f b;
#X obj 142 139 samplerate~;
#X obj 102 208 / 4;
#X obj 233 306 s see-loc;
#X obj 817 116 r see-loc;
#X obj 193 420 / 2;
#X obj 156 420 -;
#X text 229 417 back up 1/2 window;
#X obj 16 597 -~;
#X text 43 6 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.
;
#X obj 528 720 * -0.5;
#X text 91 587 "back" window 1/4 cycle behind "front" one;
#X text 137 205 computation period (msec) for overlap of 4;
#X text 164 186 msec in a window;
#X obj 528 666 /;
#X obj 528 691 * 1000;
#X obj 528 642 t f b;
#X obj 568 666 samplerate~;
#X obj 528 619 f;
#X msg 845 711 \; rewind bang \; speed \$1;
#X obj 845 684 r auto;
#X obj 730 685 r no-detune;
#X msg 730 707 \; detune 0;
#X text 326 275 loop to precess the location according;
#X text 325 291 to the "speed" parameter.;
#X text 611 31 if location changes \, update number box;
#X text 610 50 in main window via "location-set" \, but;
#X text 613 69 taking care to limit frequency of updates.;
#X text 756 462 reflect control changes;
#X text 756 479 in main window.;
#X text 754 344 setting location by hand;
#X text 752 362 sets speed to zero.;
#X text 760 653 misc controls;
#X text 496 527 "rewind" control takes us;
#X text 499 545 to a location depending on;
#X text 499 564 stretched window size.;
#X connect 0 0 30 0;
#X connect 1 0 23 0;
#X connect 2 0 11 0;
#X connect 2 0 18 0;
#X connect 3 0 59 0;
#X connect 4 0 8 0;
#X connect 5 0 31 0;
#X connect 6 0 2 0;
#X connect 7 0 67 0;
#X connect 7 0 54 0;
#X connect 8 0 58 0;
#X connect 8 0 61 0;
#X connect 9 0 21 0;
#X connect 10 0 2 1;
#X connect 11 0 2 1;
#X connect 11 0 62 0;
#X connect 12 0 11 1;
#X connect 13 0 16 1;
#X connect 14 0 16 0;
#X connect 14 1 13 0;
#X connect 15 0 7 0;
#X connect 16 0 15 0;
#X connect 17 0 18 1;
#X connect 18 0 65 0;
#X connect 20 0 67 1;
#X connect 21 0 12 0;
#X connect 22 0 20 0;
#X connect 22 0 13 1;
#X connect 22 0 64 0;
#X connect 22 0 77 1;
#X connect 23 0 22 0;
#X connect 24 0 25 0;
#X connect 25 0 26 0;
#X connect 26 0 27 0;
#X connect 27 0 28 0;
#X connect 28 0 29 0;
#X connect 29 0 23 0;
#X connect 29 1 23 1;
#X connect 32 0 5 1;
#X connect 32 0 0 1;
#X connect 33 0 34 0;
#X connect 34 0 35 0;
#X connect 36 0 37 0;
#X connect 37 0 38 0;
#X connect 40 0 41 0;
#X connect 41 0 42 0;
#X connect 43 0 45 0;
#X connect 44 0 52 0;
#X connect 45 0 47 0;
#X connect 45 1 46 1;
#X connect 46 0 44 0;
#X connect 47 0 48 0;
#X connect 48 0 49 0;
#X connect 48 0 51 0;
#X connect 49 0 47 1;
#X connect 50 0 47 1;
#X connect 51 0 50 0;
#X connect 51 0 46 0;
#X connect 53 0 0 0;
#X connect 54 0 5 0;
#X connect 55 0 17 0;
#X connect 56 0 77 0;
#X connect 59 0 4 0;
#X connect 59 1 60 0;
#X connect 60 0 4 1;
#X connect 61 0 16 2;
#X connect 61 0 12 1;
#X connect 63 0 45 0;
#X connect 64 0 65 1;
#X connect 65 0 14 0;
#X connect 67 0 53 0;
#X connect 69 0 57 0;
#X connect 73 0 74 0;
#X connect 74 0 69 0;
#X connect 75 0 73 0;
#X connect 75 1 76 0;
#X connect 76 0 73 1;
#X connect 77 0 75 0;
#X connect 79 0 78 0;
#X connect 80 0 81 0;
#X restore 109 133 pd read-windows;
#X obj 137 543 tabsend~ prev-imag;
#X obj 136 567 tabsend~ prev-real;
#X obj 20 8 tabreceive~ prev-real;
#X obj 73 29 tabreceive~ prev-imag;
#X text 272 5 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 121 69 *~;
#X obj 89 69 *~;
#X obj 89 91 +~;
#X obj 159 94 q8_rsqrt~;
#X obj 159 71 +~ 1e-20;
#X obj 73 119 *~;
#X obj 19 118 *~;
#X obj 181 290 r lock;
#X obj 29 245 lrshift~ 1;
#X obj 24 269 lrshift~ -1;
#X obj 141 245 lrshift~ 1;
#X obj 133 269 lrshift~ -1;
#X obj 35 300 *~;
#X obj 159 312 *~;
#X obj 19 325 +~;
#X obj 125 331 +~;
#X text 247 66 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 247 165 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 249 370 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 288 427 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 249 242 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 387 560 'set' message to block;
#X text 390 577 allows variable size;
#X text 259 126 Read two windows \, one 1/4 length behind the other
\, of the input sound \, with Hann window function (see inside).;
#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 55 480 pd fft-analysis;
#N canvas 260 23 647 768 phase-tables 0;
#N canvas 0 0 450 300 graph2 0;
#X array prev-imag 4096 float 0;
#X coords 0 1000 4096 -1000 400 300 1;
#X restore 169 326 graph;
#N canvas 0 0 450 300 graph3 0;
#X array prev-real 4096 float 0;
#X coords 0 500 4096 -500 400 300 1;
#X restore 170 17 graph;
#X restore 440 504 pd phase-tables;
#X obj 494 338 s transpo;
#X text 164 364 hundredths;
#X text 493 294 in cents;
#X text 389 359 normal;
#X obj 56 517 output~;
#N canvas 0 110 565 454 hann-window 0;
#N canvas 0 0 450 300 graph1 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 440 528 pd hann-window;
#N canvas 388 86 694 447 insample 0;
#N canvas 0 0 450 300 graph1 0;
#X array \$0-sample 160161 float 0;
#X coords 0 1 160160 -1 400 150 1;
#X restore 281 135 graph;
#X obj 28 133 r read-sample;
#X obj 28 184 unpack s f;
#X obj 28 294 soundfiler;
#X text 365 360 read a sample;
#X obj 285 359 loadbang;
#X obj 28 210 t s b;
#X obj 84 209 symbol \$0-sample;
#X obj 28 245 pack s s;
#X msg 28 270 read -resize \$1 \$2;
#X obj 83 156 44100;
#X obj 28 157 t a b;
#X obj 38 318 s \$0-samplength;
#X obj 125 184 s \$0-insamprate;
#X obj 28 357 /;
#X obj 28 381 * 1000;
#X obj 28 404 s \$0-samp-msec;
#X obj 66 357 r \$0-insamprate;
#X obj 29 70 hip~ 5;
#X obj 29 46 adc~ 1;
#X obj 29 9 inlet;
#X obj 91 46 samplerate~;
#X obj 29 93 tabwrite~ \$0-sample;
#X obj 91 70 s \$0-insamprate;
#X msg 285 383 \; read-sample ../sound/voice.wav;
#X obj 276 20 inlet;
#X obj 276 42 openpanel;
#X obj 276 67 s read-sample;
#X connect 1 0 11 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 24 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 13 0;
#X connect 11 0 2 0;
#X connect 11 1 10 0;
#X connect 14 0 15 0;
#X connect 15 0 16 0;
#X connect 17 0 14 1;
#X connect 18 0 22 0;
#X connect 19 0 18 0;
#X connect 20 0 21 0;
#X connect 20 0 19 0;
#X connect 21 0 23 0;
#X connect 25 0 26 0;
#X connect 26 0 27 0;
#X restore 441 480 pd insample;
#X floatatom 552 480 5 0 0 0 - #0-samp-msec -;
#X msg 229 486 ../sound/bell.aiff;
#X msg 229 511 ../sound/voice.wav;
#X msg 229 536 ../sound/voice2.wav;
#X obj 229 562 s read-sample;
#X obj 441 439 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X text 460 438 <- record;
#X obj 493 387 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
1;
#X obj 55 407 s location;
#X obj 167 407 s speed;
#X obj 262 386 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X obj 262 408 s rewind;
#X msg 345 336 200;
#X msg 345 358 100;
#X msg 345 380 20;
#X text 386 335 contract;
#X text 390 380 expand;
#X obj 493 407 s lock;
#X text 494 277 detune;
#X text 55 330 location;
#X text 52 346 (stops;
#X text 57 361 motion);
#X text 165 348 motion in;
#X text 232 464 read input sound;
#X text 103 7 PHASE VOCODER FOR TIME STETCHING AND CONTRACTION;
#X text 604 479 length \, msec;
#X floatatom 607 419 5 0 0 0 - window-size -;
#X msg 607 307 512;
#X msg 607 329 1024;
#X msg 607 351 2048;
#X msg 607 373 4096;
#X obj 607 395 s window-size;
#X text 607 274 window size \,;
#X text 607 289 samples;
#X text 648 306 <- set;
#X text 100 306 ------- location controls -------;
#X text 660 419 (check);
#X obj 345 407 s auto;
#X text 23 35 This patch takes a sound \, analyzes windows in it both
for channel magnitude and for phase precession in each channel (compared
to another operlapping window). The real-time output recreates the
same magnitudes and phase precession \, althought 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.;
#X text 483 568 updated for Pd version 0.39;
#X obj 551 316 bng 15 250 50 0 no-detune empty empty 0 -6 0 8 -262144
-1 -1;
#X obj 535 460 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
-1;
#X text 466 458 file ->;
#X connect 0 0 5 0;
#X connect 1 0 21 0;
#X connect 2 0 20 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 19 0 29 0;
#X connect 22 0 23 0;
#X connect 24 0 49 0;
#X connect 25 0 49 0;
#X connect 26 0 49 0;
#X connect 39 0 43 0;
#X connect 40 0 43 0;
#X connect 41 0 43 0;
#X connect 42 0 43 0;
#X connect 53 0 11 1;