sr = 44100 ksmps = 16 nchnls = 2 0dbfs = 1 /*****Playing a soundfile 1b: play from a buffer*****/ ;written by joachim heintz and andres cabrera ;mar 2009 instr 1; fill the buffer and play Sfile invalue "_Browse1" ;GUI input gichn filenchnls Sfile; check if mono or stereo ;reading the data in the buffers (function tables) giL ftgen 0, 0, 0, 1, Sfile, 0, 0, 1 if gichn == 2 then giR ftgen 0, 0, 0, 1, Sfile, 0, 0, 2 endif turnon 2 endin instr 2; read the buffer ;GUI input kskip invalue "skip" kloop invalue "loop" iskip = i(kskip) iloop = i(kloop) ;comparing the sample rates and reading the buffer ilensmps = ftlen(giL) idur = ilensmps / sr; duration to read the buffer ireadfreq = sr / ilensmps; frequency of reading the buffer iphs = iskip / idur; starting point as phase aL poscil3 1, ireadfreq, giL, iphs if gichn == 2 then aR poscil3 1, ireadfreq, giR, iphs; right channel for stereo soundfile else aR = aL; right channel for mono soundfile endif ;stop instr after playing the buffer if no loop ktim timeinsts if iloop == 0 && ktim > idur-iskip then turnoff endif outs aL, aR endin instr 3; turns off instr 2 turnoff2 2, 0, 0 endin f 0 36000; don't listen to music longer than 10 hours e 1 27 460 602 true 127 170 134 _Browse1 27 96 295 24 {4b9ff4d6-f93b-471c-8d3b-8f94f2c6f948} true 0 -3 _Browse1 327 93 100 30 {0bec8b20-55d0-4e86-b558-e8464ce6530a} true 0 -3 value 1.00000000 Open File / false false 124 139 78 26 {25ac6f50-68b3-4f53-8b60-66f6a60801a1} true 0 -3 event 1.00000000 Play / i 1 0 9999 false false 225 140 80 25 {bf4f12d5-4d8b-471a-a52d-d37135249573} true 0 -3 event 1.00000000 Stop / i 3 0 .1 false false skip 156 185 87 25 {79dec561-416b-4808-bc96-71900361766c} true 0 -3 right Lucida Grande 10 0 0 0 255 255 255 0.00100000 -1e+12 1e+12 false 0 loop 318 188 20 20 {388179e5-59be-49c1-859c-3c8ef59c5cb8} true 0 -3 false 76 184 80 28 {2f88b481-1b38-42cd-a00f-aae03542db9f} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 267 183 52 29 {c4ddb6ad-ce7a-4624-9959-0d8475b121ae} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 29 10 398 43 {d51eabbc-9ac1-4400-bdce-abffa14335ab} true 0 -3 center Lucida Grande 26 3 0 0 0 255 255 255 noborder 1 1 28 52 398 43 {cde28586-8a73-4794-ac1c-09f1d5af0a2c} true 0 -3 center Lucida Grande 22 3 0 0 0 255 255 255 noborder 1 1 25 410 410 182 {d7bc07b9-a49e-44b3-b942-27546029fac0} true 0 0 center DejaVu Sans 14 3 0 0 0 255 255 255 noborder 1 1 31 228 397 89 {75ecdfe7-0ac2-433a-b89b-cc2270259ddb} true 0 -3 1.00000000 scope 2.00000000 1.00000000 1.00000000 1.00000000 0.00000000 32 314 397 89 {440fb58b-dbb2-42db-9f4e-4f15331f5a18} true 0 -3 2.00000000 scope 2.00000000 1.00000000 1.00000000 1.00000000 0.00000000