#N canvas 204 58 1157 787 12;
#X declare -stdpath ./;
#X obj 743 155 delay 5;
#X text 915 379 end of note;
#X msg 82 612 record 1;
#X msg 96 667 stop;
#N canvas 813 100 569 656 playback 0;
#X obj 57 60 line~;
#X obj 75 252 line~;
#X obj 57 283 *~;
#X obj 75 223 r cutoff;
#X obj 57 31 r phase;
#X obj 57 607 outlet~;
#X obj 69 94 r sample-number;
#X obj 69 123 makefilename sample%d;
#X msg 69 151 set \$1;
#X obj 57 192 tabread4~ sample1;
#X obj 75 319 r envelope;
#X obj 75 406 sqrt;
#X obj 75 435 sqrt;
#X obj 75 463 line~;
#X obj 57 550 *~;
#X obj 75 492 *~;
#X obj 75 521 *~;
#X text 230 123 compute the name;
#X text 110 499 square the output twice to get the fourth power., f 24;
#X obj 75 348 unpack f f;
#X obj 75 377 dbtorms;
#X text 120 254 [line~] for de-clicking;
#X text 127 32 messages to the phase generating [line~];
#X text 167 309 The envelope generator. Rather than sending our message straight to the [line~] we unpack it in order to fool with the amplitude field., f 45;
#X text 141 407 take the fourth root. This because we want to raise the [line~]'s output to the 4th power afterwards. This is an inexpensive way to give the rise and decay a more natural sounding evolution than just a straight line., f 51;
#X text 190 95 setting the sample number;
#X text 124 150 and send a "set" message to [tabread4~];
#X text 146 378 convert amplitude to linear units;
#X connect 0 0 9 0;
#X connect 1 0 2 1;
#X connect 2 0 14 0;
#X connect 3 0 1 0;
#X connect 4 0 0 0;
#X connect 6 0 7 0;
#X connect 7 0 8 0;
#X connect 8 0 9 0;
#X connect 9 0 2 0;
#X connect 10 0 19 0;
#X connect 11 0 12 0;
#X connect 12 0 13 0;
#X connect 13 0 15 0;
#X connect 13 0 15 1;
#X connect 14 0 5 0;
#X connect 15 0 16 0;
#X connect 15 0 16 1;
#X connect 16 0 14 1;
#X connect 19 0 20 0;
#X connect 19 1 13 1;
#X connect 20 0 11 0;
#X restore 620 443 pd playback;
#X msg 89 637 record 2;
#X text 67 275 ARGUMENTS FOR NOTES:;
#X text 95 314 amplitude (dB), f 19;
#X text 95 348 sample number, f 19;
#X obj 991 279 f;
#X obj 942 253 f;
#X obj 873 253 f;
#X obj 836 253 f;
#X obj 804 253 f;
#X obj 727 253 f;
#X obj 727 280 mtof;
#X obj 727 308 / 261.62;
#X obj 814 369 +;
#X obj 743 182 t b b b;
#X obj 873 303 + 1;
#X obj 254 506 s note;
#X msg 991 307 \; envelope 0 \$1;
#X msg 382 421 62;
#X msg 417 421 64;
#X msg 348 421 60;
#X msg 316 421 55;
#X msg 450 421 72;
#X msg 284 421 48;
#X msg 449 447 60.5;
#X msg 70 582 reload;
#X msg 45 550 browse;
#X text 817 435 combine amplitude \, rise time \, start phase \, end phase \, and sample number in one message, f 29;
#X text 388 239 straight playback;
#X text 386 261 change amplitude;
#X text 401 283 change sample number;
#X text 427 306 change start location;
#X text 434 328 change rise time;
#X text 287 397 If you omit values they stay unchanged;
#X obj 620 480 output~;
#X obj 872 173 unpack f f f f f f f;
#X obj 804 407 pack f f f f f;
#X text 630 197 as before we mute and wait, f 13;
#X text 218 194 These demonstrate the effect of varying the parameters one by one., f 34;
#X obj 978 253 del;
#X msg 639 160 \; cutoff 0 5;
#X obj 743 118 bang;
#X msg 804 522 \; envelope 0 \, \$1 \$2 \; phase \$3 \, \$4 1e+07 \; sample-number \$5 \; cutoff 1 5;
#X listbox 804 490 27 0 0 0 - - - 0;
#X obj 872 116 r note;
#X listbox 872 145 23 0 0 0 - - - 0;
#X obj 76 23 cnv 5 5 25 empty empty Chocolate\ Sampler 15 13 0 16 #dfdfdf #202020 0;
#X text 47 74 This patch takes the same principle as the earlier "C05.sampler.oneshot" \, but allows you to parameterize sample playback. Since we must wait 5 msec before starting the playback \, we store all the parameters in [f] objects \, and recall them to construct the new note. Transposition is done by altering the amount to play back in the (artificial) ten thousand seconds (1e+07). The playback segment can be altered to start in the middle of the sample instead of the beginning \, and you can change the duration and rise and decay times., f 74;
#X msg 239 239 60 100 4000 1 0 0 0;
#X msg 246 261 60 90 4000 1 0 0 0;
#X msg 266 330 60 100 4000 1 0 1000 0;
#X text 95 331 duration (ms), f 19;
#X text 95 365 start location (ms);
#X text 95 382 rise time (ms), f 19;
#X text 95 400 decay time (ms), f 19;
#X text 95 297 MIDI pitch, f 19;
#X msg 275 375 60 100 100 1 0 0 1000;
#X msg 271 352 60 100 100 1 0 0 0;
#X text 409 351 short 0.1 sec duration;
#X text 433 374 with 1 sec decay time;
#X msg 259 306 60 100 4000 1 3000 0 0;
#N canvas 282 191 756 477 init-samples 0;
#X obj 234 37 inlet;
#X obj 144 271 adc~ 1;
#X obj 213 329 line~;
#X obj 144 308 *~;
#X msg 213 301 1;
#X obj 272 266 del 3990;
#X msg 249 301 0 10;
#X obj 144 379 tabwrite~ sample1;
#X msg 58 233 set \$1 \, bang;
#X msg 316 237 stop;
#X msg 272 237 bang;
#X obj 398 239 loadbang;
#X obj 394 141 openpanel;
#X text 438 278 v-- re-read original samples;
#X obj 234 76 route record stop reload browse;
#X obj 398 360 soundfiler;
#X msg 394 168 read \$1 sample1;
#X obj 394 195 soundfiler;
#X text 418 111 <-- browse for samples;
#X obj 394 111 bng 19 250 50 0 empty empty empty 0 -10 0 12 #dfdfdf #000000 #000000;
#X obj 526 402 declare -stdpath ./;
#X msg 398 302 read ../sound/bell.aiff sample1 \, read ../sound/voice2.wav sample2, f 32;
#X obj 58 204 makefilename sample%d;
#X connect 0 0 14 0;
#X connect 1 0 3 0;
#X connect 2 0 3 1;
#X connect 3 0 7 0;
#X connect 4 0 2 0;
#X connect 5 0 6 0;
#X connect 6 0 2 0;
#X connect 8 0 7 0;
#X connect 9 0 5 0;
#X connect 10 0 5 0;
#X connect 11 0 21 0;
#X connect 12 0 16 0;
#X connect 14 0 10 0;
#X connect 14 0 4 0;
#X connect 14 0 22 0;
#X connect 14 1 6 0;
#X connect 14 1 9 0;
#X connect 14 2 21 0;
#X connect 14 3 19 0;
#X connect 16 0 17 0;
#X connect 19 0 12 0;
#X connect 21 0 15 0;
#X connect 22 0 8 0;
#X restore 70 705 pd init-samples;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample1 192000 float 2;
#A color 0;
#A width 2;
#X coords 0 1.02 192000 -1.02 200 130 1;
#X restore 324 602 graph;
#N canvas 0 0 450 300 (subpatch) 0;
#X array sample2 192000 float 2;
#A color 0;
#A width 2;
#X coords 0 1.02 192000 -1.02 200 130 1;
#X restore 536 603 graph;
#X text 490 441 microtones are OK too, f 10;
#X text 652 43 Transposition works by altering the end phase target (\$4 below.) The [mtof] and [/ 261.62] calculate speed change considering 60 as unity., f 53;
#X text 121 583 reload original samples;
#X text 152 613 record sample 1;
#X text 157 636 record sample 2;
#X text 135 667 stop recording;
#X msg 253 284 60 100 4000 2 0 0 0;
#X text 361 740 ----- 4 sec -----;
#X text 561 740 ----- 4 sec -----;
#X text 97 549 choose a new sample for sample 1;
#X text 949 537 This starts the note \, sending to [r] objects in the [pd playback] subpatch., f 27;
#X text 819 612 The new [r envelope] is an amplitude control in parallel with the cutoff control. The "sample-number" switches the [tabread4~] between tables., f 37;
#X obj 873 278 * 48;
#X obj 727 335 * 4.8e+08;
#X connect 0 0 18 0;
#X connect 2 0 65 0;
#X connect 3 0 65 0;
#X connect 4 0 38 0;
#X connect 5 0 65 0;
#X connect 9 0 21 0;
#X connect 10 0 40 1;
#X connect 11 0 80 0;
#X connect 12 0 40 4;
#X connect 13 0 40 0;
#X connect 14 0 15 0;
#X connect 15 0 16 0;
#X connect 16 0 81 0;
#X connect 17 0 40 3;
#X connect 18 0 13 0;
#X connect 18 1 14 0;
#X connect 18 2 10 0;
#X connect 18 2 11 0;
#X connect 18 2 12 0;
#X connect 18 2 43 0;
#X connect 19 0 17 1;
#X connect 19 0 40 2;
#X connect 22 0 20 0;
#X connect 23 0 20 0;
#X connect 24 0 20 0;
#X connect 25 0 20 0;
#X connect 26 0 20 0;
#X connect 27 0 20 0;
#X connect 28 0 20 0;
#X connect 29 0 65 0;
#X connect 30 0 65 0;
#X connect 39 0 14 1;
#X connect 39 0 45 0;
#X connect 39 1 13 1;
#X connect 39 2 43 1;
#X connect 39 3 12 1;
#X connect 39 4 11 1;
#X connect 39 5 10 1;
#X connect 39 6 9 1;
#X connect 40 0 47 0;
#X connect 43 0 9 0;
#X connect 45 0 0 0;
#X connect 45 0 44 0;
#X connect 47 0 46 0;
#X connect 48 0 49 0;
#X connect 49 0 39 0;
#X connect 52 0 20 0;
#X connect 53 0 20 0;
#X connect 54 0 20 0;
#X connect 60 0 20 0;
#X connect 61 0 20 0;
#X connect 64 0 20 0;
#X connect 74 0 20 0;
#X connect 80 0 19 0;
#X connect 81 0 17 0;
